0

I need to open an EXE from a folder, when the folder is present, using javascript. I have added the code, but am not able to open the EXE after checking the folder, please share your thoughts.

<html>
    <body>
    <script language="JScript">
    <!--
    function checkfolder()
    { 

        var myObject;
        myObject = new ActiveXObject("Scripting.FileSystemObject");

        if(myObject.FolderExists("\\tmp"))
 {
            alert("tmp Folder Exists");
        }  
 else
 {
           alert("tmp Folder doesn't exist"); 
        }
     }

    -->
    </script>
    Check for folder "tmp"
    <form name="myForm">
    <input type="Button" value="Check Folder" onClick='checkfolder()'>
    </form>
    </body>
    </html>
8
  • 2
    This sounds like a security nightmare waiting to happen. I haven't researched the topic but I'd highly doubt that JS would be able to execute an EXE file. Commented May 5, 2010 at 17:24
  • In html, i can open the EXE like this <a href="Open.EXE">Open</a> but i am wondering on how we do it in j.script? Commented May 5, 2010 at 17:26
  • Is this a web page, or a stand alone app? You can probably do this from a HTA file. Commented May 5, 2010 at 17:26
  • You can't execute files using Scripting.FileSystemObject. Commented May 5, 2010 at 17:28
  • This is a static html page, if you have some other approach, please share your idea. Commented May 5, 2010 at 17:33

3 Answers 3

2

You can do it this way:

<html>
<body>
<a href="paint.exe" id="mylink">paint</a>
<script>
     document.getElementById('mylink').click();
</script>
</body>
</html>

Enjoy.

Of course, if you don't want the link to show, use CSS to hide it.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks, but i need to check for a folder, if that is present i need to open the EXE inside of that folder.
You have most of the code already (in your question). I'm just giving you the part you're missing.
1

If you have SQL Server available you can call an EXE from a stored procedure or through a DTS/SSIS package. You can call that from a SQL statement via ODBC using .NET or classic ASP.

Comments

0

In html, i can open the EXE like this <a href="Open.EXE">Open</a>

Yes. That's about all you can do.

Re BoltBait's answer, calling click() on a link doesn't work (specifically, it does not have the default action of following the link).

You have to assign to the browser's location:

location.href= 'Open.EXE';

to navigate directly to the URL of a link, causing a file open/download prompt to appear. But note that some browsers will even block that for security reasons, when not initiated by a user click.

Really, the best you can do is provide your HTML link and ask the user to click it to download and run the EXE it links to. Anything else is potentially user-hostile and prone to failure.

9 Comments

Thanks bobince, but the EXE is into a folder and when i give location.href= 'tmp//Open.EXE'; its not opening the EXE.
The directory separator in an HTTP URL is a single slash (tmp/Open.EXE) regardless of whether the filesystem on the server uses a forward slash or backslash for directory separators.
Yes i tried with / slash but it opens the path of the EXE in IE and displays Internet Explorer cannot display the webpage instead of showing run and save option, any help?
You still haven't got the right path then. For tmp/Open.EXE, the file must be in a folder called tmp in the same folder on the server as the HTML file. If you are serving it from a non-Windows server, the case must also be correct: ie. if the file is called open.exe, linking to it as Open.EXE won't work.
Thanks a lot, the path was incorrect you are genius, also one last question: if(myObject.FolderExists("\\tmp")) { alert("tmp Folder Exists"); } else { alert("tmp Folder doesn't exist"); } This always display tmp doesn't exist although i created tmp folder, any syntax error?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.