How can I run a program or batch file on the client side?

How can I run a batch file on the client side? An exe file? Just to open pre-installed program in client side?


Regarding ActiveX, I tried

    var activeXObj = new ActiveXObject("Shell.Application");
    activeXObj.ShellExecute("C:\\WINDOWS\\NOTEPAD.EXE", "", "", "open", "1");

but this doesn't work. Any suggestions?



From Javascript? You can't. It's a security risk. Think about it - would you want every website to be able to run programs on your PC?


You mean launch an external program thru a browser window using JavaScript? No way you can do that! That's a goddamn security black hole!


If you really have control on the client, then you may want to install some remote daemon service on the client side, like SSH.

PS. Invoke it through your "server-code", however.


Don't be discouraged. You can absolutely do that in safe manner.

  1. First you need a daemon service on the client that will handle the task of invoking your application. Personally, I'd rather build simple rpc-server as windows-service with C++ or Delphi; but many other kinds of server could also do the job (SSH, Apache, Telnet)

  2. Then make a web pages that allow the user to "register" their services with proper authentication to invoke that service (password, security key)

  3. When you want to invoke your application from web-page on the client that's already registered, make ajax call (xmlhttprequest) to your server.

  4. The server should validate the requesting IP address with registered information.

  5. Then make a remote command invokation to the client with the registered information.

There can be some networking situation that this scheme might not work. However, if you really have control on the execution environment then there always be some workarounds.


Redirect the client to http://yourserver/batchfile.bat. Under some browsers, this will prompt the user to run the batch file.


If the problem is the batch file is being displayed in the browser you need to set Content-Type and Content-Disposition in the HTTP header so the user is prompted to Save (or Run) the file rather than have the browser display it.

You won't be able to run the file without an OK from the user but this shouldn't be a problem.

Have a look at this question for a little more detail.


Basically, you can't. If you need to launch something on the client side, you'll need another mechanism altogether, presumably one with some security built in. A previous poster mentioned psexec (, which will obviously only work if you have appropriate permissions on the target system, and which is completely outside the browser.

Basically, what you are asking for is a BIG, BIG, problem if you were able to do it easily.

You might look into ActiveX, but I don't know what limits there are on an ActiveX object these days (I know there ARE limits, but perhaps you can work within them).

<script language="javascript" type="text/javascript">

    function RunEXE(prog) {
        var oShell = new ActiveXObject("WScript.Shell");
        oShell.Run('"' + prog + '"', 1);


Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.