Windows Vista Forums

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

  1. #1


    Pegasus [MVP] Guest

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


    "Rich" <richjone@xxxxxx> wrote in message
    news:1D3543F0-45E9-497F-BF93-A4E68B603D21@xxxxxx

    >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).
    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
    running
    c:\Scripts\MyScript.vbs
    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.



      My System SpecsSystem Spec

  2.   


  3. #2


    Rich Guest

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

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

    "Pegasus [MVP]" wrote:

    >
    > "Rich" <richjone@xxxxxx> wrote in message
    > news:1D3543F0-45E9-497F-BF93-A4E68B603D21@xxxxxx

    > >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).
    >
    > 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
    > running
    > c:\Scripts\MyScript.vbs
    > 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.
    >
    >
    >

      My System SpecsSystem Spec

  4. #3


    Rich Guest

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

    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.

    "Pegasus [MVP]" wrote:

    >
    > "Rich" <richjone@xxxxxx> wrote in message
    > news:1D3543F0-45E9-497F-BF93-A4E68B603D21@xxxxxx

    > >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).
    >
    > 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
    > running
    > c:\Scripts\MyScript.vbs
    > 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.
    >
    >
    >

      My System SpecsSystem Spec

  5. #4


    Rich Guest

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

    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.

    "Pegasus [MVP]" wrote:

    >
    > "Rich" <richjone@xxxxxx> wrote in message
    > news:1D3543F0-45E9-497F-BF93-A4E68B603D21@xxxxxx

    > >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).
    >
    > 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
    > running
    > c:\Scripts\MyScript.vbs
    > 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.
    >
    >
    >

      My System SpecsSystem Spec

  6. #5


    Pegasus [MVP] Guest

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

    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!


    "Rich" <richjone@xxxxxx> wrote in message
    news:74AEC7B2-01E7-4BC5-BF25-891A5E9E8C77@xxxxxx

    > 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.
    >
    > "Pegasus [MVP]" wrote:
    >

    >>
    >> "Rich" <richjone@xxxxxx> wrote in message
    >> news:1D3543F0-45E9-497F-BF93-A4E68B603D21@xxxxxx

    >> >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).
    >>
    >> 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
    >> running
    >> c:\Scripts\MyScript.vbs
    >> 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.
    >>
    >>
    >>


      My System SpecsSystem Spec

  7. #6


    Pegasus [MVP] Guest

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

    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
    names.


    "Rich" <richjone@xxxxxx> wrote in message
    news:5D164308-4588-4D1A-9CD4-A206908CE839@xxxxxx

    >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.
    >
    > "Pegasus [MVP]" wrote:
    >

    >>
    >> "Rich" <richjone@xxxxxx> wrote in message
    >> news:1D3543F0-45E9-497F-BF93-A4E68B603D21@xxxxxx

    >> >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).
    >>
    >> 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
    >> running
    >> c:\Scripts\MyScript.vbs
    >> 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.
    >>
    >>
    >>


      My System SpecsSystem Spec

  8. #7


    DaveMills Guest

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

    On Mon, 13 Jul 2009 23:33:13 +0200, "Pegasus [MVP]" <news@xxxxxx> wrote:

    >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
    >names.
    And be aware that mapped drives in the users profile will not be available to
    the script unless that script maps them itself.

    >
    >
    >"Rich" <richjone@xxxxxx> wrote in message
    >news:5D164308-4588-4D1A-9CD4-A206908CE839@xxxxxx

    >>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.
    >>
    >> "Pegasus [MVP]" wrote:
    >>

    >>>
    >>> "Rich" <richjone@xxxxxx> wrote in message
    >>> news:1D3543F0-45E9-497F-BF93-A4E68B603D21@xxxxxx
    >>> >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).
    >>>
    >>> 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
    >>> running
    >>> c:\Scripts\MyScript.vbs
    >>> 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.
    >>>
    >>>
    >>>
    >
    --
    Dave Mills
    There are 10 types of people, those that understand binary and those that don't.

      My System SpecsSystem Spec

  9. #8


    Al Dunbar Guest

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

    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

    "Pegasus [MVP]" <news@xxxxxx> wrote in message
    news:ui2LIGABKHA.1208@xxxxxx

    > 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 names.
    >
    >
    > "Rich" <richjone@xxxxxx> wrote in message
    > news:5D164308-4588-4D1A-9CD4-A206908CE839@xxxxxx

    >>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.
    >>
    >> "Pegasus [MVP]" wrote:
    >>

    >>>
    >>> "Rich" <richjone@xxxxxx> wrote in message
    >>> news:1D3543F0-45E9-497F-BF93-A4E68B603D21@xxxxxx
    >>> >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).
    >>>
    >>> 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
    >>> running
    >>> c:\Scripts\MyScript.vbs
    >>> 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.
    >>>
    >>>
    >>>
    >
    >



      My System SpecsSystem Spec

  10. #9


    Rich Guest

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

    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
    code.

    "Al Dunbar" wrote:

    > 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
    >
    > "Pegasus [MVP]" <news@xxxxxx> wrote in message
    > news:ui2LIGABKHA.1208@xxxxxx

    > > 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 names.
    > >
    > >
    > > "Rich" <richjone@xxxxxx> wrote in message
    > > news:5D164308-4588-4D1A-9CD4-A206908CE839@xxxxxx

    > >>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.
    > >>
    > >> "Pegasus [MVP]" wrote:
    > >>
    > >>>
    > >>> "Rich" <richjone@xxxxxx> wrote in message
    > >>> news:1D3543F0-45E9-497F-BF93-A4E68B603D21@xxxxxx
    > >>> >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).
    > >>>
    > >>> 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
    > >>> running
    > >>> c:\Scripts\MyScript.vbs
    > >>> 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.
    > >>>
    > >>>
    > >>>
    > >
    > >
    >
    >
    >
    >

      My System SpecsSystem Spec

  11. #10


    Mark D. MacLachlan Guest

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

    And since this is a VBScritp forum, the equivalent VBScript code would
    be:

    Code:
    Set WshShell = CreateObject("WScript.Shell")
    Set WshSysEnv = WshShell.Environment("PROCESS")
    UserProfile = WshSysEnv("USERPROFILE")
    WScript.Echo UserProfile

      My System SpecsSystem Spec

Page 1 of 2 12 LastLast

Re: How to schedule a vbscript as a Scheduled Task in Server 2003
Similar Threads
Thread Forum
are VBscript on Windows server 2003 and VBscript on WS2008 compatible? VB Script
I can not see add task in scheduled task in win server 2003 .NET General
2008 R2 server, scheduled task issue Server General
schedule task not deleted in windows 2003 .NET General
Start scheduled task on remote Server with prompt VB Script