'Get the value of a registry key within wow6432node using a batch script?
I have a batch script below (which I was able to derive from Open a file in Visual Studio at a specific line number and How can I get the value of a registry key using a batch script? ).
@echo off
for /f "tokens=3*" %%x in ('reg query "HKLM\SOFTWARE\Microsoft\Window\CurrentVersion\App Paths\devenv.exe"') do set DEVENV="%%x %%y"
%DEVENV% /Command "Edit.Goto %1" "E:\Bat\Example\Sample\%2"
@echo off
I run the above batch script using a Javascript code given below, where the values of %1 and %2 are passed by this Javascript as a number (10) and a path (examples/helloWorld/helloWorld.cpp) as shown below
<html>
<head>
<script language="JavaScript" type="text/javascript">
MyObject = new ActiveXObject( "WScript.Shell" )
function Goto()
{ MyObject.Run("D:/GoToLine2.bat 10 examples/helloWorld/helloWorld.cpp") ;}
</script>
</head>
<body>
<h1>Run a Program</h1>
This script launches a bat file >> <p>
<button onclick="Goto()">Run BatFile</button>
</body>
</html>
My problem is that the registry key of "E:\Bat\Example\Sample" is HKLM\SOFTWARE\Wow6432Node\BI\Science\AB and I don't know how to get its value so that I need not have to pass the path as E:\Bat\Example\Sample\ in the batch file, but just get it from the registry and append the "%2" (which I get from the Javascript code - i.e. examples/helloWorld/helloWorld.cpp) to its value. I'm using a windows 7 64 bit PC.
Solution 1:[1]
I don't really get why you're bothering with a batch script anyway. Since you're already creating a WScript.Shell object, which is used both for executing a program and for reading from the registry, why not do the whole thing in JavaScript?
<html>
<head>
<script language="JavaScript" type="text/javascript">
function Goto(line, file) {
var osh = new ActiveXObject("WSH.Shell");
var devenv = osh.RegRead('HKLM\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths\\devenv.exe');
// is the file variable a full path? If not, get path from registry.
var batsample = /^\w\:\\/.test(file)
? file
: osh.RegRead('HKLM\\SOFTWARE\\Wow6432Node\\BI\\Science\\AB')
+ '\\' + file;
osh.Run(devenv + ' /Command "Edit.Goto ' + line + '" "'
+ batsample + '"');
}
</script>
</head>
<body>
<h3>Run a Program</h3>
<p>Click this to go to line 10 of helloWorld.cpp.
<button onclick="Goto(10, 'examples\\helloWorld\\helloWorld.cpp')">Run Editor</button>
</p>
<p>Click this to go to line 20 of helloWorld.cpp.
<button onclick="Goto(20, 'examples\\helloWorld\\helloWorld.cpp')">Run Editor</button>
</p>
<p>Click this to go to line <input type="text" id="line" value="10" />
of <input type="file" id="file" />.
<button
onclick="Goto(document.getElementById('line').value, document.getElementById('file').value)">Run Editor</button>
</p>
</body>
</html>
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
