Search code examples
javascriptscheduled-taskshtawindows-task-scheduler

Task Scheduler not running HTA files


Task Scheduler does not seem to run HTA files. I have the action like this:

Action: "start an application"
program/script path: C:/TestMeeting.hta
Start In: C:/

So it should run the HTA, but when the task is triggered it does nothing. It says that it's status is running. It never stops and I have to manually stop it. Another thing I tried was using "C:\Windows\SysWOW64\mshta.exe" for the program path then put the HTA path in the "Add argument" box. It runs and says it successfully completed but nothing happens.

So how do I run HTA files using Task Scheduler?

Here is the code in the HTA (in case it matters):

<Script Language=JavaScript>
    var window = open("https://ww2.livelesson.com/REMOVED_FOR_SECURITY_REASONS");
    function SignIn() {
    setTimeout(function(){
    try{
    var corral = window.document.getElementsByClassName("loginField coral3-Tab")[0];
    corral.click();
    var text = window.document.getElementsByClassName("coral-Textfield login-textfield coral3-Textfield coral3-Textfield--quiet")[0];
    text.value = "Name";
    var button = window.document.getElementsByClassName("coral3-Button coral3-Button--cta enterRoom")[0];
    button.click();
    closeEveyThing();
    } catch (error) {
    SignIn();
    }
    }, 500);
    }
    function closeEveyThing() {
    setTimeout(function(){
    window.close();
    close();
    },10000);
    }
    SignIn();
    </Script>

UPDATE: I found out you can run mshta.exe with the path of the HTA as the arguments in bash:

cd
/mnt/c/Windows/System32/mshta.exe C:/TestMeeting.hta

It runs fine so It seems weird that running C:/Windows/System32mshta.exe with C:/TestMetting.hta in the arguments does not work.


Solution

  • I still don't know why does not run HTA files, but it can run .bat files. If you put the following code in an .bat file and run the .bat file it will work.

    cd
    mshta.exe C:/PATH_TO_HTA/Example.hta