Solved

Vbscript to query a registry key and pass to a batch file

Posted on 2011-02-22
5
650 Views
Last Modified: 2012-05-11
Hi,

I need a script that will be able to query a reg_sz key in the registry within HKLM.

I would then like the vbscript to call another Windows Batch file and pass the key as a variable into this script. I assume I can then use %1 within the batch script.

Thanks
0
Comment
Question by:aideb
[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 12

Expert Comment

by:prashanthd
ID: 34951877
try this code
Give the reg key paths and modify test.bat to the batch file name
Yes, you can use %1 in batch file.
On Error Resume Next

strKeyPath = "SOFTWARE\Microsoft\Windows Script Host\Settings" 'give reg path
strValueName = "TrustPolicy" 'give key to get
strComputer = "."

Const HKEY_LOCAL_MACHINE = &H80000002
dim shell
set shell=createobject("wscript.shell")

 
Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _
    strComputer & "\root\default:StdRegProv")
 

oReg.GetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue

'WScript.Echo "strvalue" & strvalue

shell.run "test.bat " & strvalue
set shell=nothing

Open in new window

0
 
LVL 2

Author Comment

by:aideb
ID: 34952143
Excellent thanks.

is there anyway to run the batch script hidden?
0
 
LVL 12

Accepted Solution

by:
prashanthd earned 500 total points
ID: 34953569
you can test the following to hide the batch script

On Error Resume Next

strKeyPath = "SOFTWARE\Microsoft\Windows Script Host\Settings" 'give reg path
strValueName = "TrustPolicy" 'give key to get
strComputer = "."

Const HKEY_LOCAL_MACHINE = &H80000002
dim shell
set shell=createobject("wscript.shell")

 
Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _
    strComputer & "\root\default:StdRegProv")
 

oReg.GetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue

'WScript.Echo "strvalue" & strvalue

shell.run "test.bat " & strvalue,0
set shell=nothing
0
 
LVL 12

Expert Comment

by:prashanthd
ID: 34957580
Did the above code work?
0
 
LVL 2

Author Comment

by:aideb
ID: 34960250
Yes it did!.

fantastic - thanks...
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

The recent Microsoft changes on update philosophy for Windows pre-10 and their impact on existing WSUS implementations.
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…
In this video, we discuss why the need for additional vertical screen space has become more important in recent years, namely, due to the transition in the marketplace of 4x3 computer screens to 16x9 and 16x10 screens (so-called widescreen format). …
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.

630 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