Solved

getting values from the registry win 7 vbs

Posted on 2014-12-01
5
97 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

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
win 7 pro give user permission to install but not uninstall 12 76
laptop problem 21 93
Way to setup network drive share permanently mapped to server 3 44
Error in script 11 44
The recent Microsoft changes on update philosophy for Windows pre-10 and their impact on existing WSUS implementations.
When you try to share a printer , you may receive one of the following error messages. Error message when you use the Add Printer Wizard to share a printer: Windows could not share your printer. Operation could not be completed (Error 0x000006…
Windows 8 comes with a dramatically different user interface known as Metro. Notably missing from the new interface is a Start button and Start Menu. Many users do not like it, much preferring the interface of earlier versions — Windows 7, Windows X…
This Micro Tutorial will give you a introduction in two parts how to utilize Windows Live Movie Maker to its maximum capability. This will be demonstrated using Windows Live Movie Maker on Windows 7 operating system.

919 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

14 Experts available now in Live!

Get 1:1 Help Now