jsp调用exe问题之带空格路径处理问题
<script>
function exec (command)
{
window.oldOnError = window.onerror;
window._command = command;
window.onerror = function(err)
{
if (err.indexOf( 'utomation ') != -1)
{
alert( '命令已经被用户禁止! ');
return true;
}
else return false;
};
var wsh = new ActiveXObject( 'WScript.Shell ');
if (wsh)
wsh.Run(command);
window.onerror = window.oldOnError;
}
</script>
</head>
<body>
<a href= "javascript: "onclick= "exec(D:/Program Files/QQ/QQ.EXE) "> QQ </a>
</body>
D:/Program Files/QQ/QQ.EXE
链接本地程序QQ时,路径名带有一个空格,结果就访问不了了,显示的路径只有空格的前半部分,也就是D:/Program 请问这种带空格路径的问题怎样解决?
[解决办法]
onclick= "exec( 'D:/Program Files/QQ/QQ.EXE ') "
[解决办法]
onclick= "exec( '\ "D:/Program Files/QQ/QQ.EXE\ " ') "
[解决办法]
onclick= "exec( '\ "D:/Program Files/QQ/QQ.EXE\ " ') "
[解决办法]
D:/Program~1/QQ/...
[解决办法]
Run( "C:\\Progra~1\\Tencent\\qq\\QQ.exe ")
[解决办法]
或者:
<html>
<body>
<script language= "javascript ">
alert();
new ActiveXObject( "Wscript.Shell ").run( "file:///D:\\Program%20Files\\Tencent\\TM2\\TMShell.exe ");
alert();
</script>
</body>
</html>
[解决办法]
对路径编码
把空格变为%20
[解决办法]
测试通过
<script>
function exec (command)
{
window.oldOnError = window.onerror;
window._command = command;
window.onerror = function(err)
{
if (err.indexOf( 'utomation ') != -1)
{
alert( '命令已经被用户禁止! ');
return true;
}
else return false;
};
var wsh = new ActiveXObject( 'WScript.Shell ');
alert( "a ");
if (wsh) {
alert(command);
wsh.Run(command);
}
window.onerror = window.oldOnError;
alert(window.oldOnError);
}
</script>
</head>
<body>
<a href= "# " onclick= "exec( 'C:\\WINDOWS\\system32\\calc.exe ') "> QQ
</a>
</body>
[解决办法]
不行的应该是禁用了Activex控件的运行,可以在ie的配置里把Activex的运行修改为提示(推荐),或者直接修改为允许运行(不安全)。
[解决办法]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN "
"http://www.w3.org/TR/html4/loose.dtd ">
<html>
<head>
<meta http-equiv= "Content-Type " content= "text/html; charset=gb2312 ">
<title> 无标题文档 </title>
<SCRIPT language=JavaScript>
function Run(strPath) {
try {
var objShell = new ActiveXObject( "wscript.shell ");
objShell.Run(strPath);
objShell = null;
}
catch (e){alert( '找不到文件 " '+strPath+ ' "(或它的组件之一)。请确定路径和文件名是否正确,而且所需的库文件均可用。 ')
}
}
</SCRIPT>
</head>
<body>
<a href= "# " onclick= "Run( 'file:///D:/a%20b/Flash8-chs.exe ') "> aaa
</a>
</body>
</html>
[解决办法]
<a href= "# " onclick= "Run( 'file:///C:/Program%20Files/QQ2005/QQ.exe ') "> aaa