Search code examples
javascriptbatch-filedom-eventsbatch-processing

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

  • @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.