Solved

getting values from the registry win 7 vbs

Posted on 2014-12-01
5
92 Views
Last Modified: 2014-12-22
Hello given the following code:
strComputer = "."
Const HKCU = &H80000001 'HKEY_CURRENT_USER
strKeyPath = "Software\x\y"
szvalue = " "
szvaltype = " "
strname="z"


       Set oReg= _
          GetObject("winmgmts:{impersonationLevel=impersonate}!\\" _
          & strComputer & "\root\default:StdRegProv")
      
       oReg.GetStringValue HKcu, strKeyPath, strname, szValue  

      wscript.echo szvalue

      
  Where z is a reg_sz with a value of 1 does the code above echo reg_sz and not the value 1 ?
0
Comment
Question by:HalCHub
  • 3
  • 2
5 Comments
 
LVL 11

Expert Comment

by:Dany Balian
ID: 40473909
the above should return 1, what's the problem? try to run the code in elevated permission (right click, run as administrator)
0
 
LVL 1

Author Comment

by:HalCHub
ID: 40474082
I ran as administrator it returns reg_sz
0
 
LVL 11

Expert Comment

by:Dany Balian
ID: 40474099
i just ran your code on xp and win7, they both return 1
and it gives a runtime error (invalid use of null) if the key does not exist!
is this the exact code your using? or your modifying it for experts exchange? if so, check your code, you might have a typo!
i'm using win7 ultimate sp1;
and xp sp3
0
 
LVL 1

Author Comment

by:HalCHub
ID: 40474110
nope its the exact code
0
 
LVL 11

Accepted Solution

by:
Dany Balian earned 500 total points
ID: 40474132
can you try this code?
Dim oWshShell
Set oWshShell = WScript.CreateObject("WScript.Shell")

GetValue "HKCU\SOFTWARE\x\y\","z"

Sub GetValue(value, name)
Dim strValue
On Error Resume Next
ValueData = oWshShell.RegRead(value & name)
num = Err.Number
If Not IsEmpty(ValueData) Then
strValue = Trim(ValueData)
WScript.Echo " " & name & "=" & strValue & ", typeName=" & TypeName(ValueData) & ", rval=" & CStr(rval) & ", err=" & CStr(num)
End If
On Error Goto 0
End Sub

Open in new window

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

The recent Microsoft changes on update philosophy for Windows pre-10 and their impact on existing WSUS implementations.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This Micro Tutorial will give you a basic overview of Windows Live Photo Gallery and show you various editing filters and touches to photos you can apply. This will be demonstrated using Windows Live Photo Gallery on Windows 7 operating system.
The viewer will learn how to successfully create a multiboot device using the SARDU utility on Windows 7. Start the SARDU utility: Change the image directory to wherever you store your ISOs, this will prevent you from having 2 copies of an ISO wit…

758 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

13 Experts available now in Live!

Get 1:1 Help Now