Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Task scheduler won't execute vbs

3,596 views
Skip to first unread message

wpher56

unread,
Mar 18, 2009, 7:45:10 AM3/18/09
to
Hello
(Windows server 2008 x64) : I have a very basic vbs that I would run every
hour: it checks the size of a file and stores (appends) the result in a
logfile. I double-click this vbs and all is fine. Now I create a task in the
task Scheduler to run it every hour and it won't run. Both the vbs and the
log are located in the c:\ directory. The history shows
- task triggered
- Action started (operational code = 1)
- task engine received message to start task (operational code = 1)
- task started (operational code = 1)
- Created task process

and that's all. Last Run Result: 0x41301.
Then I removed the lines concerning the output and I get the same result.
Looks like the Task Scheduler won't execute vbs files !

Or did I miss something ?
pher

Pegasus [MVP]

unread,
Mar 18, 2009, 8:38:03 AM3/18/09
to

"wpher56" <wph...@gmail.com> wrote in message
news:%23KeWw77...@TK2MSFTNGP03.phx.gbl...

Yes, the Task Scheduler WILL execute .vbs files but you need to give
yourself some eyes to see what the problem is. Instead of invoking the .vbs
file directly, invoke it through a batch file like so:
@echo off
echo %date% %time% %username% >> c:\test.txt
cscript //nologo c:\pher.vbs 1>>c:\test.txt 2>>&1
echo %date% %time% >> c:\test.txt

Now run this file via the Task Scheduler, then examine the file c:\test.txt.
I expect that all will become very clear. Note that you could replace
cscript.exe with wscript.exe, depending on which interpreter you wish to
use.


Masterplan

unread,
Mar 18, 2009, 8:37:40 AM3/18/09
to
Hi,

Just put in task scheduler the following command: cscript yourscript.vbs

--
Have a nice day!
MCSE, MCITP-EA
winmasterplan.blogspot.com


"wpher56" <wph...@gmail.com> wrote in message
news:%23KeWw77...@TK2MSFTNGP03.phx.gbl...

wpher56

unread,
Mar 18, 2009, 9:11:10 AM3/18/09
to
Thank you very much for this trick.
Well, the problem is that I get a "Permission denied" on the line
set lf=FSO.OpenTextFile("c:\outfile.log",8)
when I run the command file (not through the Task Scheduler), but NOT when I
run the vbs directly.
The user is "administrator", the outfile.log is set to "everyone full
access".
pher

"Pegasus [MVP]" <ne...@microsoft.com> wrote in message
news:edSKiZ8p...@TK2MSFTNGP02.phx.gbl...

wpher56

unread,
Mar 18, 2009, 11:12:11 AM3/18/09
to
Finally I could run the command file after having moved the cmd, vbs and log
file to the Administrator documents directory !
But from the Task Scheduler I get "Task Start Failed, Launch Failure"
Additional Data: Error Value: 2147750687, which corresponds to 0x8004131F.
This means SCHED_E_ALREADY_RUNNING. So I set the settings to "Stop the
existing instance". And finally the Task Scheduler shows "Action completed".
But the job is NOT done: the output of the command file is written to the
log file, but NOT the output of the vbs.
pher


"wpher56" <wph...@gmail.com> wrote in message

news:eR%23tzr8p...@TK2MSFTNGP04.phx.gbl...

Pegasus [MVP]

unread,
Mar 18, 2009, 11:23:11 AM3/18/09
to
Let's have a look at the contents of the log file c:\test.txt!


"wpher56" <wph...@gmail.com> wrote in message

news:%23qXq6v9...@TK2MSFTNGP04.phx.gbl...

wpher56

unread,
Mar 19, 2009, 4:02:52 AM3/19/09
to
Through the task scheduler:

19/03/2009 7:30:00.19 administrator
19/03/2009 7:30:00.21 administrator

Command file directly executed:

19/03/2009 7:32:00.24 administrator
File size: 22998765
19/03/2009 7:32:00.28 administrator

The line "File size" is output from the vbs.

pher


"Pegasus [MVP]" <ne...@microsoft.com> wrote in message

news:O89Gz19p...@TK2MSFTNGP06.phx.gbl...

Pegasus [MVP]

unread,
Mar 19, 2009, 5:10:08 AM3/19/09
to

