Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > VB Script

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

Reply
 
Old 07-13-2009   #1 (permalink)
Pegasus [MVP]


 
 

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
Quote:

>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
Old 07-13-2009   #2 (permalink)
Rich


 
 

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:
Quote:

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

> >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
Old 07-13-2009   #3 (permalink)
Rich


 
 

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:
Quote:

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

> >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
Old 07-13-2009   #4 (permalink)
Rich


 
 

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:
Quote:

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

> >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
Old 07-13-2009   #5 (permalink)
Pegasus [MVP]


 
 

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
Quote:

> 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:
>
Quote:

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

>> >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
Old 07-13-2009   #6 (permalink)
Pegasus [MVP]


 
 

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
Quote:

>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:
>
Quote:

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

>> >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
Old 07-14-2009   #7 (permalink)
DaveMills


 
 

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:
Quote:

>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.
Quote:

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

>>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:
>>
Quote:

>>>
>>> "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
Old 07-14-2009   #8 (permalink)
Al Dunbar


 
 

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
Quote:

> 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
Quote:

>>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:
>>
Quote:

>>>
>>> "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
Old 07-15-2009   #9 (permalink)
Rich


 
 

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:
Quote:

> 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
Quote:

> > 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
Quote:

> >>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
Old 07-15-2009   #10 (permalink)
Mark D. MacLachlan


 
 

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
Reply

Thread Tools


Similar Threads
Thread Forum
Schedule PowerShell script with Windows Server 2003 PowerShell
VBscript in 2008 Server Task Scheduler will not run VB Script
schedule task not deleted in windows 2003 .NET General
Start scheduled task on remote Server with prompt VB Script
Server 2003 scheduled PowerShell job won't run PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46