Solved

getting values from the registry win 7 vbs

Posted on 2014-12-01
5
103 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
[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
  • 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

What Is Transaction Monitoring and who needs it?

Synthetic Transaction Monitoring that you need for the day to day, which ensures your business website keeps running optimally, and that there is no downtime to impact your customer experience.

Question has a verified solution.

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

On some Windows 7 (SP1) computers, Windows Update becomes super slow even the computer is reasonably fast.  There's one solution that seemed to have worked well for me (after trying a few other suggested solutions).
There are many software programs on offer that will claim to magically speed up your computer. The best advice I can give you is to avoid them like the plague, because they will often cause far more problems than they solve. Try some of these "do it…
This Micro Tutorial will teach you how to change your appearance and customize your Windows 7 interface to your unique preference. This will be demonstrated using Windows 7 operating system.
This Micro Tutorial will give you basic overview of the control panel section on Windows 7. It will depth in Network and Internet, Hardware and Sound, etc. This will be demonstrated using Windows 7 operating system.

707 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