• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

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

P

Pegasus [MVP]

#1
"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 Computer

R
#2
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 Computer

R
#3
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 Computer

R
#4
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 Computer

P

Pegasus [MVP]

#5
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 Computer

P

Pegasus [MVP]

#6
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 Computer

D

DaveMills

#7
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 Computer

A

Al Dunbar

#8
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 Computer

R
#9
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 Computer

M

Mark D. MacLachlan

#10
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 Computer

A

Alex K. Angelopoulos

#11
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
script.

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
statement

WScript.Timeout = nn

"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).
 

My Computer

H

Harvey Colwell

#12
I meant for testing and not for production.


You are right that the command prompt will only show up if the logged on
user is the same as the one the script is scheduled to run as. As I said,
this method is only used while debugging.

But there is an other method that works regardless of whether the script is
ran interactively or by scheduled task.

Simply write your breakpoint messages to a log file. I typically create a
variable called "bDebug". I have the sub that writes to the log file
conditional on bDebug being set to "true". That way after I have the script
running properly, all I have to do is set bDebug to "false".

Here is the relevant code. Just make sure that the log file is in a location
that the user has write access to, such as their temp folder.



bDebug=True


sLog = oWS.ExpandEnvironmentStrings("%temp%\") & "my_script.log"


Sub Log(sLog, sMsg)
If bDebug Then
Dim oFile
Set oFile = oFS.OpenTextFile(sLog,8,True)
oFile.WriteLine sMsg
oFile.Close
Set oFile = Nothing
End If
End Sub







"Al Dunbar" <alandrub@xxxxxx> wrote in message
news:uVCO0IaCKHA.1248@xxxxxx

>
> "Harvey Colwell" <HarveyColwell@xxxxxx> wrote in message
> news:eO9K4sTCKHA.4376@xxxxxx

>> I haven't followed the complete thread, so I hope that I'm not repeating
>> anything.
>>
>> 1.) Make sure that the script runs as expected. Manually run it from a
>> command prompt.
>>
>> 2.) Make the scheduled task run the script inside a command prompt that
>> remains on screen. This allows you to see any error messages.
>>
>> %comspec% /k cscript.exe //nologo my_script.vbs
>>
>> 3.) Put temporary popup messages throughout the script so you can see how
>> far you are progressing through the script. Or you could write these
>> messages to a log file.
>>
>> msgbox "Brake point 1: Script setup complete"
>>
>> msgbox "Brake point 2: Gathered user input"
>>
>> msgbox "Brake point 3: Completed tasks"
>
> MSGBOThat works for script that are run interactively, but no so well when
> it is run as a scheduled task for reasons explained elsethread.
>
> /Al
>
>
 

My Computer

Users Who Are Viewing This Thread (Users: 1, Guests: 0)