Page 1 of 2 12 LastLast
Results 1 to 15 of 20

Thread: Task scheduler won't execute vbs

  1. #1
    wpher56 Guest

    Task scheduler won't execute vbs

    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


  2. #2
    Masterplan Guest
    Hi,

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


    Let's have a look at the contents of the log file c:\test.txt!

    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.

  3. #3
    Pegasus [MVP] Guest

    Re: Task scheduler won't execute vbs

    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.

  4. #4
    wpher56 Guest

    Re: Task scheduler won't execute vbs

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

  5. #5
    wpher56 Guest

    Re: Task scheduler won't execute vbs

    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

  6. #6
    Pegasus [MVP] Guest

    Re: Task scheduler won't execute vbs

    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.

  7. #7
    wpher56 Guest

    Re: Task scheduler won't execute vbs

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

  8. #8
    Pegasus [MVP] Guest

    Re: Task scheduler won't execute 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!

  9. #9
    wpher56 Guest

    Re: Task scheduler won't execute vbs

    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

  10. #10
    Pegasus [MVP] Guest

    Re: Task scheduler won't execute vbs

    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?

  11. #11
    wpher56 Guest

    Re: Task scheduler won't execute vbs

    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.

  12. #12
    Pegasus [MVP] Guest

    Re: Task scheduler won't execute vbs

    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.

  13. #13
    wpher56 Guest

    Re: Task scheduler won't execute vbs

    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.

  14. #14
    Pegasus [MVP] Guest

    Re: Task scheduler won't execute vbs

    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!

  15. #15
    Join Date
    Dec 2009
    Posts
    2

    Re: Task scheduler won't execute vbs

    I have a vbs script that opens an excel spreadsheet and fills in information from several servers on my network. This script is currently running on an XP box and has worked for 2 years. The script runs 2 times a day and no one is logged on.

    I am trying to get this to work on my server 2008 box. I can run it interactively or from task scheduler as long as I am logged on. It will not work if I am logged off.

    I do have the box checked to run logged on or not.

Page 1 of 2 12 LastLast

Similar Threads

  1. Replies: 5
    Last Post: 29-09-2011, 01:03 PM
  2. Task Scheduler
    By StevenSchmid in forum Windows Software
    Replies: 3
    Last Post: 11-05-2010, 12:43 AM
  3. Task scheduler - anyone??
    By Jay in forum Vista Help
    Replies: 6
    Last Post: 04-11-2009, 05:49 AM
  4. Can't get MS Task Scheduler to run
    By 5201man in forum Windows Software
    Replies: 1
    Last Post: 07-05-2008, 02:17 PM
  5. Delete task from Task Scheduler
    By Jimbo in forum Vista Help
    Replies: 2
    Last Post: 05-03-2008, 09:41 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,714,150,468.61337 seconds with 16 queries