0

下面的脚本工作正常,它获取我正在搜索的密钥的路径。请有人帮我找到从文本文件中读取服务器列表的方法。我正在学习 vbscript 并尝试了一些方法来读取它失败的文本文件。

Const HKEY_LOCAL_MACHINE = &H80000002
strComputer = "Server name" 
const REG_SZ = 1 
const REG_EXPAND_SZ = 2 
const REG_BINARY = 3 
const REG_DWORD = 4 
const REG_MULTI_SZ = 7 
strOriginalKeyPath = "SOFTWARE\VMware, Inc.\VMware Tools" 
FindKeyValue(strOriginalKeyPath) 
'------------------------------------------------------------------------- 
Function FindKeyValue(strKeyPath) 
    Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &_        
          strComputer & "\root\default:StdRegProv") 
    errorCheck = oReg.EnumKey(HKEY_LOCAL_MACHINE, strKeyPath, arrSubKeys)        

    If (errorCheck=0 and IsArray(arrSubKeys)) then        
          For Each subkey In arrSubKeys            
          strNewKeyPath = strKeyPath & "\" & subkey            
          FindKeyValue(strNewKeyPath)        
          Next    
    End If 
oReg.EnumValues HKEY_LOCAL_MACHINE, strKeyPath, _            
          arrValueNames, arrValueTypes     
If (errorCheck=0 and IsArray(arrValueNames)) then        
           For i=0 To UBound(arrValueNames)            
          'Wscript.Echo "Value Name: " & arrValueNames(i)        
 if arrValueNames(i) = "InstallPath" then            
          strValueName = arrValueNames(i)            
          oReg.GetDWORDValue HKEY_LOCAL_MACHINE, strKeyPath, strValueName, dwValue            
          wscript.echo strComputer & "\" & strkeyPath & vbNewLine              
  end if        
  Next    
End if 
end Function 
4

1 回答 1

0

以下是我用来读取机器名称列表的一些代码,例如:

MACHINE1
MACHINE2
MACHINE3

进入一个数组,然后您可以使用“For”语句循环遍历该数组。

pcList = readlist("C:\temp\testlist.txt")

'
' Reads in a list of PC names from a file and returns
' an array containing one PC name per member.
'
' Blank lines are ignored.
' Lines starting with ";" are treated as comments and
' are not added to the list.
'
'
function ReadList(listfile)

   const forReading = 1

   dim thelist()
   redim thelist(1)
   listLen = 0

   set theFSO = createobject("Scripting.FileSystemObject")
   set listFile = theFSo.openTextFile(listfile,forReading)

   while not listFile.atendofstream

     pcname = ltrim(rtrim(listFile.readline))

     if len(pcname)>1 and left(pcname,1)<>";" then

        if listlen = 0 then
           thelist(0) = pcname
           listlen = listlen+1
        else
           redim preserve thelist(listlen)
           thelist(listlen) = pcname
           listlen = listlen + 1
        end if


     end if

   wend

   listfile.close
   set listfile = nothing
   set thefso = nothing

   ReadList = theList

end Function
于 2012-08-09T15:38:23.890 回答