JS invoke executable (EXE) file (ie only available)

Source: Internet
Author: User

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;
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.