注意:: 如果调用不成功,除了安全性因素之外,可能是应用程序出错.自己写的代码就是如此,调用系统的记事本没有问题.但是调用自己的程序时就发现程序不能运行,一直找原因,甚至以为是Wscript.shell的问题,结果最终发现是自己程序的问题.
代码如下:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title> WScript.Shell Run Programs. </title>
<meta name="Generator" content="EditPlus">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
<script type="text/javascript">
function Run(strPath, args){
try{
var objShell = new ActiveXObject("WScript.Shell");
var cmdArgs = "";
if(typeof args === "object"){
for(var item in args){
cmdArgs += " " + args[item];
}
}else if(typeof args === "string"){
cmdArgs = args;
}else{
alert("错误的参数类型");
return;
}
var runCmd = "\"" + strPath + "\"" + cmdArgs;
var result = objShell.Run(runCmd);
}catch(e){
alert("找不到文件" + strPath);
}
}
function readRegedit(){
var obj = new ActiveXObject("WScript.Shell");
var sPath = "HKEY_CURRENT_USER\\SOFTWARE\\XXXProg\\XXXProperty";
var sNic = obj.RegRead(sPath);
return sNic;
}
function RunScan(){
var path = readRegedit();
//alert(path);
if(path != ""){
//alert(arguments);
Run(path, arguments);
}
}
</script>
</head>
<body>
<button onclick="RunProg('-run', 'xxx.txt', 5)">Run Button</button>
<br/>
<div id="content"></div>
</body>
</html>