Solved

Using VBscript to read String Value from registry

Posted on 2006-11-22
9
5,027 Views
Last Modified: 2012-05-05
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

0
Comment
Question by:hpops
  • 5
  • 4
9 Comments
 
LVL 67

Expert Comment

by:sirbounty
ID: 17995450
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)
0
 

Author Comment

by:hpops
ID: 17995670
I'm getting a 'type mismatch' error when replacing that line.
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 17995787
Are you sure it's a string value?

Try placing a
msgbox arrValues
just before that line..
0
 

Author Comment

by:hpops
ID: 17995826
It's returning the value in the messagebox ok.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 67

Expert Comment

by:sirbounty
ID: 17995902
..and what about

If Not IsNull(arrValues) then msgbox arrValues
??
0
 

Author Comment

by:hpops
ID: 17996100
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.
0
 
LVL 67

Accepted Solution

by:
sirbounty earned 500 total points
ID: 17996127
You'll have to strip out your for each as well, since it's no longer an array...

if not isnull(arrvalues) then
   logts.writeline...
0
 

Author Comment

by:hpops
ID: 17996395
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
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 17996412
Glad to hear it - happy to have helped. :^)
~sirbounty
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now