Solved

Using VBscript to read String Value from registry

Posted on 2006-11-22
9
5,024 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

746 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

15 Experts available now in Live!

Get 1:1 Help Now