"wpher56" <wph...@gmail.com> wrote in message
news:%23eKybkG...@TK2MSFTNGP03.phx.gbl...

> Through the task scheduler:
>
> 19/03/2009 7:30:00.19 administrator
> 19/03/2009 7:30:00.21 administrator
>
> Command file directly executed:
>
> 19/03/2009 7:32:00.24 administrator
> File size: 22998765
> 19/03/2009 7:32:00.28 administrator
>
> The line "File size" is output from the vbs.
>
> pher

The log file shows that your .vbs file did execute, even though the Subject
of your thread suggests that it didn't. We can therefore consider this issue
to be resolved.

You now say that the .vbs program does not generate the output you expect.
This is an issue within your .vbs code. To resolve it you must post the
code. Maybe you have a permissions problem that you're hiding by having a
global "on error resume next" statement in your code. You must not use such
statements while testing your code unless you wish to make things difficult
for yourself!

Alternatively you could use the Task Scheduler to invoke a very simple .vbs
program, e.g. one that uses the File System Object to write a line of text
to a file of your choice. This test would be a clear demonstration that .vbs
code will execute properly, even when invoked by the Task Scheduler.


wpher56

unread,
Mar 19, 2009, 7:38:16 AM3/19/09
to
:-) You are right, the vbs is executed !
But it does not produce any result.
This is the code of the testwrite.vbs:


set FSO = CreateObject("Scripting.FileSystemObject")
Set lf =
FSO.OpenTextFile("C:\Users\administrator.UNIFR\Documents\testwrite.txt", 8,
True)
msg = date & " " & time
lf.WriteLine(msg)
lf.Close
Set lf=Nothing
Set FSO=Nothing

The file testwrite.txt exist, the vbs runs fine when double-clicked.

pher

"Pegasus [MVP]" <ne...@microsoft.com> wrote in message

news:OMMMAKHq...@TK2MSFTNGP05.phx.gbl...

Pegasus [MVP]

unread,
Mar 19, 2009, 8:34:14 AM3/19/09
to

"wpher56" <wph...@gmail.com> wrote in message
news:umbHzcIq...@TK2MSFTNGP06.phx.gbl...

> :-) You are right, the vbs is executed !
> But it does not produce any result.
> This is the code of the testwrite.vbs:

When debugging programs then you should keep them as simple as possible.
Instead of writing data to a folder that may be subject to access
restrictions, select a folder that is accessible to everyone, e.g. like so:

Set FSO = CreateObject("Scripting.FileSystemObject")
Set lf = FSO.OpenTextFile("C:\testwrite.txt", 8, True)
msg = Date & " " & Time
lf.WriteLine(msg)
lf.Close

When this works (as it will!) then you can build your code up until you find
the cause of the problem. Remember to pay attention to the account you use
for your scheduled task!


wpher56

unread,
Mar 19, 2009, 9:37:11 AM3/19/09
to
The only place where the program runs is in the Administrator documents
directory. Setting it in C:\ causes the Task Scheduler to hang at the step
"Created task Process". That explains the title of my question "Task
Scheduler won't execute vbs".
I tried to put the vbs and the output file in the system32 directory which
is the home of the task scheduler, with no more success.
I also displayed the Err.Number value after the FSO.OpenTextFile statement,
but the value is 0, No error.
pher


"Pegasus [MVP]" <ne...@microsoft.com> wrote in message

news:%23%23JhF8Iq...@TK2MSFTNGP04.phx.gbl...

Pegasus [MVP]

unread,
Mar 19, 2009, 11:02:04 AM3/19/09
to

"wpher56" <wph...@gmail.com> wrote in message
news:%23ntsRfJ...@TK2MSFTNGP03.phx.gbl...

> The only place where the program runs is in the Administrator documents
> directory. Setting it in C:\ causes the Task Scheduler to hang at the step
> "Created task Process". That explains the title of my question "Task
> Scheduler won't execute vbs".
> I tried to put the vbs and the output file in the system32 directory which
> is the home of the task scheduler, with no more success.
> I also displayed the Err.Number value after the FSO.OpenTextFile
> statement, but the value is 0, No error.
> pher

