Computing.Net > Forums > Programming > VBScript Riddle

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

VBScript Riddle

Reply to Message Icon

Name: Odyss
Date: October 8, 2009 at 14:13:43 Pacific
OS: Windows XP
Subcategory: General
Comment:

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.Add

objExcel.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 file

Set Fso = CreateObject("Scripting.FileSystemObject")
Set InputFile = fso.OpenTextFile("MachineList.Txt")
Do While Not (InputFile.atEndOfStream)
strComputer = InputFile.ReadLine

intRow = x

objExcel.Cells(intRow, 1).Value = strComputer

GetRegInfo

objExcel.Cells(intRow, 4).Value = Now()


x = x + 1

Loop

Wscript.Echo "Done"

'*********************************************************************************************************
'Get information from Registry

Sub 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,sValue

objExcel.Cells(intRow, 2).Value = sValue

oReg.GetStringValue _
HKEY_LOCAL_MACHINE,strKeyPath,strDriver,sValue

objExcel.Cells(intRow, 3).Value = sValue

End Sub



Sponsored Link
Ads by Google

Response Number 1
Name: Razor2.3
Date: October 8, 2009 at 14:48:26 Pacific
Reply:

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.


0

Response Number 2
Name: Odyss
Date: October 9, 2009 at 05:16:09 Pacific
Reply:

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...


0

Response Number 3
Name: Razor2.3
Date: October 9, 2009 at 06:15:57 Pacific
Reply:

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


0

Response Number 4
Name: Odyss
Date: October 9, 2009 at 08:09:41 Pacific
Reply:

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.


0

Response Number 5
Name: Razor2.3
Date: October 9, 2009 at 09:56:28 Pacific
Reply:

Replace
oReg.GetStringValue _
HKEY_LOCAL_MACHINE,strKeyPath,strValueName,sValue

With

WScript.Echo oReg.GetStringValue(HKEY_LOCAL_MACHINE,strKeyPath,strValueName,sValue)

This should return something useful, even if you have On Error Resume Next enabled.

0

Related Posts

See More



Response Number 6
Name: Odyss
Date: October 9, 2009 at 12:48:33 Pacific
Reply:

Script returns:
0 for strValueName = "Atest"
and
1 for strDriver = "ExePath"


0

Response Number 7
Name: Razor2.3
Date: October 12, 2009 at 09:48:20 Pacific
Reply:

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.


0

Response Number 8
Name: Odyss
Date: October 12, 2009 at 14:15:08 Pacific
Reply:

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.


0

Response Number 9
Name: Razor2.3
Date: October 12, 2009 at 15:16:42 Pacific
Reply:

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"


0

Sponsored Link
Ads by Google
Reply to Message Icon





Use following form to reply to current message:

Login or Register to Reply
LoginRegister


Sponsored links

Ads by Google


Results for: VBScript Riddle

Vbscript & SQL www.computing.net/answers/programming/vbscript-amp-sql/1243.html

Pop-Up IE Browser window w/VBScript www.computing.net/answers/programming/popup-ie-browser-window-wvbscript/6613.html

VBScript IP Address within range www.computing.net/answers/programming/vbscript-ip-address-within-range/14735.html