使用批处理脚本获取wow6432node中的注册表项的值?

时间:2013-03-29 17:52:42

标签: javascript javascript-events batch-file batch-processing

下面有一个批处理脚本(我可以从Open a file in Visual Studio at a specific line numberHow 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

我使用下面给出的javascript代码运行上面的批处理脚本,其中%1%2的值由此java脚本作为数字(10)和路径({{1}传递}})如下所示

examples/helloWorld/helloWorld.cpp

我的问题是“E:\ Bat \ Example \ Sample \”的注册表项是<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> ,我不知道如何获取它的值,所以我不需要传递路径为{{ 1}}在批处理文件中,但只是从注册表中获取它并将“%2”(我从java脚本代码中获取 - 即HKLM\SOFTWARE\Wow6432Node\BI\Science\AB)附加到其值。我使用Windows 7 64位电脑。提前致谢

2 个答案:

答案 0 :(得分: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%

应该完成任务。这基本上是your earlier question的重复,你还没有接受答案。

答案 1 :(得分:0)

我真的不明白你为什么还要打扰批处理脚本。由于您已经创建了一个WScript.Shell对象,该对象同时用于executing a programfor reading from the registry,为什么不在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>