Latest tutorial: Making a Movieclip face another Movieclip or point on the stage | Ask Tutorial5!
 

How to launch an application with JavaScript

(9 votes)
Software - Tweaks
Written by Michael D.   

java-logo.jpg
Here is a simple script that can be used to launch an application when accessed.


Insert the code bellow in the <body> of your HTML file.

<SCRIPT Language="JScript">
function runcmd() {
File="cmd.exe";
WSH=new ActiveXObject("WScript.Shell");
WSH.run(File);
}
</SCRIPT>


<A href="#" onClick="runcmd(); return false;">Run CMD.exe</A>

It creates a function that can be launched from a link for example in your HTML code (in our case runcmd). This will run the File variable that must be set - i used cmd.exe in my example. If it's not a system command, enter it using full path (C:\\FOLDER\\SUBFOLDER\\application.exe for example).

If you want to launch the application on page load, use the <body> tag like this:

<body onLoad="javascript:runcmd();">

Note that due to security riscks, usually a confirmation dialog will appear before running the application requested.

The script works well on Internet Explorer. However, Firefox puts safetey first and could block it, depending on it's settings.



Subscribe now via RSS feed and get all the new tutorials

written by gumi , December 23, 2007

I want to learn more about javascript
written by Adept Infotech , January 27, 2008

I want to Know the difference between havascript and javascript 1.0
written by Confused , March 05, 2008

How can you run an application from a USB drive. i.e. if I have a .html page on a flash drive and I want to use this javascript within that webpage to launch a java program also stored on the USB flash drive.

the FILE="cmd.exe"; looks on the computer, how do you change this to look in the USB drive where the .html page this javascript code is running from is stored?

Thanks
written by hamza , June 17, 2008

hi , i like this but how i can remove the confirmation messeg window before running the application requested and run directely my application requested

Do you need more help? Ask now!
 

busy
Last Updated ( Sunday, 22 April 2007 )