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,strKeyP ath, strValueName,arrValues to
oReg.GetStringValue HKEY_LOCAL_MACHINE,strKeyP ath, 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.Netw ork")
strUser = wshNetwork.Username
Set oReg=GetObject("winmgmts:{ impersonat ionLevel=i mpersonate }!\\" &_
strComputer & "\root\default:StdRegProv" )
strKeyPath = "SOFTWARE\Novell"
strValueName = "CurrentVersion"
oReg.GetStringValue HKEY_LOCAL_MACHINE, strKeyPath, strValueName, arrValues
'create the FileSystemObject
Set fso = CreateObject("scripting.fi lesystemob ject")
'Open the data file for appending
'fso.OpenTextFile "C:\Fall2006UpdatesCheck.t xt", ForAppending, True, TristateFalse
Set logts = fso.OpenTextFile("C:\Fall2 006Updates Check.txt" , 8, -1, 0)
regComputerName = "HKLM\SYSTEM\CurrentContro lSet\Contr ol\" & _
"ComputerName\ComputerName \ComputerN ame"
Set objShell = CreateObject("WScript.Shel l")
Set objFileSystem = CreateObject("Scripting.Fi leSystemOb ject")
ComputerName = objShell.RegRead(regComput erName)
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
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,strKeyP
oReg.GetStringValue HKEY_LOCAL_MACHINE,strKeyP
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.Netw
strUser = wshNetwork.Username
Set oReg=GetObject("winmgmts:{
strComputer & "\root\default:StdRegProv"
strKeyPath = "SOFTWARE\Novell"
strValueName = "CurrentVersion"
oReg.GetStringValue HKEY_LOCAL_MACHINE, strKeyPath, strValueName, arrValues
'create the FileSystemObject
Set fso = CreateObject("scripting.fi
'Open the data file for appending
'fso.OpenTextFile "C:\Fall2006UpdatesCheck.t
Set logts = fso.OpenTextFile("C:\Fall2
regComputerName = "HKLM\SYSTEM\CurrentContro
"ComputerName\ComputerName
Set objShell = CreateObject("WScript.Shel
Set objFileSystem = CreateObject("Scripting.Fi
ComputerName = objShell.RegRead(regComput
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
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..
Try placing a
msgbox arrValues
just before that line..
ASKER
It's returning the value in the messagebox ok.
..and what about
If Not IsNull(arrValues) then msgbox arrValues
??
If Not IsNull(arrValues) then msgbox arrValues
??
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.
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
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
~sirbounty
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)