Solved

Using VBscript to read String Value from registry

Posted on 2006-11-22
9
5,034 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:hpops
ID: 17995826
It's returning the value in the messagebox ok.
0
 
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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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 …
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

749 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