Hello all,
I am trying to run a vbscript to run a reg query command on remote systems. I am passing a list of system names into the script from a text file. The script runs and is reading the text file fine but the output is only writing the name of the system in the output text file, not the output of the reg query command. I have searched this forum, searched the Internet/Googled for a while and cannot find the reason why this is not working. This is what I have so far:
Const ForReading = 1
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objShell = CreateObject("Wscript.Shell")
Set objTextFile = objFSO.OpenTextFile("C:\workstations.txt", ForReading)
Const REGQ = "C:\REG QUERY "
Do Until objTextFile.AtEndOfStream
strComputer = objTextFile.ReadLine
strRegKey="HKLM\Software\Policies\Microsoft\Windows\NetCache\"
Set objExec = objShell.Exec("cmd /c " & REGQ & " \\" & strComputer & strRegKey)
Do While Not objExec.StdOut.Atendofstream
val = (objExec.StdOut.ReadAll)
Loop
Set fs = CreateObject("Scripting.FileSystemObject")
Set file = fs.OpenTextFile("C:\offline-regcheck.txt", 8, True)
file.Write ""& strComputer & vbCrLf
file.Write "" & val & vbCrLf
file.close
Loop
objTextFile.Close
wscript.echo "Done"
wscript.quit
Any pointers/tips would be greatly appreciated.
I am trying to run a vbscript to run a reg query command on remote systems. I am passing a list of system names into the script from a text file. The script runs and is reading the text file fine but the output is only writing the name of the system in the output text file, not the output of the reg query command. I have searched this forum, searched the Internet/Googled for a while and cannot find the reason why this is not working. This is what I have so far:
Const ForReading = 1
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objShell = CreateObject("Wscript.Shell")
Set objTextFile = objFSO.OpenTextFile("C:\workstations.txt", ForReading)
Const REGQ = "C:\REG QUERY "
Do Until objTextFile.AtEndOfStream
strComputer = objTextFile.ReadLine
strRegKey="HKLM\Software\Policies\Microsoft\Windows\NetCache\"
Set objExec = objShell.Exec("cmd /c " & REGQ & " \\" & strComputer & strRegKey)
Do While Not objExec.StdOut.Atendofstream
val = (objExec.StdOut.ReadAll)
Loop
Set fs = CreateObject("Scripting.FileSystemObject")
Set file = fs.OpenTextFile("C:\offline-regcheck.txt", 8, True)
file.Write ""& strComputer & vbCrLf
file.Write "" & val & vbCrLf
file.close
Loop
objTextFile.Close
wscript.echo "Done"
wscript.quit
Any pointers/tips would be greatly appreciated.