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
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.
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...
"Pegasus [MVP]" <ne...@microsoft.com> wrote in message
news:edSKiZ8p...@TK2MSFTNGP02.phx.gbl...
"wpher56" <wph...@gmail.com> wrote in message
news:eR%23tzr8p...@TK2MSFTNGP04.phx.gbl...
"wpher56" <wph...@gmail.com> wrote in message
news:%23qXq6v9...@TK2MSFTNGP04.phx.gbl...
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...
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.
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...
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!
"Pegasus [MVP]" <ne...@microsoft.com> wrote in message
news:%23%23JhF8Iq...@TK2MSFTNGP04.phx.gbl...
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?
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...
"wpher56" <wph...@gmail.com> wrote in message
news:uI2q3nSq...@TK2MSFTNGP06.phx.gbl...
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...
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!