Solved

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

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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

OfficeMate Freezes on login or does not load after login credentials are input.
Possible fixes for Windows 7 and Windows Server 2008 updating problem. Solutions mentioned are from Microsoft themselves. I started a case with them from our Microsoft Silver Partner option to open a case and get direct support from Microsoft. If s…
This Micro Tutorial will teach you how to the overview of Microsoft Security Essentials. This is a free anti-virus software that guards your PC against viruses, spyware, worms, and other malicious software. This will be demonstrated using Windows…
This Micro Tutorial will teach you how to change your appearance and customize your Windows 7 interface to your unique preference. This will be demonstrated using Windows 7 operating system.

757 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

20 Experts available now in Live!

Get 1:1 Help Now