-2

我在下面有一个批处理脚本(我可以从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该 Javascript 作为数字 (10) 和路径 ( examples/helloWorld/helloWorld.cpp) 传递,如下所示

<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>

我的问题是“E:\Bat\Example\Sample”的注册表项是HKLM\SOFTWARE\Wow6432Node\BI\Science\AB并且我不知道如何获取它的值,因此我不必像E:\Bat\Example\Sample\批处理文件中那样传递路径,而只需获取它从注册表中,并将“%2”(我从 Javascript 代码中获得 - 即examples/helloWorld/helloWorld.cpp)附加到它的值。我正在使用 Windows 7 64 位 PC。

4

2 回答 2

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%

应该做的任务。这本质上是您之前尚未接受答案的问题的重复。

于 2013-03-29T18:16:14.220 回答
0

无论如何,我真的不明白您为什么要打扰批处理脚本。既然您已经创建了一个WScript.Shell对象,它既用于执行程序用于从注册表中读取,为什么不使用 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>
于 2013-03-29T18:25:44.373 回答