Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2011-02-22
5
Medium Priority
?
657 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 2000 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

What Is Blockchain Technology?

Blockchain is a technology that underpins the success of Bitcoin and other digital currencies, but it has uses far beyond finance. Learn how blockchain works and why it is proving disruptive to other areas of IT.

Question has a verified solution.

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

A quick guide on how to use Group Policy to create a custom power plan and set it active on Windows 7.
There are many software programs on offer that will claim to magically speed up your computer. The best advice I can give you is to avoid them like the plague, because they will often cause far more problems than they solve. Try some of these "do it…
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…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Suggested Courses

670 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