Link to home
Start Free TrialLog in
Avatar of aideb
aideb

asked on

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

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
Avatar of prashanthd
prashanthd
Flag of India image

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

Avatar of aideb
aideb

ASKER

Excellent thanks.

is there anyway to run the batch script hidden?
ASKER CERTIFIED SOLUTION
Avatar of prashanthd
prashanthd
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Did the above code work?
Avatar of aideb

ASKER

Yes it did!.

fantastic - thanks...