Let's go about this a little more systematically:
1. Create a folder c:\Test.
2. Set the permissions of c:\Test to "Full read-write access for everyone".
3. Copy your .vbs file into c:\Test.
4. Use runas.exe to start a Command Prompt under the **same account** as the
one used for the scheduled task.
5. Put your test VB Script code into c:\test\test.vbs.
6. Create a batch file c:\test\wpher.bat as I suggested in my first reply.
7. Execute c:\test\wpher56.bat from the "runas" Command Prompt. Does it run
as expected?
8. Execute c:\test\wpher56.bat as a scheduled task. Does it run as expected?


wpher56

unread,
Mar 20, 2009, 3:02:56 AM3/20/09
to
The problem occurs at step 7, so I did not even tried step 8:

VBScript runtime error: Permission denied
Line: set lf=FSO.OpenTextFile("c:\test\testwrite.txt", 8, True)

The DOS box shows the correct user, the one I use in the Task Scheduler
(System Administrator). The files and directory c:\test have full access to
everyone as well as administrators.

pher

"Pegasus [MVP]" <ne...@microsoft.com> wrote in message

news:eYE6pOKq...@TK2MSFTNGP02.phx.gbl...

Pegasus [MVP]

unread,
Mar 20, 2009, 6:08:20 AM3/20/09
to
In my previous reply I went to the trouble of spelling out in great detail
what steps you should take in order to home in on the cause of your problem.
Your reply is unfortunatly so brief that it tells me next to nothing. I
don't know what script you're running (appart from a single line of code)
and I do not know under what conditions you ran the script, e.g.
- running the batch file directly (what does the batch file look like?)
- running the batch file via the Task Scheduler
- running the script file directly
- running the script file via the Task Scheduler.
I recommend you ask a person with a strong background in Windows, VB Scripts
and batch files to assist you on site so that he/she can see things directly
instead of having to rely on incomplete reports. If this is not feasible and
if you're desperate to resolve this issue then you can make your machine
visible to me so that I can see with my own eyes what's going on. It's not a
solution I recommend but if you want to know more about it then you can send
a note to pegasus_fnlATyahooDOTcom to find out more.


"wpher56" <wph...@gmail.com> wrote in message

news:uI2q3nSq...@TK2MSFTNGP06.phx.gbl...

wpher56

unread,
Mar 20, 2009, 9:41:50 AM3/20/09
to
I followed the steps 1 thru 7 of your previous mail, so I did not repeat
everything.
Steps 1 to 6: ok, step 7: VBScript Runtime Error, Permission denied.

The script is what you wrote 2 days ago, except for the path (c:\test
instead of c:\).
The vbs is what I posted yesterday, very basic:

set FSO = CreateObject("Scripting.FileSystemObject")
Set lf =
FSO.OpenTextFile("C:\Users\administrator.UNIFR\Documents\testwrite.txt", 8,
True)


msg = date & " " & time
lf.WriteLine(msg)
lf.Close

I wrote tons of programs in cmd, vb, vbs, fortran, php etc in the past 30
years, so I believe I have a strong backgroud in that matter.
I'm System Administrator (Windows Server 2003/2008 and Linux) and DBA (SQL
Server + Oracle) in charge of about 50 servers in a university with 16'000
accounts, I suppose I have also enough background in that matter too.

We regularly do remote assistance with Microsoft, but I thought that such a
basic thing as running a vbs from the Task Scheduler was not worth a ticket
to Microsoft.

pher


"Pegasus [MVP]" <ne...@microsoft.com> wrote in message

news:OcIVLPUq...@TK2MSFTNGP02.phx.gbl...

Pegasus [MVP]

unread,
Mar 23, 2009, 7:14:16 AM3/23/09
to
>
> We regularly do remote assistance with Microsoft, but I thought that such
> a basic thing as running a vbs from the Task Scheduler was not worth a
> ticket to Microsoft.
>
> pher

I agree that this is a trivial issue. Unfortunately, despite of my best
efforts, I haven't been able to establish a dialog that would have led us to
a satisfactory solution. While you may have extensive experience in
programming, your conclusions with this particular problem were repeatedly
incorrect, starting with the very Subject of your post (Task Scheduler won't
execute vbs). It actually did, as we established with a simple test. If you
do not wish to make your machine visible to me (and I probably wouldn't
either) then I suggest you raise another ticket with Microsoft. Remember to
post the conclusion here for the benefit of everyone else!


0 new messages