I've been asked to see if we can create a sidebar link to an executable and start a program to run that has been installed on a user's local hard drive. Can that be done and what would the syntax look like?

Prior to this, I've only seen links to files in folders saved in an org that because of the mime type would cause WORD or Excel to open. Would we perhaps need to associate the program with a mime type or local path on their machine, and then have the link go to a local folder instead? Also, might this possibly need to be scripted in order to make it work if there is no universal mime type (I'm told there isn't)?

Edit #2

Have tried getting the IE JavaScript from the links Techtrekker posted to work: Run exe file using Java Script for IE and Running Applications Using nsILocalFile.launch() for Firefox, but seem to be having difficulties, so am posting the script I've been using to see if someone can spot the error of my ways.

I've attempted using "straight Javascript" in the Homepage Link to an executable with a path of C:/Program Files (x86)/UltraEdit/UEDIT32.EXE Note: this program isn't important, it just happens to be a 32 bit program I'm using to demonstrate that this will work.

So, as straight script, here's what I put in for the link:

<script language="JavaScript" type="text/javascript">MyObject = new ActiveXObject( "WScript.Shell" )function RunExe(){MyObject.Run("file:///C:/Program%20Files%28x86%29/UltraEdit/UEDIT32.EXE");}</script><link onclick="RunExe()">UltraEdit</link>

Did I perhaps also need to escape the backslashes in the path?

I've also tried creating a custom link page using the code below through adding it as a Home page component and haven't been able to get it to work either. I have it's Behavior set as "Execute JavaScript" and the Content Source as "On Click JavaScript".

 <script language="JavaScript" type="text/javascript">  
     MyObject = new ActiveXObject( "WScript.Shell" )  
     function RunExe()   
        MyObject.Run("file:///C:/Program%20Files%28x86%29/UltraEdit/UEDIT32.EXE") ;  

<link onclick="RunExe()">UltraEdit</link> 

So, could someone please tell me what I've overlooked or not implemented correctly from the link Techtrekker referenced? Its been a number of years since I've done any JavaScript and the 1st method above seemed to be the more logical and no different than what I've done in-line above.

Further, there seems to be a question of how to properly escape the paths from the Salesforce Orgs to the local executables on user machines when using JavaScript and which path format to use. A network path would use a \ notation while a local path would use a / notation. Apex would escape characters with a \ while according to Javascripter.net, Javascript would escape the \ or encode it with a %5C. In the case of the /, it would escape it with another / or encode it with a %2F.

Needless to say, I'd be most appreciative of some clarification of how best to implement this as I've tried various combinations and don't seem to be able to get the IE version to work (am using IE8 and WinXP-64). Once I do, I'd like to get the Firefox version working for the client too.

  • Yes its possible to do via Javascript dotnetspider.com/resources/19547-Run-exe-file-Java-Script.aspx has the IE JS - running it with Firefox developer.mozilla.org/en-US/docs/Code_snippets/… Commented May 22, 2013 at 21:25
  • Thanks for the links techtrekker! Everything I was finding in the SF docs was leading me to the conclusion that Javascript would probably be the only way to do it! You've saved me some legwork. :)
    – crmprogdev
    Commented May 23, 2013 at 3:12
  • No problem, that's the way I've done it in the past, and it's worked. There are some Firefox security settings you need to do, will try and find that. Commented May 23, 2013 at 5:31
  • Would be very much appreciated techtrekker. Following some links from the 2nd link above, I saw some chrome and mozilla references on the subject, but they were at least 5 yrs old, so not certain if they were still applicable. Appeared to be a totally different approach.
    – crmprogdev
    Commented May 23, 2013 at 14:05
  • I keep getting a "URL no longer exists" when I try implementing the IE code from my Dev Org with IE8. Any tips on how you've made this work for you?
    – crmprogdev
    Commented May 23, 2013 at 15:51

1 Answer 1


Try this:

var oShell = new ActiveXObject("Shell.Application");
var commandtoRun = "C:\\Windows\\notepad.exe"; 

Have in mind that ActiveXObject only works on IE, if you are looking for a cross browser solution read this.

How to do it on FF: https://developer.mozilla.org/en-US/docs/Code_snippets/Running_applications

  • I'm a bit (a lot perhaps?) confused. I see you've used "network path" notation via the backslashes (didn't work) to a local path which you've escaped with backslashes like Apex does, but I understood JS to use different escape methods per the references I've checked. However, the Shell notation makes sense to me.
    – crmprogdev
    Commented May 26, 2013 at 13:39
  • Forget about apex. This is only javascript and browser matter. The file path you want to execute is the expected parameter(commandToRun), so, if you are on windows you only have to escape backslashes and spaces as I showed you on my example. Check the links I added Commented May 26, 2013 at 22:41
  • I've gotten into some further debugging and made some progress! I'm now getting the a Permission denied message on this line: oShell.ShellExecute(commandtoRun,"","","open","1"); when I tried to run the code in a visualforce page as part of sorting out the escape issues. I have the browser set to allow active content and the Active X control as well! Any suggestions?
    – crmprogdev
    Commented May 28, 2013 at 17:58
  • I managed to get the code to run on a visualforce page with a link to call the executable. Still no joy on getting it to work directly from a sidebar link but at least I've made progress.:) Thanks!
    – crmprogdev
    Commented May 31, 2013 at 19:11

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .