tags:

views:

141

answers:

3

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>
+2  A: 

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.

BoltBait
Thanks, but i need to check for a folder, if that is present i need to open the EXE inside of that folder.
Karthick
You have most of the code already (in your question). I'm just giving you the part you're missing.
BoltBait
Thanks Boltbait, if possible please show how to hide in CSS.
Karthick
+1  A: 

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.

Diodeus
A: 

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.

bobince
Thanks bobince, but the EXE is into a folder and when i givelocation.href= 'tmp//Open.EXE'; its not opening the EXE.
Karthick
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.
bobince
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?
Karthick
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.
bobince
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?
Karthick
Yeah, you can't sniff for the existence of a folder like that at all; `FileSystemObject` would only work from a local file in IE and then only with non-standard lax security permissions, and then you'd still have to work out your own absolute filepath by tediously translating it from your URL.
bobince
Thanks, but do you any option/sample to implement this?
Karthick
Implement what? Are you saying you're a local HTML file on the filesystem? Even if you were, and you converted the `'file:///C:/xxx/tmp'` URL to a Windows `'C:\\xxx\\tmp'` path by stripping off the `file:///` and translating `'/'` to `'\\'`, you'd *still* have something that only worked in IE, and only worked after the user had clicked through warnings telling them what you are doing is unsafe. And with reason: with the FileSystemObject you could steal or delete all their documents. It's not worth all this to see if a folder exists. Find enough way.
bobince
For example, if when the directory was created you could also put a file called `presence.js` inside, containing `var iexist= true;`, you could easily include that in the HTML file with `<script src="tmp/presence.js">` and sniff for it with `if (window.iexist) ...`.
bobince