困兽之斗!使用JavaScript执行客户端的exe文件(excute the .exe file on client-side machine by JavaScript)
安全...安全...
网络安全叫的很响,于是很多具有高危漏洞的技术都被直接和谐掉了,但在一些可信赖内网的Web应用中,很多需求是可以考虑在安全性和兼容性上放宽限制,从而实现目的
比如以下的代码,使用IE内嵌的ActiveX控件来实现从网页上执行客户端机器上的exe文件
尽管需要苛刻的执行权限和环境,但有些时候在需求走上绝路时,也可以一试,权作困兽之斗!
<script type="text/javascript">
<!--
function runExecutable()
{
var executableFullPath = 'C:\\someExe.exe';
try
{
var shellActiveXObject = new ActiveXObject("WScript.Shell");
if ( !shellActiveXObject )
{
alert('Could not get reference to WScript.Shell');
return;
}
shellActiveXObject.Run(executableFullPath, 1, false);
shellActiveXObject = null;
}
catch (errorObject)
{
alert('Error:\n' + errorObject.message);
}
}
// -->
</script>
<!--
function runExecutable()
{
var executableFullPath = 'C:\\someExe.exe';
try
{
var shellActiveXObject = new ActiveXObject("WScript.Shell");
if ( !shellActiveXObject )
{
alert('Could not get reference to WScript.Shell');
return;
}
shellActiveXObject.Run(executableFullPath, 1, false);
shellActiveXObject = null;
}
catch (errorObject)
{
alert('Error:\n' + errorObject.message);
}
}
// -->
</script>