Solved

Using VBscript to read String Value from registry

Posted on 2006-11-22
9
5,038 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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 

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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

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…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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…

691 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