?
Solved

getting values from the registry win 7 vbs

Posted on 2014-12-01
5
Medium Priority
?
104 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 2000 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 does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

When you try to extract and to view the contents of a Microsoft Update Standalone Package (MSU) for Windows Vista, you cannot extract the files from the MSU. Here we are going to explain how to extract those hotfix details without using any third pa…
The Windows functions GetTickCount and timeGetTime retrieve the number of milliseconds since the system was started. However, the value is stored in a DWORD, which means that it wraps around to zero every 49.7 days. This article shows how to solve t…
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.
The Task Scheduler is a powerful tool that is built into Windows. It allows you to schedule tasks (actions) on a recurring basis, such as hourly, daily, weekly, monthly, at log on, at startup, on idle, etc. This video Micro Tutorial is a brief intro…
Suggested Courses
Course of the Month12 days, 17 hours left to enroll

777 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