Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Guys,
Any idea why the following VB script only returns value for strDriver = "ExePath" and not for strValueName = "Atest" ???
Both are String Values and yet only ExePath is entered to the xls. Any help will be highly appreciated.
On Error Resume Next
Const ForReading = 1
Const HKEY_LOCAL_MACHINE = &H80000002
x = 2'Create an Excel Work Sheet
Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = True
objExcel.Workbooks.AddobjExcel.Cells(1, 1).Value = "Machine Name"
objExcel.Cells(1, 2).Value = "Database Name"
objExcel.Cells(1, 3).Value = "Driver Name"
objExcel.Cells(1, 4).Value = "Report Time Stamp"objExcel.Range("A1:G1").Select
objExcel.Selection.Interior.ColorIndex = 19
objExcel.Selection.Font.ColorIndex = 11
objExcel.Selection.Font.Bold = True
objExcel.Cells.EntireColumn.AutoFit
'Read machine names from a txt fileSet Fso = CreateObject("Scripting.FileSystemObject")
Set InputFile = fso.OpenTextFile("MachineList.Txt")
Do While Not (InputFile.atEndOfStream)
strComputer = InputFile.ReadLineintRow = x
objExcel.Cells(intRow, 1).Value = strComputer
GetRegInfo
objExcel.Cells(intRow, 4).Value = Now()
x = x + 1Loop
Wscript.Echo "Done"
'*********************************************************************************************************
'Get information from RegistrySub GetRegInfo
Set oReg=GetObject( _
"winmgmts:{impersonationLevel=impersonate}!\\" &_
strComputer & "\root\default:StdRegProv")
strKeyPath = "SOFTWARE\ACRONIS\DDDeployer"
strValueName = "Atest"
strDriver = "ExePath"oReg.GetStringValue _
HKEY_LOCAL_MACHINE,strKeyPath,strValueName,sValueobjExcel.Cells(intRow, 2).Value = sValue
oReg.GetStringValue _
HKEY_LOCAL_MACHINE,strKeyPath,strDriver,sValueobjExcel.Cells(intRow, 3).Value = sValue
End Sub

Not much of a riddle.
On Error Resume Next
Step 1: Delete this line. It hides errors.oReg.GetStringValue _
HKEY_LOCAL_MACHINE,strKeyPath,strValueName,sValue
Step 2: Check the return value. Chances are, it's throwing a Not Found.

Well riddle hasn’t been cracked yet. Both reg values are populated with data:
http://hd-motormania.com/Images/reg...And this is what I get in the xls:
http://hd-motormania.com/Images/xls...Not sure what’s preventing script from returning TEST for Atest value
I also did not see any Not Found messages.
Razor2.3 Thanks for your reply I wish it was that easy...

Thanks for your reply I wish it was that easy
Well, if it's not throwing a Not Found, what is its return code?

That’s the issue, script runs just fine, no error messages are return but cell in xls is not updated event though I see test in the Atest String value.

Replace
oReg.GetStringValue _
HKEY_LOCAL_MACHINE,strKeyPath,strValueName,sValueWith
WScript.Echo oReg.GetStringValue(HKEY_LOCAL_MACHINE,strKeyPath,strValueName,sValue)
This should return something useful, even if you have On Error Resume Next enabled.

Oh, wow. This fell far on my list.
0 for strValueName = "Atest"
and
1 for strDriver = "ExePath"
Are you sure that's not reversed? 1 for "Atest" would be expected, as that would indicate a problem returning "Atest" from a remote computer.

You are right, I got them mixed up. Sorry about that...Any idea why script fails to return Atest? It's my local workstation not remote machine.

Chances are, it's not "Atest". It might be " Atest", or "Atest ", (or even "Atest<null>",) but it can't find the value. You can see what WMI sees with this:
Set out = CreateObject("Scripting.FileSystemObject").OpenTextFile("out.txt", 2, True) Set wmiReg = GetObject("winmgmts:root/default:StdRegProv") wmiReg.EnumValues , "SOFTWARE\ACRONIS\DDDeployer", names, types For Each n In names out.WriteLine """" & n & """" Next 'n out.Close CreateObject("WScript.Shell").Run "out.txt"

![]() |
![]() |
![]() |
| Login or Register to Reply | |
| Login | Register |
| Ads by Google |