0

我有下面的Javascript。我想获取特定注册表项中值名称的数据。例如,如果键是HKEY_LOCAL_MACHINE\\SOFTWARE\\VideoLAN\\VLC,值名称是InstallDir,我怎样才能得到InstallDir(这是一个路径,即D:\Program Files\VideoLAN\VLC)的数据。如何在 JavaScript 或 VBScript 中获取此路径?

<html>
<head>
<script language="JavaScript" type="text/javascript">
  MyObject = new ActiveXObject( "WScript.Shell" )
  function Goto()
  {
    var bat= MyObject.RegRead("HKEY_LOCAL_MACHINE\\SOFTWARE\\VideoLAN\\VLC\\InstallDir");
    MyObject.Run("bat/GoToLine2.bat 10 /examples/helloWorld/helloWorld.txt") ;
  }
</script>
</head>
<body>
<button onclick="Goto()">Run BatFile</button>
</body>
</html>

如您所见,我希望将 的文件路径InstallDir保存在变量 (bat) 中以运行GoToLine2.bat位于InstallDir(ie ) 的值数据中的批处理文件 ( D:\Program Files\VideoLAN\VLC)。你能告诉我如何获得这条路径,这样我就不必使用

MyObject.Run("D:/Program Files/VideoLAN/VLC/GoToLine2.bat 10 /examples/helloWorld/helloWorld.txt");
4

2 回答 2

0

在某些语言中,您可以使用变量插值/替换将变量的内容放入字符串文字中:

perl -e 'my $v = "c"; my $s = "${v}x"; print $s, "\n";'
cx

VBScript 和 J(ava)script 都没有这个特性:

% v = "c" // given variable v containing "c"
c
% s = "vx" // j(ava)script does not interpolate
vx
% s = v + "x" // so use concatenation
cx

Another option is to use Replace instead of concatenation:

>> v = "c"
>> s = Replace("$vx", "$v", v)
>> WScript.Echo s
>>
cx
于 2013-03-30T18:58:35.937 回答
0
MyObject.Run(bat + "\\GoToLine2.bat 10 /examples/helloWorld/helloWorld.txt");

Ok, I think I get what's wrong. The path has space, so you need to enclose it with quotes, i.e.:

MyObject.Run("\"" + bat + "\\GoToLine2.bat\" 10 /examples/helloWorld/helloWorld.txt");
于 2013-03-31T01:05:56.820 回答