Javascript 是否使用批处理脚本获取wow6432node中注册表项的值?
下面我有一个批处理脚本(我可以从中派生出来,感谢2个u组成员) 我使用下面给出的javascript代码运行上述批处理脚本,其中Javascript 是否使用批处理脚本获取wow6432node中注册表项的值?,javascript,javascript-events,batch-file,batch-processing,Javascript,Javascript Events,Batch File,Batch Processing,下面我有一个批处理脚本(我可以从中派生出来,感谢2个u组成员) 我使用下面给出的javascript代码运行上述批处理脚本,其中%1和%2的值作为数字(10)和路径(examples/helloWorld/helloWorld.cpp)由该java脚本传递,如下所示 <html> <head> <script language="JavaScript" type="text/javascript"> MyObject = new ActiveXObject(
%1
和%2
的值作为数字(10)和路径(examples/helloWorld/helloWorld.cpp
)由该java脚本传递,如下所示
<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>
MyObject=newActiveXObject(“WScript.Shell”)
函数Goto()
{MyObject.Run(“D:/GoToLine2.bat 10个示例/helloWorld/helloWorld.cpp”);}
运行程序
此脚本启动bat文件>>
运行BatFile
我的问题是“E:\Bat\Example\Sample\”的注册表项是
HKLM\SOFTWARE\Wow6432Node\BI\Science\AB
,我不知道如何获取它的值,因此我不需要在批处理文件中以E:\Bat\Example\Sample\
的形式传递路径,而只需从注册表中获取它并附加“%2”(这是我从java脚本代码中获得的,即examples/helloWorld/helloWorld.cpp
)转换为它的值。我使用的是一台windows 7 64位pc。提前感谢
@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%
应该完成任务。这基本上是一个重复,你还没有接受答案。我真的不明白你为什么要用批处理脚本。既然你已经创建了一个
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>
函数转到(行、文件){
var osh=新的ActiveXObject(“WSH.Shell”);
var devenv=osh.regrad('HKLM\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App path\\devenv.exe');
//文件变量是否为完整路径?如果不是,请从注册表获取路径。
var batsample=/^\w\:\\/.test(文件)
文件
:osh.regrad('HKLM\\SOFTWARE\\Wow6432Node\\BI\\Science\\AB')
+“\\”+文件;
运行(devenv+'/Command“Edit.Goto'+line+''
+样本+“”);
}
运行程序
单击此按钮转到helloWorld.cpp的第10行。
运行编辑器
单击此按钮转到helloWorld.cpp的第20行。
运行编辑器
单击此按钮转到第行
属于
运行编辑器
是HKLM\SOFTWARE\Wow6432Node\BI\Science\AB
一个键(一个文件夹),您需要(默认值)
,还是HKLM\SOFTWARE\Wow6432Node\BI\Science
包含名为AB
的字符串项的键?HKLM\SOFTWARE\Wow6432Node\BI\Science\AB是一个文件夹(键).我不想要default的值我想要(INSTDIR)的值,它紧跟在default之后(第二行):)…对不起,完全忘记了..我确实尝试了上面的代码,但它抛出了一个错误,表示系统无法找到指定的注册表…这次我将示例文件夹放在路径D:\Program Files\VideoLAN\VLC…中,VLC的注册表项名称为HKEY\U LOCAL\U MACHINE\SOFTWARE\VideoLAN\VLC,以及我想要的值数据(即路径)来自值名称InstallDir(在默认值之后)…如何实现此操作???。请提前感谢在REG QUERY
行中,用所需的键替换带引号的字符串,并用值替换/v
后面的项,并更改目标变量名称以适应。我在ECHO
之前添加的SET
只是将所有/
转换为`因为/`用作命令开关,而不是目录分隔符。我只是尝试了一下,但没有一个按钮起作用:(我所做的只是函数Goto(line,file){var osh=new ActiveXObject(“WSH.Shell”);var devenv=osh.regrad('HKLM\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App path\\devenv.exe');var batsample=osh.regrad('HKEY\U LOCAL\u MACHINE\SOFTWARE\VideoLAN\VLC')+'\\'+文件;osh.Run(devenv+'/Command“Edit.Goto'+line+'+batsample+');)如何在文件夹(键)HKEY\U LOCAL\U MACHINE\SOFTWARE\VideoLAN\VLC..中获取默认值之后的值名称InstallDir的值数据,以便将路径(文件)-(即“examples\\helloWorld\\helloWorld.cpp”)附加到其值中
<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>