1

The task is supposed to run a .js file every minute.

To make this happen, I made the task run every day at 00:00 and repeat every 1 minutes.

However, the task now allways has Status of Running without actually doing anything and the Last Run Result is 0x41301 (cannot run because it is allready running).

I tried making a trigger for for each minute (for a few consequtive minutes) and this works. The script was being run every minute (for those minutes), but I cannot make a trigger for each minute of the day...


When I use repetition the process wscript.exe is constantly running, and this is the problem - when I have a trigger for each minute then the process ends itself after each run.

But when I use repetition, it never ends the process and is therefore not able to run the script again. (Hence the error: 0x41301)

I thought I'd be able to solve this by selecting for If the task is already running, then the follow rule applies: the option Stop the existing instance - however, this does not apply to each repetition, it only applies to when the task starts each day - I think; after all this option does not work.


The .js script does not run at all (not even once) when I use repetition; if it did, then I'd make it kill the process of wscript.exe after it was done.

So how do I fix this?


EDIT:

Having tried making a .vbs script and a batch program, to find out whether it's the task or the script that is in the wrong I've discovered that nothing works - my conclusion is therefore that the error lies with the task itself.

I even tried starting Internet Explorer directely from the task and even that did not work.

That is to say: everything works, but not while repetition is active <- any kind of repetition, I've tried a bunch of possible combinations of repetition and other settings, but nothing works.

Is there a secret rule, hidden from the public, that states that whenever repetition is activated, the script has to be written backwards in greek? Because I've tried that and it didn't work!

Levi
  • 185
  • 1
  • 2
  • 9
  • Operating system version? – Greg Askew Mar 27 '14 at 13:37
  • Windows Server 2012 Standard - 64-bit – Levi Mar 27 '14 at 13:39
  • @GregAskew In Task Scheduler, the task is configured for **Windows Vista, Windows Server 2008** - this was the default setting. I just tried changing it to **Windows Server 2012**, same result. – Levi Mar 27 '14 at 13:44
  • Seems like we need to identify why the wscript is not completing. How long does it need to run? Does it work as expected if you increase the frequency to five minutes? – Greg Askew Mar 27 '14 at 13:48
  • @GregAskew The script uses 3 seconds to complete and it runs and completes when I double-click it, and also when I remove the repetition option and just runs it at a specific time. The result is the same no matter what I use for repetiton, 5 minutes or even 1 hour. – Levi Mar 27 '14 at 13:57
  • Also: It does not run at all, not even the first time when I have specified repetition. – Levi Mar 27 '14 at 13:58
  • If you are running wscript.exe, you may need to check the Settings table for "If the task is already running: Do not start a new instance". – Greg Askew Mar 27 '14 at 14:48
  • I've tried this - but it does not work. There could be something wrong with the script itself, I've tried doing the same thing with a .vbs script, but it's the same - I'll give .bat a try – Levi Mar 28 '14 at 07:45
  • @GregAskew Using batch has solved the problem. Through batch I am unable to accomplish everything in a hidden way, but it doesn't really matter. – Levi Mar 28 '14 at 08:19
  • I spoke too soon - the status does shift between **Running** and **Ready** and the **Last Run Result** shows 0x0, but it still doesn't work. The script is simply supposed to open a website, that in turn does a task... – Levi Mar 28 '14 at 08:24
  • I've also tried starting Internet Explorer (instead of my script) with the website I want to load as the argument - this works, but not when I have activated repetition! What is wrong with using repetition... it never loads the website when I have repetition enabled. – Levi Mar 28 '14 at 08:45

1 Answers1

1

The solution was rather simple, but not obvious.

My original VBS script was basically like this:

Set objExplorer = WScript.CreateObject _("InternetExplorer.Application", "IE_")
objExplorer.Navigate "https://domain.com/place/?token=key"

'Make window invisible
objExplorer.Visible = 0

'Wait for URL to load properly, then quit
WScript.Sleep 6000
objExplorer.quit

This script uses Internet Explorer to load the website - this works, but when I added repetition to the task it did not work.

The reason why it did not work is still unclear to me, but I imagine the usage of repetition will open Internet Explorer again and again within the same "task" and using the same temporary memory (or something), and then each repetition will find it unnecessary to load the website because it is allready in the memory...

This might be incorrect, but I solved the problem by replacing the script with this:

On Error Resume Next
dim ObjRequest
dim URL
URL = "https://domain.com/place/?token=key"

CreateObject("Microsoft.XMLHTTP")
objRequest.open "GET", URL, false
objRequest.Send

Set objRequest = Nothing

Everything now works perfectely.

Levi
  • 185
  • 1
  • 2
  • 9