[Home]  [Edit this page]  [Recent Changes]  [Special Pages]  [Help
How_To_Javascript_Run_Executable_On_Client

How to run an executable program on the client?

Client-side scripts themselves cannot make system calls but on Windows systems you can insert Windows Script Host commands in client-side script.

To launch an application on the client machine, place this script in the head of the HTML page.

<script language="javascript" type="text/javascript">
function runApp() 
{ 
var shell = new ActiveXObject("WScript.shell"); 
shell.run("notepad.exe", 1, True); 
} 
</script>


Place this in the body of the HTML page. The button click will trigger off the function and the application is run.

<input type="button" name="button1" value="Run Notepad" onClick="runApp()" />


var shell = new ActiveXObject("WScript.shell");


Creates the WSH object as a new instance of an ActiveXObject.

shell.run("notepad.exe", 1, True);


The run method of WSH starts the executable program.

The first parameter passed into the run method executes the command "notepad.exe".

The second parameter is optional and its integer value specifies the window style of the application launched. The 1 value will activate and display the window.

The third parameter is optional and its boolean value specifies if it is to wait for the command to complete before further execution. The True value will wait for the completion of the command.

Note that running such scripts properly require to change the client's security settings.

Related threads:
Opening a .exe or .xls file through JS...
How Do I Execute Shelll Commands?

JavaScript FAQ

last edited (April 28, 2004) by lillu, Number of views: 13321, Current Rev: 2 (Diff)

[Edit this page]  [Page history]  [What links here]  [Discuss this topic]  [Printer Friendly]  

Members

Username:

Password:


Register
Forgot Password?




Programmers Heaven - for .NET, Java, C/C++ and WEB Developers!
© 1996-2008 Community Networks Ltd. All rights reserved. Reproduction in whole or in part, in any form or medium without express written permission is prohibited. Violators of this policy may be subject to legal action. Please read Terms Of Use and Privacy Statement for more information. Development by Tore Nestenius at .NET Consultant - Synchron Data.