Solved

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

Posted on 2011-02-22
5
625 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
  • 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

New Windows 7 Installations take days for Windows-Updates to show up and install. This can easily be fixed. I have finally decided to write an article because this seems to get asked several times a day lately. This Article and the Links apply to…
The recent Microsoft changes on update philosophy for Windows pre-10 and their impact on existing WSUS implementations.
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…

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

22 Experts available now in Live!

Get 1:1 Help Now