Windows Task Scheduler Doesn't Run VBScript

65,033

Solution 1

After hours of research, one of Blake Morrison (from Microsoft)'s blogs came up; it mentioned that

If running a .vbs / .ps1 script, try launching it from a .cmd / .bat script

see Help! My Scheduled Task does not run…

That blog also explains a lot of rules/tips when using Task Scheduler.

So please create a .cmd/.bat file that calls for your VBScript. For example: cscript.exe YourScript.vbs would be in your .cmd/.bat script.

Solution 2

Write a batch file like this:

echo "Started!" > c:\foldergoeshere\log.txt
cscript.exe "C:\...\script.vbs" > c:\foldergoeshere\log.txt
echo "Stopped!" > c:\foldergoeshere\log.txt

Then schedule the batch file instead of the vbs. That will allow you to see what is happening that is preventing it from running. Any error that you would have seen executing in the console (CMD), will be instead output to that log file between "Started!" and "Stopped!"

Solution 3

What's the hassle all about? I don't use .cmd/.bat and script works! (Windows7 here)
My VBS script (as a scheduled task) runs well on any scenario of these 4:

  1. cscript and option "Run only when user is logged on"
  2. cscript and option "Run whether user is logged on or not"
  3. wscript and option "Run only when user is logged on"
  4. wscript and option "Run whether user is logged on or not"

It's only that on the 1st scenario I encounter the black command window flashing on my screen.

Action settings:

cscript
or
wscript

My script, which simply creates a file:

Set objFSO = CreateObject("Scripting.FileSystemObject")
filename = "C:\Temp\" & Hour(Time) & Minute(Time) & Second(Time)
Set objFile = objFSO.CreateTextFile(filename)

Solution 4

Greg answered this https://superuser.com/a/816073

Basically you need to create 2 folders:

You have to create a folder (or two on a 64bit-windows):

(32Bit, always) C:\Windows\System32\config\systemprofile\Desktop

(64Bit) C:\Windows\SysWOW64\config\systemprofile\Desktop

Fixed the issue for me (and I could point to the .vbs file, not bat needed).

Solution 5

The .vbs file is running invisibly, which is a consequence of running it with the 'logged on or not' option.

You will not be allowed to interfere with a user using the computer, which means you will be able to help yourself, but not others.

Please read the following text from the Task Scheduler Help menu:

Task Security Context

You can specify that a task should run even if the account under which the task is scheduled to run is not logged on when the task is triggered.

To do this, select the radio button labeled Run whether user is logged on or not.

If this radio button is selected, tasks will not run interactively.

To make a task run interactively, select the Run only when user is logged on radio button.

Share:
65,033

Related videos on Youtube

lovechillcool
Author by

lovechillcool

Updated on July 09, 2022

Comments

  • lovechillcool
    lovechillcool almost 2 years

    I am trying to automate a VBScript by using Windows Task Scheduler. However, I tried to use cscript.exe + "C:\...\script.vbs" but it didn't run. I also tried to directly run the same command in CMD (cscript.exe "C:\...\script.vbs") and it worked.

    What might be the problem?

    EDIT :

    I just tried to switch the setting to "Run only when user is logged on" from "Run whether user is logged on or not" and it worked. I am wondering if there is a way to make my task scheduled run even when the user is logged off.

    • flo5783
      flo5783 almost 5 years
      After multiple hours searching and trying dozens of variations for this issue, this is finally what did it for me: it has to run when user is logged on... that's a pity, but there it is... I guess this is because my VBScript file is calling Excel (it refreshes data connections and calculates formulas before saving the Excel file).
  • lovechillcool
    lovechillcool over 7 years
    Did you try if it works when you logged off? btw, I am using Win Server 2012.
  • ZygD
    ZygD over 7 years
    @lovechillcool - Yes, for me it works as it should. When "Run whether user is logged on or not" is selected, Task Scheduler successfully calls my VBS script via either, cscript.exe or wscript.exe, even if I am not logged in.
  • Andrew Spencer
    Andrew Spencer over 3 years
    I suspect the issue happens when using Office applications, so the above script would be fine.
  • Brian
    Brian over 2 years
    Use >> instead of >. Using > would overwrite previous contents.
  • Jingwei Yu
    Jingwei Yu over 2 years
    This solved my problem. I could run the .vbs by double clicking it, but not when scheduling it in Task Scheduler. After creating the \Desktop folder, it worked. It almost gave me a heart attack