Link to home
Start Free TrialLog in
Avatar of hpops
hpops

asked on

Using VBscript to read String Value from registry

Hello,

I have some code below that works great when reading a Multi-String value from the registry. I tried to convert it by changing the line that read
oReg.GetMultiStringValue HKEY_LOCAL_MACHINE,strKeyPath, strValueName,arrValues to
oReg.GetStringValue HKEY_LOCAL_MACHINE,strKeyPath, strValueName,arrValues

Changing this alone did not work and it's returning my else statement even though the registry key exists and has a data value.
Any ideas on how I could fix this?


Option Explicit
'On Error Resume Next
Dim objShell, objFileSystem, strKeyPath, strValueName, strValue, arrValues
Dim regComputerName, ComputerName, strComputer, StdOut, oReg, fso, logts
Dim CurrentDate, CurrentTime, wshNetwork, strUser
CurrentDate = Date
CurrentTime = Time

const HKEY_LOCAL_MACHINE = &H80000002
strComputer = "."
Set StdOut = WScript.StdOut
Set wshNetwork = CreateObject("WScript.Network")
strUser = wshNetwork.Username
Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &_
strComputer & "\root\default:StdRegProv")
 
strKeyPath = "SOFTWARE\Novell"
strValueName = "CurrentVersion"
oReg.GetStringValue HKEY_LOCAL_MACHINE, strKeyPath, strValueName, arrValues

'create the FileSystemObject
Set fso = CreateObject("scripting.filesystemobject")
'Open the data file for appending
'fso.OpenTextFile "C:\Fall2006UpdatesCheck.txt", ForAppending, True, TristateFalse
Set logts = fso.OpenTextFile("C:\Fall2006UpdatesCheck.txt", 8, -1, 0)

regComputerName = "HKLM\SYSTEM\CurrentControlSet\Control\" & _
"ComputerName\ComputerName\ComputerName"
Set objShell = CreateObject("WScript.Shell")
Set objFileSystem = CreateObject("Scripting.FileSystemObject")
ComputerName = objShell.RegRead(regComputerName)

If (isarray(arrValues)) then
For Each strValue In arrValues
   'StdOut.WriteLine strValue
   'append to file
   logts.WriteLine ComputerName & "|" & strUser & "|" & strValue & "|" & CurrentDate & "|" & CurrentTime

Next

else
logts.WriteLine ComputerName  & "|" & strUser & "|" & "Is the Novell Client installed" & "|" & CurrentDate & "|" &  CurrentTime
end if

'close the file
logts.Close

Avatar of sirbounty
sirbounty
Flag of United States of America image

Cause it's no longer an array...
You could use   If Not IsNull(arrValues) in place of If(isarray(arrValues))

Unless I just don't understand what you're trying to accomplish... : \ (possible)
Avatar of hpops
hpops

ASKER

I'm getting a 'type mismatch' error when replacing that line.
Are you sure it's a string value?

Try placing a
msgbox arrValues
just before that line..
Avatar of hpops

ASKER

It's returning the value in the messagebox ok.
..and what about

If Not IsNull(arrValues) then msgbox arrValues
??
Avatar of hpops

ASKER

Ok, getting a Syntax error on my Else statement near the end of the code.
I never got a messagebox even though the registry key exists and has data. I'm assuming this is because of the Synatx error.
ASKER CERTIFIED SOLUTION
Avatar of sirbounty
sirbounty
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of hpops

ASKER

Thank you very much.
I removed the for, each items and changed this line

logts.WriteLine ComputerName & "|" & strUser & "|" & strValue & "|" & CurrentDate & "|" & CurrentTime

to

logts.WriteLine ComputerName & "|" & strUser & "|" & arrValues & "|" & CurrentDate & "|" & CurrentTime

 
It's working great now.
Thanks a bunch for all your help
Glad to hear it - happy to have helped. :^)
~sirbounty