EXE from JavaScript [duplicate]
Possible Duplicate:
How can I run a program or batch file on the client side?
I am new to JavaScript. I am trying to execute an EXE file from JavaScript on the web browers. How can it be done with simple code?
That is not possible due to security reasons. Imagine you are trying to access the file system of the client.
This is usually disallowed due to security reasons, if you absolutely need to do this then you have a few options however:
- Prompt the user to download and run the executable
- Use the WScript.Shell object
See this question for details on how to do this. Note that this almost certainly won't work on most browsers unless your site has been placed into some sort of "trusted" zone (which may be the case if you are developing an intranet application or running inside a Html Application / .hta)
- Use an ActiveX control (this will also require elevated permissions, however it is more likely that you will at least be able to prompt the user for permissions)
All 3 of these options require trust to be granted by the user (they will either have to have placed your page / site into a certain trust level, or they will have to have clicked on some sort of "trust this site" / "download this file" dialog.
(Also note that all of these options are speicfic to the Windows operating system)
As sAc says, it's not possible to directly run an exe file, though you may want to look into Google NaCl if you wish to do native code execution in a web browser. Also, please note that exe is a Windows format, and it would be very uninterpretable with other OSes and detrimental to the open web if you could run them through a browser.
It is possible if you lower the security level on your browser ..BUT that's not a good idea!
for example, in IE you can do this: write a run function:
function run(file) {
var ws = new ActiveXObject("WScript.Shell");
ws.run(file);
}
and then for example: ....
onclick = run("file:///C:/Program%20Files/My%20Documents/yourFile.exe")
精彩评论