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 に答える