Jquery:
$ (function () {
$ (' #exsp '). Click (function (EXE) {
exe.value=$ ('. Exsp '). attr (' Val ');
try {
var objshell = new ActiveXObject ("Wscript.Shell");
Objshell.run ($ ('. Exsp '). attr (' Val '));
Objshell = null;
}
catch (EXE) {
Alert (' Cannot find file ' ' +$ ('. Exsp '). attr (' val ') + ' "(or one of its components). Make sure the path and file name are correct, and that the required library files are available. ‘)
}
});
});
Js:
function Run (strpath) {
Exit
Exe.value=strpath;
try {
var objshell = new ActiveXObject ("Wscript.Shell");
Objshell.run (strpath);
Objshell = null;
}
catch (e) {
Alert (' Cannot find file ' ' +strpath+ ' "(or one of its components). Make sure the path and file name are correct, and that the required library files are available. ‘)
}
}
Html:
<input type= "button" id= "Exsp" value= "Play Course" >
Web server JS lets the client execute EXE
There is no problem with calling ActiveXObject locally, the problem occurs on the Web server. Always prompt that the server cannot create objects.
That's because IE is banned from being executed outside the network. So we can prompt the client's IE option to secure a custom level inside the "Initialize and execute script for ActiveX controls that are not marked as safe to execute scripts" is OK, there are four security settings in it. The internet means that all Web sites can run ActiveXObject, which is dangerous for clients to use. We can have the client add our Web server to a trusted site, and then start "Initialize and execute scripts for ActiveX controls that are not marked as safe to execute" on their custom levels.
Call EXE
function exec (command,type) {
try {
if (Navigator.userAgent.indexOf ("MSIE") <= 0) {
Alert ("Please use IE browser view");
Return
}
var fso, F, S;
FSO = new ActiveXObject ("Scripting.FileSystemObject");
if (!FSO. FileExists (command)) {
var msg= "";
if (type== "CZ") {
Msg= "not Found" +command;
}else{
Msg= "may not have the video plugin installed, OK to download the installation?" ";
}
var flag=confirm (msg);
if (flag) {
return "Bucunzai";
}else if (type!= "CZ") {
Return "Cunzai"
}
Return
}
}
catch (e) {
if (e.number==-2146823281) {
var msg= "";
if (type== "CZ") {
Msg= "not Found" +command;
}else{
Msg= "may not have the video plugin installed, OK to download the installation?" ";
}
var flag=confirm (msg);
if (flag) {
return "Bucunzai";
}else if (type!= "CZ") {
Return "Cunzai"
}
Return
}
Alert (e.number+ ":" +e.message);
Alert ("The command has been banned by the user!") Please add this site to the trusted site in the security module of the IE option and start the ' Initialize and execute scripts for ActiveX controls not marked as Safe script ' option in this custom level, then refresh the page ");
Return "command has been banned by the user! Please add this website to < Trusted sites > and < launch > the ' Initialize and execute scripts for ActiveX controls not marked as Safe script ' option in the IE option's security module, then < refresh the > page ";
}
if (type!= "CZ") {
return "Cunzai";
}
Alert (command);
Window.oldonerror = Window.onerror;
Window._command = command;
Window.onerror = function (err) {
if (Err.indexof ("utomation")! =-1) {
Alert ("The command has been banned by the user!") Please add this site to the trusted site in the security module of the IE option and start the ' Initialize and execute scripts for ActiveX controls not marked as Safe script ' option in this custom level, then refresh the page ");
Return "command has been banned by the user! Please add this website to < Trusted sites > and < launch > the ' Initialize and execute scripts for ActiveX controls not marked as Safe script ' option in the IE option's security module, then < refresh the > page ";
} else {
return false;
}
};
var wsh = new ActiveXObject ("Wscript.Shell");
if (WSH) {
Wsh. Run (command);
}
Window.onerror = Window.oldonerror;
return window.oldonerror;
}