How to schedule a vbscript as a Scheduled Task in Server 2003

Discussion in 'Windows Server' started by Rich, Jul 13, 2009.

  1. Rich

    Rich Guest

    I have a vbscript that when I launch it manually it runs and closes in about
    5 minutes. I created a new Scheduled Task on my server, having it just run
    the .vbs file (the vbs path\filename is the only thing in the Run box), but
    it it still running after 10 minutes and I can't tell why so I cancelled it.
    Is there a better way to setup the scheduled task so it will stop "running"
    (whether it finished and didn't close or whether it was still running after
    10 minutes which it shouldn't have been).
    Rich, Jul 13, 2009
    1. Advertisements

  2. Hello Rich,

    Did you check the logfile within scheduled tasks, Advanced, view log for
    errors/problems listed?

    Best regards

    Meinolf Weber
    Meinolf Weber [MVP-DS], Jul 13, 2009
    1. Advertisements

  3. If you want your scripts to be robust then you must invoke them explicitly
    instead of relying on some associations that may or may not work. Instead of
    you should run
    cscript.exe //nologo c:\Scripts\MyScript.vbs

    This will probably solve your problem. If it doesn't, log on under the same
    account as the one used for the scheduled task, then launch that task in the
    Task Scheduler and watch what happens.
    Pegasus [MVP], Jul 13, 2009
  4. Rich

    Rich Guest

    all it says in there is that i cancelled it.

    Maybe I didn't set it up properly. Do i need to do a

    cmd /c cscript.exe path\script.vbs

    or can i just do a

    Rich, Jul 13, 2009
  5. Rich

    Rich Guest

    Thanks, i'll do the cscript.exe //nologo way.

    Rich, Jul 13, 2009
  6. Rich

    Rich Guest

    Still have a problem. I logged in as the local admin who runs the task, tell
    the scheduled task to run, then what i'm guessing is the cscript box pops up
    for a split second, closes, then i get an result code of 0x1 for the task.
    Rich, Jul 13, 2009
  7. Rich

    Rich Guest

    I think I figured it out. I looked in Documents and Settings, and the folder
    name for the administrator was "administrator.000" instead of just
    administrator. after cleaning that up, I logged back in with my domain admin
    account, then can run the task.
    Rich, Jul 13, 2009
  8. Now take it one easy step further:
    1. Log in as the local admin.
    2. Start a Command Prompt (which is NOT the same as the "Run" box!)
    3. Type the previous command:
    cscript.exe //nologo c:\Scripts\MyScript.vbs
    The overall consideration is always the same: To make things visible!
    Pegasus [MVP], Jul 13, 2009
  9. This probably means that you did not fully qualify your file names. Again,
    if you want your scripts to be robust then you *must* fully qualify all file
    Pegasus [MVP], Jul 13, 2009
  10. Hi,

    Thank you for posting here. I would like to confirm if the issue persists
    or not. If it still occurs, please try the steps below for troubleshooting.

    Based on the article below, "0x1" means "An incorrect function was called
    or an unknown function was called". Please check your script to make sure
    all file and folder called by their full path.

    How to troubleshoot scheduled tasks in Windows XP and in Windows Server 2003

    Please also follow other suggestions in above article to collect
    information. Let us know "Status" and paste Scheduled Tasks Log here for

    Mervyn Zhang
    Microsoft Online Community Support

    This posting is provided "AS IS" with no warranties, and confers no rights.
    Mervyn Zhang [MSFT], Jul 14, 2009
  11. Rich

    DaveMills Guest

    And be aware that mapped drives in the users profile will not be available to
    the script unless that script maps them itself.
    DaveMills, Jul 14, 2009
  12. Rich

    Al Dunbar Guest

    More likely, he simply assumed that the profile folder name would be the
    same as the username in question. Another trick to making scripts robust is
    to avoid assumptions that are not universally correct, and get the
    information required from the operating system. There are a couple of ways
    of determining the fully qualified path to certain "special folders" in
    vbscript - the equivalent in batch mode would be something like:

    (set _myprofile=%userprofile%)

    Al Dunbar, Jul 15, 2009
  13. Rich

    Rich Guest

    After running it a couple times, it now runs with a 0x0. weird since I
    didn't change anything in the script.
    Rich, Jul 15, 2009
  14. Rich

    Rich Guest

    I think the problem was more due to someone previously manually deleting
    profile folders, and the registry pointing to a non-existing folder for the
    administrator %username% folder. at least that's my hunch.

    This script doesn't do anything with profile folders or %username% in the
    Rich, Jul 15, 2009
  15. And since this is a VBScritp forum, the equivalent VBScript code would

    Set WshShell = CreateObject("WScript.Shell")
    Set WshSysEnv = WshShell.Environment("PROCESS")
    UserProfile = WshSysEnv("USERPROFILE")
    WScript.Echo UserProfile
    Mark D. MacLachlan, Jul 15, 2009
  16. By the way, although stopping the script after a particular time wouldn't
    have solved your underlying problem here, you CAN specify a timeout for a

    One technique is to add the argument //T:nn to the script at launch, where
    nn is the number of seconds the script is allowed to run before terminating.
    Alternatively, within the script itself you can set the timeout with a

    WScript.Timeout = nn
    Alex K. Angelopoulos, Jul 15, 2009
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.