How to execute a Local File using Html Application?

Did you ever want to run an application from your local resource inside your HTML page? If so, you will face some issues. It will never run any application from local resource directly. It may ask you to download the file before running it. This is due to browser security issue as the code runs inside the browser sandbox.


So, what to do for this? In this post, I will describe you the steps resolve to do this. Read the complete post in order to learn the same.


As I mentioned above, you can’t run application from browser window due to security reasons. To execute file you need to use .HTA applications (which is a HTML Application). HTA applications run outside the browser window just like a normal application and have full trust support.


If you are new to Html Application, read more about it here: http://msdn.microsoft.com/en-us/library/ms536471(v=VS.85).aspx


Let’s jump to create one Html Application to launch the notepad for you (without any security warnings). To do this, design your Html page with a button, which will execute the notepad once clicked. You can set some application specific properties using the <HTA:APPLICATION /> tag. This step is optional. Add the following JavaScript code inside your <head /> tag:


<script type="text/javascript" language="javascript">
    function RunFile() {
    WshShell = new ActiveXObject("WScript.Shell");
    WshShell.Run("c:/windows/system32/notepad.exe", 1, false);


Here you can see that, first I am creating the instance of the “WScript.Shell” ActiveXObject and then calling the Run() method of the newly created object with proper parameters.


Now, from the button click event give a call to the JavaScript method named “RunFile()”. Once you click on the button, it will execute the file mentioned in the Run() method.


If you run this code inside the browser, it will not work. To resolve this, just save the file with a .hta extension. You will see that, the file icon has changed to application icon. If you double click on this file, it will execute and open a Window having the button inside it. Click the button to open the notepad.exe file.


Here is the full code for that:


    <title>Application Executer</title>
        APPLICATIONNAME="Application Executer" 
    <script type="text/javascript" language="javascript">
        function RunFile() {
        WshShell = new ActiveXObject("WScript.Shell");
        WshShell.Run("c:/windows/system32/notepad.exe", 1, false);
    <input type="button" value="Run Notepad" onclick="RunFile();"/>



So, what is the purpose of it? You may need it in various reasons but that will depend on your requirement. Recently it was needed for me to do one on going R&D and this concept helped me a lot. Hence thought to share this with you, so that, you can also learn & use it in your requirement.

If you have come this far, it means that you liked what you are reading (How to execute a Local File using Html Application?). Why not reach little more and connect with me directly on Twitter, Facebook, Google+ and LinkedIn. I would love to hear your thoughts and opinions on my articles directly.

Don't forget to share your feedback/queries in the comment section below.


  1. good one. i am trying this for my app.

  2. hi,

    I tried your code, but it's not run the notepad. Nothing happen in my IE. Is there something that I missed? how about the IE setting, nothing have to do with this??

    please help,

    1. You must save your file with .hta extension. It will work.

  3. Hi in my case, I open a word document. from other page (.aspx). how I can pass an argumento to .hta page?.

    thanks very much

  4. Hi, I create my page .hta and it work fine. open the notepad.exe Fine.., but I wanna open a word document from other page (.aspx), please how I send an argument?.. file name by example?
    and how obtain this argument from .hta file?

    Thanks very much

  5. Doens happen when click the button... please help !
    no ACTION happens

  6. This worked for me and is awesome. But does bring up a question, if the whole point of HTML coding security is to not allow automatic opening of executable applications, then why is the .HTA work around even in existence? Seems to just null the whole HTML security reasons.

  7. I had this working but it stopped when I upgraded to windows 10. I have IE set up to launch apps and unsafe files but to no avail. Does anyone know what the fix is?

  8. you have to create a separate web page all together .hta and upload it to a real web server the code is only possible if you do it that way writing it to a site as ordinary code will never function.

  9. it worked for me thank u very much.
    please can you tell me how it can be linked with html link

  10. Super. It is Worked for me. Thank you....:)

  11. please do the video

  12. What is the syntax if I wanted to have 2 buttons with 2 different apps? i.e. c:\notepad.exe & C:\wordpad.exe


© 2008-2018 Kunal-Chowdhury.com | Designed by Kunal Chowdhury
Back to top