-2

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.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Dan K
  • 218
  • 5
  • 12
  • Is `HKLM\SOFTWARE\Wow6432Node\BI\Science\AB` a key (a folder) and you want the value of `(Default)`, or is `HKLM\SOFTWARE\Wow6432Node\BI\Science` the key containing a string item named `AB`? – rojo Mar 29 '13 at 18:05
  • HKLM\SOFTWARE\Wow6432Node\BI\Science\AB is a folder (key).i dont want the value of default I want the value of (INSTDIR)- which is right after default (2nd in the row) :)... – Dan K Mar 30 '13 at 06:45

2 Answers2

2
@ECHO OFF
SETLOCAL 
FOR /F "tokens=2*" %%A IN (
   'REG QUERY "HKLM\SOFTWARE\Wow6432Node\BI\Science" /v AB'
) DO (set yourpath=%%B%2)
set yourpath=%yourpath:/=\%
ECHO %yourpath%

Should do the task. This is essentially a repeat of your earlier question for which you haven't yet accepted an answer.

Community
  • 1
  • 1
Magoo
  • 77,302
  • 8
  • 62
  • 84
  • Sorry totally forgot..and i did try the above code but it throws an error saying that the system was unable to find the specified registry...This time i put my examples folder within the path D:\Program Files\VideoLAN\VLC...and the registry key name of VLC is HKEY_LOCAL_MACHINE\SOFTWARE\VideoLAN\VLC and the value data i want (i.e the path) is from the value name InstallDir (right after default)..How can i make this happen??..Thanks in advance – Dan K Mar 30 '13 at 06:33
  • In the `REG QUERY` line, Replace the quoted string with the KEY you want and the item following `/v` with the **V**alue and change the destination variablename to suit. The `SET` I added before the `ECHO` simply converts all `/` to `\` because `/` is used as a command switch, not a directory separator. – Magoo Mar 30 '13 at 06:51
0

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>
rojo
  • 24,000
  • 5
  • 55
  • 101
  • I just tried this out but none of the buttons worked :(All i did was function Goto(line, file) { var osh = new ActiveXObject("WSH.Shell"); var devenv = osh.RegRead('HKLM\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths\\devenv.exe'); var batsample = osh.RegRead('HKEY_LOCAL_MACHINE\SOFTWARE\VideoLAN\VLC')+ '\\' + file; osh.Run(devenv + ' /Command "Edit.Goto ' + line + '" "'+ batsample + '"'); } – Dan K Mar 30 '13 at 07:04
  • How can i get the value data of value name InstallDir which is right after default within the folder (key)HKEY_LOCAL_MACHINE\SOFTWARE\VideoLAN\VLC..so that i can append the path (file)- (i.e 'examples\\helloWorld\\helloWorld.cpp')..to its value – Dan K Mar 30 '13 at 07:07