Link to home
Start Free TrialLog in
Avatar of jbeallva
jbeallva

asked on

Scheduled Task doesn't run when not logged in

Hello All,

We have some scheduled tasks that point at vb scripts (.vbs files), and a few months ago they stopped running when the user they run as was not logged in.  They worked fine before that, and we made no changes to the scheduled task.

We've tested vbscript files that send emails, and that open IE (see below).  Both exhibit the same behavior, they run when you're logged on to the machine, but won't run if you're not logged on.

The scripts are doing things like this:

On Error Resume Next
Set objIE = CreateObject("InternetExplorer.Application")

objIE.Visible = false
objIE.Navigate("http://internalserver/some/script.asp")
Do While objIE.Busy
    WScript.Sleep 2000
Loop
   
objIE.Quit

Set objIE = nothing


So, what do I need to do in order to get my tasks running again?
Avatar of jwarnken
jwarnken
Flag of United States of America image

1st check the simple things.
- ensure the task is enabled
- ensure "Run only if logged on" is not checked

If everything looks right but you still have an issue try recreating the tasks
Avatar of jbeallva
jbeallva

ASKER

Yes, all those things check out, and I actually just created a new task just for the purpose of testing the behavior.  Still getting the same thing, it runs when I'm logged on, not when I'm logged off.
Can you post the results of
schtasks /query /fo LIST /v
For the tasks in question?
Please sanatize the system and user info that you would not want public.
Avatar of Don
I would try scheduling them using the service account so that when a user changes password scheduled tasks arent affected. Do this using the "AT" command:
http://support.microsoft.com/kb/313565
jwarnken:

HostName:                             {removed}
TaskName:                             Debugging Scheduled Task Issues
Next Run Time:                        5:24:00 PM, 12/2/2008
Status:                              
Logon Mode:                           Interactive/Background
Last Run Time:                        5:23:00 PM, 12/2/2008
Last Result:                          0
Creator:                              {removed}
Schedule:                             Every 1 minute(s) from 3:05 PM for 6 hour(s) every day, starting 12/2/2008
Task To Run:                          E:\WebMarket\www\WSH\TestScript.vbs
Start In:                             E:\WebMarket\www\WSH\
Comment:                              N/A
Scheduled Task State:                 Enabled
Scheduled Type:                       Minute
Start Time:                           3:05:00 PM
Start Date:                           12/2/2008
End Date:                             N/A
Days:                                 Everyday
Months:                               N/A
Run As User:                          {removed}
Delete Task If Not Rescheduled:       Disabled
Stop Task If Runs X Hours and X Mins: 72:0
Repeat: Every:                        1 Minute(s)
Repeat: Until: Time:                  None
Repeat: Until: Duration:              6 Hour(s): 0 Minute(s)
Repeat: Stop If Still Running:        Disabled
Idle Time:                            Disabled
Power Management:                     No Start On Batteries, Stop On Battery Mode


Keep in mind this is just a test script I'm using to try and figure out what's preventing vbscript from executing as a scheduled task.  That's why it's set to run every minute.

dstewartjr:

Thanks for the advice, this is a good maintenance idea but doesn't help with the immediate issue, as no passwords have changed since we started having this issue.
not only good maintenance, but also dont have to worry about permissions
Is there an error code when the script fails
It's not clear to me from the links you provided how to set the task to run as the Network Service account--can you provide more specific instructions?  I tried setting the username to Network Service, NetworkService, NT AUTHORITY\NetworkService, and NT AUTHORITY\Network Service and none of those worked.  NT Authority\System, however, did work.

Also, I'm not sure this is a permissions issue.  Remember that tasks run fine when a user is logged on.  If the user they're running as did not have sufficient permissions, why would it ever run successfully?

  -Josh
They have a "last status" of 0x1 after they have failed to run.
if you go to control panel/scheduled tasks/advanced/AT service account you can change it there
jwarnken:

I get the same behavior even if I am not using IE from vbscript

dstewartjr:

I'm not in the office anymore but will check on that tomorrow.
dstewartjr:

You said:

"If I go to if you go to control panel/scheduled tasks/advanced/AT service account you can change it there"

I see that I can change the AT service account, but I don't see a way to change the account that a particular scheduled task is running as.

By the way, right now this task is running as an account that has administrative privileges on the machine, so it seems pretty unlikely that it's a permissions issue with the account it's running as.
Also have you considered having these scripts run either as startup/shutdown or logon/logoff scripts?
This is a production server that may be logged on to several times in one day or not at all for several days, and it's only rebooted when necessary (maybe once every month or two), but the scripts that we're having trouble with are maintenance tasks that need to run daily.

So, no, we haven't considered that because it's wouldn't work to achieve what we need to do.
The task schedule service was already running as "Local System account".  I did not have "Allow service to interact with desktop" checked, but I checked that, logged off, and there was no change in behavior (scheduled .vbs tasks did not run, even though they were scheduled to run).

I then logged back on, and the scheduled .vbs tasks began running again at their specified intervals.

The problem seems to be that .vbs script files will not execute unless there we are actually logged on via remote desktop.  Other tasks will run when not logged on, but not vbscript files.

  -Josh
The error code of 1 or 0X01 reffers to: An incorrect function was called or an unknown function was called.
This is basicly a general failure of the task. Meaning it tried to run but failed. It can be caused by any number of things but seems to be related to the logon type of the user running the task.
Does the task run successfly if some other user is logged in?
Sounds like the problem is because it is running as "local System account" and that account may not have the priveledges on the other machines. Try creating a "scheduled task" user with admin rights and use this account for all tasks
dstewartjr:

You said: "Sounds like the problem is because it is running as "local System account" and that account may not have the priveledges on the other machines."

The task is not running as local system account.  The Task Scheduler service is running as the local system account.  The tasks themselves are running as machine administrators.  Also, the scripts fail regardless of whether or not they are doing anything over the network, so it's not an issue with connecting to other machines over the network.  I've got a test script write now that simply tries to write a "i ran successfully" message to a log file.  It works when I'm logged in as the same user the task is running as, but not otherwise.

jwarnken:

It only runs successfully if the you logon as the same user the task is scheduled to run as.  If I logon to the system as a different user, the task will not run.

For instance, let's say I have to administrator accounts, admin1 and admin2.  If I set the task to run as admin1, it will only run if I am logged on to the machine as admin1.  If I log off, it will not run.  If I logon as admin2, it will not run.  If, however, I logon as admin2 and then change the task to run as admin2, it starts running at the specified intervals, so long as I stay logged on to the machine as admin2.
You can use this vbs script to ensure that scripts will run without the user being logged in.
If this works the issue will be in what the script is trying to do when no user is logged in.
Const ForReading = 1, ForWriting = 2, ForAppending = 8, CreateIfNotExist = -1
LogFile = "c:\TestLog.log"
Set LogObjFSO = CreateObject("Scripting.FileSystemObject")
set LogObjFile = LogObjFSO.OpenTextFile (LogFile, ForAppending, True)
LogObjFile.WriteLine "Task ran at: " & Now 
LogObjFile.Close

Open in new window

have you tried to use runas to duplicate the failure?
runas /noprofile /user:mymachine\administrator cmd
then run the script to see if it works without the profile loaded
jwarnken: -- that's basically the script I've been using to test this issue.  I tried your script exactly and got the same behavior--runs when I'm logged in as the same user the task is scheduled to run as, not when I'm logged off.
dstewartjr: That KB article says that the issue was fixed in Windows 2003 SP1, which we installed some time ago (SP1 was released March 2005)
Try changing your task run to

C:\Windows\system32\cscript E:\WebMarket\www\WSH\TestScript.vbs
Oh. I assume E: is a local drive since NT Authority\System worked right?
We may be on to something with the runas bit.  Here's what I got:

E:\WebMarket\www\WSH>runas /noprofile /usr:domain\user TestScript.vbs
Enter the password for hslda\josh:
Attempting to start TestScript.vbs as user "domain\user" ...
RUNAS ERROR: Unable to run - TestScript.vbs
193: TestScript.vbs is not a valid Win32 application.

I replaced my actual username with domain\user, jfyi.

At any rate, if I enter a bad password, I get a different error about the username and password being incorrect.  If I input the correct password, I get the error above.

It looks like it's trying to directly execute the vbs file as if it were a binary executable. What it needs to do is fire up the vbscript interpreter, which will parse and execute the file.

Perhaps the scheduled task needs to call the vbscript interpreter and pass the script to execute as an argument, rather than trying to execute the vbscript file directly?  I'll see if I can figure that out.  But I don't know where the vbscript interpreter is?

  -Josh
That explains how the two script interpreters work and how to call them manually, which is step one.
progress is good
try it this way

runas /noprofile /usr:domain\user cscript TestScript.vbs

Did you also try

Changing your task run to

C:\Windows\system32\cscript E:\WebMarket\www\WSH\TestScript.vbs
Sorry you need quotes for the runas

runas /noprofile /usr:domain\user "cscript TestScript.vbs"
.vbs is not a command nor is it an application.
The runas works from the command line (with the quotes), and I tried changing the task to execute cscript directly and pass it the script file as a parameter, but no luck.  Same behavior.  Works when run as the same user who is logged in, but does not work otherwise (e.g., if the task is set to run as a different user, or there is no user logged in).

  -Josh
try creating a batch file that calls your vbs and then schedule your task to run the .bat
AmazingTech--you posted some of your comments at the same time as I was composing my own comments, but it sounds like we had the same idea (call the vbscript interpreter directly and pass the script as an argument).  And in regards to your other question: yes, the e: drive is a local drive, not a network drive.  For this test script I'm specifically trying to eliminate network resources from the equation so we have as few variables in the picture as possible.  All this script does it try write one line to a log file on a local drive.
Already tried creating a batch file testscript.bat that contains this line:

c:\windows\system32\cscript.exe e:\webmarket\www\wsh\testscript.vbs

It runs fine when called directly, but I get the same behavior with the scheduled task.  If I'm logged in as the user that the scheduled task is set to run as, it runs fine, but otherwise, no success.
The Task Scheduler service is it set to Log On As Local System?
have you look at your scheduled task log? C:\WINDOWS\SchedLgU.txt ?
dstewartjr: there's no C:\WINDOWS\SchedLgU.txt file on my machine, could that log file be somewhere else?

There's nothing informative in the windows event log.

AmazingTech: yes, the task scheduler service is set to log on as local system.
you get the same file if you click on "view log" under scheduled task/advanced

also see if this solution helps:
https://www.experts-exchange.com/questions/23566247/Scheduled-Task-Could-Not-Start.html
dstewartjr: looks like the log file is actually at C:\WINDOWS\Tasks\SchedLgU.txt

In there, I see records of all the successful runs.  But there is no log entry for the times that it is supposed to run but is not running.
did you look at your  "Log on as a batch job"  settings ?
The solution there

"In that case, the "No override"-option (Enforced if using GPMC) is enabled on the GPO-link."

I'm not really sure how to apply that solution to my situation.
Thought maybe some of the other trouble shooting prior to the solution may be of help ?
I read it through and didn't see anything that I thought applied, but I'm not an active directory guru so I might be missing something relevant...
try to locate in your script where it is failing
It's not failing in the script, the script is simply not running, as best I can tell.
Does this work on another workstation of yours?
read towards bottom
This runs fine on an XP Pro workstation, regardless of whether or not I'm logged in.
did you confirm that your user is in the "log on as batch" and "log on as service" ?
Just checked, the user was in the log on as batch, but not log on as service.  I added to users that can logon as service.

No change in behavior.
is the user a local admin or a domain admin?
Local admin, I don't have the credentials for the domain admin, and regardless we would not want the task running as a domain admin.
why not?
how about then adding the administrators "group" to log on as batch?
http://support.microsoft.com/kb/222628
Because it's just a simple little maintenance script that doesn't need full access to every resource on the domain, and we don't give something more rights than it needs.  What we want is the old behavior, where these scripts were running as local, non-privileged users.  We just escalated to a local admin for debugging purposes, and whether or not anybody was logged in didn't matter.

And then there's the policy/bureaucracy side of things: even if I wanted to run these scripts as scheduled tasks, our top IT guys would refuse to let it happen.
> dstewartjr:
> how about then adding the administrators "group" to log on as batch?
http://support.microsoft.com/kb/222628

Already tried that, no change.
is the script accessing network resources?
No, here's the entire script:

Const ForReading = 1, ForWriting = 2, ForAppending = 8, CreateIfNotExist = -1
LogFile = "c:\TestLog.log"
Set LogObjFSO = CreateObject("Scripting.FileSystemObject")
set LogObjFile = LogObjFSO.OpenTextFile (LogFile, ForAppending, True)
LogObjFile.WriteLine "Task ran at: " & Now
LogObjFile.Close
could you post the script -minus any pertainent info?
Yes, that's how the file system object works, was there anything in there that you thought suggested a change in what this script is doing?
try this bat instead once?

@echo off
echo Task ran at:,,%date%,, %time%>>c:\testlog.csv
ENDLOCAL
first line "The FileSystemObject is a component often used to access the server's file system" makes me think permissions
I have defrag scripts that are task scheduled but are set up with a domain admin rights
"First line "The FileSystemObject is a component often used to access the server's file system" makes me think permissions"

Yes, but it's running as an administrator right now with full access to everything on the system, and it's not accessing any network resources.
yes local admin, try the .bat?
The batch file runs correctly all the time (both when logged on and logged off), which lends more support to what we suspected, which is that the issue has something to do with vbscript.  There is no vbscript that I have been able to get to successfully execute while logged off on this machine.  It seems like the system is refusing to execute VB code unless there is a user interactively logged on.
Im 99.999% positive that it has something to do with user rights and permissions, but the .bat should do what you need.
What user right/permission could an administrator be missing that would prevent it from writing to a text file (which has full permissions granted to the administrators group)?
If it was a problem with the DLL, wouldn't it fail all the time, not just when I'm not logged in?
did you check this part ?
"you need to adjust the permissions on the SCRRUN.DLL.
Here's how you do it:
Navigate to your WINNT\SYSTEM32 directory and find the SCRRUN.DLL. Right-click the file and select properties. Then click the security tab and ensure that the IUSR_<machinename> and IWAM_<machinename> accounts have "read" and "read & execute" permissions. That's it."
did you delete the testlog.log to start fresh and/or check the permissions/owner of it?
Yes, I've tried deleting the file, and I've checked the permissions on it.

As far as setting the permissions on the SCRRUN.DLL file, there's no reason for the IUSR or IWAM accounts to have access to that file because I'm not trying to execute this script via IIS (that's what those accounts are for), I'm trying to execute it directly as a local administrator.
try it you never know
that's how we all learn trial and error
otherwise just use the batch method
The batch method just writes a few lines to a file, it doesn't do everything we need our scripts to do.

While debugging this problem I've stripped things down to a very basic test vbscript, but it doesn't actually do anything useful.  It just tells me that it ran.
this isnt worth the lousy 125 points anymore good luck.
Ok, I've been around and around with this and haven't made any real progress.  I have determined that it's working on other machines, though, so it's something peculiar about this machine.  I tried two other Win2003 servers and an XP Pro box.  All exhibit the behavior you'd *expect*, which is that the script runs as the user you set it to run as, and it doesn't matter if you're logged in or not.  It just runs.

I went a little further and created a basic console application in C# that attempts to call the script interpreter, to see if that would give me any more insights.  The code attached.

I then set my scheduled task to execute this .NET app.  Now, the .NET app runs as you'd expect it to (whether you're logged in or not), but the cscript.exe process that it's trying to start will only run if I'm logged in as the same user that the scheduled task is trying to run as.  If I'm not logged in, here's what I get in the debugging email:

The output of the process was



(Length of string was 0)



(Length of string was 0)

Start Time: 12/4/2008 4:04:23 PM 736
End Time: 12/4/2008 4:04:23 PM 861
Exit Code: 1
Machine: .


As you can see, there's nothing in the standard output or the standard error streams.  The only indication that there was an error is the fact that the exit code is 1, rather than 0, as it is when it runs successfully.

So, cscript.exe is giving an exit code of 1.  Does that mean anything meaningful?  I haven't been able to find a list of exit codes for cscript.exe.
        static void Main(string[] args)
        {
            SmtpClient client = new SmtpClient("localhost", 25);
            //SmtpClient client = new SmtpClient("localhost", 26);
            System.Diagnostics.ProcessStartInfo start = new System.Diagnostics.ProcessStartInfo(@"c:\windows\system32\cscript.exe",
                    @"e:\webmarket\www\wsh\TestScript.vbs");
            start.RedirectStandardOutput = true;
            start.RedirectStandardError = true;
            start.UseShellExecute = false;
            System.Diagnostics.Process process = System.Diagnostics.Process.Start(start);
            process.WaitForExit();
            StreamReader reader = process.StandardOutput;
            string output = reader.ReadToEnd();
            Console.Write(output);
 
            string errorOutput =  process.StandardError.ReadToEnd();
 
            MailMessage message = new MailMessage("myemail", "myemail");
            message.Subject = "Debug .net app ran at " + DateTime.Now.ToString();
            message.Body = "The output of the process was \n\n" + output + "\n\n(Length of string was "
                + output.Length.ToString() + ")\n\n"
                + errorOutput + "\n\n(Length of string was "
                + errorOutput.Length.ToString() + ")\n\n"
                + "Start Time: " + process.StartTime.ToString() + " " + process.StartTime.Millisecond.ToString() + "\n"
                + "End Time: " + process.ExitTime.ToString() + " " + process.ExitTime.Millisecond.ToString() + "\n"
                + "Exit Code: " + process.ExitCode.ToString() + "\n"
                + "Machine: " + process.MachineName;
            client.Send(message);
        }

Open in new window

try this and see if it helps :
resetting security settings back to defaults
http://support.microsoft.com/kb/313222
This is a Windows 2003 server and it looks like that KB is for XP Pro and Vista.  The same might work on Win2003, but as this is a production box I'm wary of just resetting everything back to defaults...
this is a head scratcher for sure....LOL
Did you for grins try the permissions on the SCRRUN.DLL ?
i would think that resetting back to defaults  may not break much as group policy should reset the appropriate settings? Ive done this on production pcs with no ill harm but havent tried on servers.
Changing the SCRRUN.DLL didn't have any effect.  I've been out of the office for a while but want to get back on this.  I got a reference to this technet article that might have something relevant, if I can get it properly digested... :-)

http://technet.microsoft.com/en-us/library/cc722152.aspx
I was thinking that finding the "Run with highest privileges" checkbox (mentioned in the Technet article) might be the trick, but I think that's actually only a Vista machine.
I actually wound up creating a .NET executable that calls the cscript.exe vbscript interpreter and attempts to run the .vbs file that way.  Here's the C# code:
           SmtpClient client = new SmtpClient("localhost", 25);
            System.Diagnostics.ProcessStartInfo start = new System.Diagnostics.ProcessStartInfo(@"c:\windows\system32\cscript.exe",
                    @"e:\webmarket\www\wsh\TestScript.vbs");
            start.RedirectStandardOutput = true;
            start.RedirectStandardError = true;
            start.UseShellExecute = false;
            System.Diagnostics.Process process = System.Diagnostics.Process.Start(start);
            process.WaitForExit();
            StreamReader reader = process.StandardOutput;
            string output = reader.ReadToEnd();
            Console.Write(output);

            string errorOutput =  process.StandardError.ReadToEnd();

            MailMessage message = new MailMessage("me@mydomain.com", "me@mydomain.com");
            message.Subject = "Debug .net app ran at " + DateTime.Now.ToString();
            message.Body = "The output of the process was \n\n" + output + "\n\n(Length of string was "
                + output.Length.ToString() + ")\n\n"
                + errorOutput + "\n\n(Length of string was "
                + errorOutput.Length.ToString() + ")\n\n"
                + "Start Time: " + process.StartTime.ToString() + " " + process.StartTime.Millisecond.ToString() + "\n"
                + "End Time: " + process.ExitTime.ToString() + " " + process.ExitTime.Millisecond.ToString() + "\n"
                + "Exit Code: " + process.ExitCode.ToString();
            client.Send(message);


When it runs successfully, this is the email I get (the "Starting" and "Ending" lines are output by the .vbs file it's attempting to run):

The output of the process was Microsoft (R) Windows Script Host Version 5.6Copyright (C) Microsoft Corporation 1996-2001. All rights reserved.StartingEnding(Length of string was 136)(Length of string was 0)Start Time: 12/12/2008 2:37:08 PM 756End Time: 12/12/2008 2:37:09 PM 272Exit Code: 0

However, when I log out of the machine, I start getting output like this:

The output of the process was (Length of string was 0)(Length of string was 0)Start Time: 12/12/2008 2:38:00 PM 474End Time: 12/12/2008 2:38:00 PM 521Exit Code: 1
Both stdout and stderr are empty strings, and the exit code changed from 0 to 1.

So at this point it seems pretty clear that it has something to do with cscript.exe not executing properly when the user is not logged in interactively.  But why?  And why did it work up until a few months ago?

I made another interesting discovery.  After a reboot, the problem seems to resolve itself for a little while (hours, maybe a day or two), but eventually it comes back.

I'm pretty much out of ideas at this point, but if anybody can come up with a solution, I'm open to hear it! :-)  Our next step at this stage is to rewrite the .vbs files as .NET apps, which appear to run without issue.  But that's a big headache that shouldn't be necessary!

  -Josh
Alright, create a batch file that calls your script and then schedule task the batch file and see if that works.
I already tried that, no luck with that method either.
Pretty sure you'll have to try the "delegation of authority" route then
read up on this, it may help:
http://searchwinit.techtarget.com/tip/0,289483,sid1_gci860487,00.html 
We recently tried setting this task to run as the domain administrator, and it still didn't work.  I'm not sure how we could use the "delegation of authority" route to give the domain administrator account any privileges that it doesn't already have...
have you tried forcing it to run as wscript instead of cscript?
yup
Article says:
When you either create  a local at command to schedule a command, a script, or a program to run at a specified date and time or use Task Scheduler to create a scheduled task, if you push either the at command or the scheduled task over the network to another computer, the task may not run. When the task does not run, the following error is logged in the schedule log:  0x8004130f: No account information could be found in the Task Scheduler security database for the task indicated.

But, we didn't create this task with at, and it has not been pushed to another computer.  Also, their resolution is to log on to the computer, which we have done many times and it hasn't resolved the issue, unfortunately.
trying here....:),,,,,,just dont understand cause I have many scripts and tasks that run while no one is logged on without any issue.
found this:
Modify the permissions of CMD.exe in the windir\system32 folder to
assign the BATCH group the Read and the Read & Execute permissions. The
scheduled task is failing because it needs to spawn a command prompt.
Are you  using any mapdrives in script or scripts ? If so change to UNC path and try again
dstewartjr:trying here....:),,,,,,just dont understand cause I have many scripts and tasks that run while no one is logged on without any issue.

So do we!  And these scripts used to work!  That's what is frustrating, there is no reason that I can come up with that they shouldn't be working.

I already came across the "modify cmd.exe permissions" suggestions another place, and tried that, to no avail.

Not using any mapped drives, the only thing my testing script is doing is writing a single line to a log file saying "I ran at such-and-such a date and time"
have you added  error checking to the script to see what errors you get while logged off:
putting a "on error resume next"  so the code still finishes ?
 
Here's my test script:

Const ForReading = 1, ForWriting = 2, ForAppending = 8, CreateIfNotExist = -1
LogFile = "c:\temp\TestLog.log"
Set LogObjFSO = CreateObject("Scripting.FileSystemObject")
set LogObjFile = LogObjFSO.OpenTextFile (LogFile, ForAppending, True)
LogObjFile.WriteLine "Task ran at: " & Now
LogObjFile.Close

How would I add error checking to that see if errors are being thrown?

  -Josh
what is the location of the script??
Right now I've got it in c:\temp, but I've had it in a handful of different locations, trying to determine if moving things into a different folder would have any effect.
second link give any help?
That might have some useful info, but I'm out of the office until January 2nd.  I'll have to look into this at that time.
Ok, I read that link in more detail and I don't think it helps in my situation.  They discuss relative vs absolute paths, but in my case, both relative and absolute paths work when logged in, and neither work when logged out.

  -Josh
I would then get it to work using the batch method and be done with it, spare yourself the headache....:)
Unfortunately it's doing stuff that we can't do via a batch file, but it is looking like we're going to need to rewrite the scripts as something else, something that will run!  I have a feeling we'll use C# and compile to executables, but we haven't reached a firm decision.
For clarification: the test script I posted is not doing anything we couldn't do in a batch file, but we have other scripts that are doing things we couldn't do in a batch file.  Specifically, launching a web browser and navigating to several specific pages, then closing the browser.

If there's a way to get a batch file to do that, I don't know it--you could certainly launch the browser and send it to a specific page, but I don't know how you would then control the browser and tell it to go to subsequent pages.  I don't think you can.
I'm running into this same problem with a batch file that runs a powershell script.  Very simple code that checks the size of a folder and deletes old backup files if the folder is over a specific size.  The powershell script works fine by itself and the batch file I call from task scheduler works fine, but when Task Scheduler runs it, I'm getting the same 0x1 result.  My system is Windows 2008.  I know this doen't help you out any, but I just started on this and will plug away and let you know if I figure it out.
try adding something like this to script:
from http://www.computerperformance.co.uk/Logon/Logon_Script_Troubleshooting.htm



Err.Number
Err.number is the first stage in introducing proper error correcting code.  Combined with If ..then... End If, Err.number offers real solutions to your problem.  The only trouble is that you need experience both of the If ..then structures and the possible logical outcomes.  Perhaps my ideas for err.number are best explained by an example:

' Sub Routine
Sub GuyCase()
 ' Select Case (Not Case Select!)
errLogonScript = err.number
Select Case errLogonScript
Case vbEmpty strError = "No Problem "
Case -2147024811 strError = "Drive already in use "
Case -2147023665  strError = "Check server name " 
Case -2147023693 strError = "Check share name " 
Case -2147024829 strError = "Another share name problem "
' Finish with Case Else in order to catch exceptions
Case  Else strError = "Research this number: "
End Select
WScript.Echo strError & err.number
' Wscript.Echo "Errors = " '& err.count
err.clear
err.number = vbEmpty
End Sub

can you post a screenshot of the failing scheduled task from the "task" tab and "security" tab?
also have you tried?

1. Right-click My Computer and from the drop down menu click Manage.
2. From the Services and Applications menu, click Services.
3. From the right scroll down menu, double-click Task Scheduler.
4. Click the Log On tab, select the Local System Account and Allow Service to Interact with Desktop options, and then click Apply.
5. Click the General tab, click Start
No change whether "Interact with Desktop" is checked or unchecked.

Attached are screenshots.

I'll try the error number thing when I get a chance, but I'm not very hopeful because based on everything I can tell, the script is not executing at all.  In other words, it's not like there's an error in the script that we can trap for, it's that the script doesn't even start.

  -Josh

tasktab.png
securitytab.png
Is E:\ a physical drive on this computer or a mapped drive?
Physical drive
Could this be a problem writing to the log file Schedlgu.txt?  On 12/3 you said "In there, I see records of all the successful runs.  But there is no log entry for the times that it is supposed to run but is not running.".  Could the task be terminating with the 0x1 result because it cannot write to the log file for some reason?
Lets hope so, this thread is huge.....LOL
Regarding writing to the log file: I've checked the permissions on that file and the account the task is running as has full rights to the file.

Also, remember that one of the other things I tried was to write a C# program that called cscript.exe.  If you go to the command prompt and type cscript.exe you'll get something like this:

Microsoft (R) Windows Script Host Version 5.6Copyright (C) Microsoft Corporation 1996-2001. All rights reserved.

Now, it's not actually doing anything besides telling you the version information.  It's not running any vbscript code, it's not trying to write to a log file, it's just printing out version information.

My C# program would capture the results it got when it called cscript and email it to me, and if I was logged in when the C# program ran, I would see that version information.  As soon as I logged out (and it continued to run, as my C# program was setup as a scheduled task), it started getting an empty string back when it executed cscript.exe).

So, again, it does not appear that it's related to any vbscript code, it's related to the windows script host (wscript and cscript) not executing when the user is not logged in.
and its failing because somewhere it is trying to do something that can only be done while logged on, so you needed to look for something to supress that. Hence the added command line options.
It seems that it is the task scheduler service that is failing, not the script or executable that the scheduler is running.  The scheduler itself needs to write to that logfile and may be failing because it can't for some reason.  It should write to that log file anytime it runs any task.  Since there are missing log entries, it apparently is having a problem writing to the log file.
give this a try from another forum
 
 run the following batch file to see what's going on:

@echo off
echo %date% %time% Start of job > c:\test.log
echo User=%UserName% >> c:\test.log
cacls c:\*.* >> c:\test.log
cacls c:\a*.* >> c:\test.log
cacls c:\admin >> c:\test.log
cacls c:\admin\scripts >> c:\test.log
etc. etc.  
global-works wrote:
It seems that it is the task scheduler service that is failing, not the script or executable that the scheduler is running.

But, my C# app, running as a scheduled task, can write to the log file just fine.  It's only the vbscript that's having trouble.  Both would be kicked off by the task scheduler, since they are running as scheduled tasks.  So if it's a problem with the task scheduler's permissions, why would the C# app work but not the vbscript?

dstewartjr, I'll try that and report back, it may not be until tomorrow as I've had a few other more urgent items come up that I need to address.
dstewartjr said:
try these command line options//b /nologo

Tried that, no change.  Working on other suggestions now...
Well well, this is very interesting--adding //b /nologo *and* changing from cscript to wscript appears to have done something.  My little test vbscript is now running when the user is logged off.  Let's see if it will continue to run consistently now!  We've had issues in the past where it would mysteriously start working, then quit working after some time.  Let's hope that this will not be a repeat of that scenario.

//b /nologo with cscript did not produce any change.  Not sure why wscript would produce a different result, but hey, at this point all I care about is getting it to work!
Finally, Good news.....:)  are you crossing your fingers?
 
 
this is why
 
//B         Batch mode: Suppresses script errors and prompts from displaying

more here:
http://www.robvanderwoude.com/wsh.html 
 
Ok, I think that the actual cause of the change was switching from cscript to wscript.  Why that would matter, I'm not sure--I would think that the one that should work better when logged off is cscript, not wscript.

Here's where we're at: after switching to wscript, I can see that my test task is running successfully, but when I tried switching the other tasks to wscript, I can see that they *run*, but there's an error when it gets to this line:

Set objIE = CreateObject("InternetExplorer.Application")

So it seems it's having trouble creating the IE object.  I'm using On Error Resume Next to get the error information.  It's giving a blank Err.Description and Err.Source, and the Err.Number is -2147467259.  Why would the Err.Description and Err.Source be blank?

Attached is the complete script (with usernames and passwords scrubbed)

Dim startTime
startTime = Now
 
Const ForReading = 1, ForWriting = 2, ForAppending = 8, CreateIfNotExist = -1
LogFile = "E:\WebMarket\www\WSH\ProcessClosingsLog.txt"
Set LogObjFSO = CreateObject("Scripting.FileSystemObject")
set LogObjFile = LogObjFSO.OpenTextFile (LogFile, ForAppending, True)
 
Dim objIE
Dim gsURL
Dim gsAdminName
Dim gsAdminPassword
Dim giShowResults
 
'*** Configuration Section ***
'Set this to your site's URL path to the auction and your admin login/password
gsURL = "{removed}"
gsAdminName = "{removed}"
gsAdminPassword = "{removed}"
'Set this to TRUE or FALSE, TRUE if you want to see the results of the closing, FALSE if you don't
giShowResults = False
'*** End of Configuration ***
    
 
On Error Resume Next
Set objIE = CreateObject("InternetExplorer.Application")
If Err.Number = 0 Then
 
    objIE.Visible = giShowResults
    objIE.Navigate(gsURL & "APAdmin.asp?cmd=login&loginname=" & gsAdminName & "&password=" & gsAdminPassword)
    Do While objIE.Busy
        WScript.Sleep 2000
    Loop
    
    objIE.Navigate(gsURL & "APAdmProcessClosings.asp?cmd=run&AutomatedProcess=y")
    Do While objIE.Busy
        WScript.Sleep 2000
    Loop
    
    If Not giShowResults Then
        objIE.Navigate(gsURL & "APAdmin.asp")
    End If
 
    objIE.Quit
    
    LogObjFile.WriteLine "Process closings task ran at: " & Now & " (Started at " & startTime & ")"
    LogObjFile.Close
Else
    'MsgBox "Internet Explorer is not installed. IE 4.x or later is required.", 0, "Process Closings"
    
    LogObjFile.WriteLine "ERROR: Process closings task ran at: " & Now & " (Started at " & startTime & ") Error Description: " & Err.Description & "|Error Source: " & Err.Source & "|Error number " & Err.Number
    LogObjFile.Close
End If

Open in new window

Last line is "Set objIE = nothing" -- looks like that got truncated from code I posted in my previous post.
Hmm... I've been around and around with this error and can't seem to figure it out.  I've found a bunch of other people who reported issues with CreateObject("InternetExplorer.Application") in vbscript, when running as a scheduled task for a user who is logged off (just like I am experiencing).  However, none of them ever really solved it.  Instead, they figured out a workaround to not use CreateObject("InternetExplorer.Application").

For most other people they only needed to open one page and/or send on HTTP request.  But unfortunately, in my case, I need to open on page, then navigate to another page, and the browser will need to execute JavaScript on that page.  So, what we need is a way to control the browser, and CreateObject("InternetExplorer.Application") did it in the past for us--but it's not working now for some reason.

dstewartjr, I looked at that link, but didn't see anything that was applicable, unfortunately.

Can you instead of using a URL path try using a UNC path?
It's failing on this line:

Set objIE = CreateObject("InternetExplorer.Application")

So there's no URL vs UNC path there... Not sure what you mean?

I tried getting rid of all the other lines of the script, and it fails on that line, whether or not you have URL or UNC paths elsewhere.

In other words, I tried this (see below), and it still gives the same error (blank source and description, error number of -2147467259).

Dim objIE
 
On Error Resume Next
Set objIE = CreateObject("InternetExplorer.Application")
If Err.Number = 0 Then
    LogObjFile.WriteLine "Process closings task ran at: " & Now & " (Started at " & startTime & ")"
    LogObjFile.Close
Else
    LogObjFile.WriteLine "ERROR: Process closings task ran at: " & Now & " (Started at " & startTime & ") Error Description: " & Err.Description & "|Error Source: " & Err.Source & "|Error number " & Err.Number
    LogObjFile.Close
End If
 
Set objIE = nothing

Open in new window

ok I tested with both wscript and cscript and removed "on error resume next"
and had no errors or problems either way
Is it working for you when you set it as a scheduled task, and then log all user off the machine?  That's when it's failing for me.  It works when I'm logged in.
Think I found something
 
add:
 
Do While ie.Busy
Wscript.Sleep 500
Loop
 
taken from here:
http://www.eggheadcafe.com/software/aspnet/31960082/objiedocumenttitle-unkn.aspx 
yes, it was working both logged in or off
If I add that code here:

Set objIE = CreateObject("InternetExplorer.Application")
Do While objIE.Busy
    Wscript.Sleep 500
Loop

Then the script appears to just run forever when logged off.  It's like objIE.busy is always true?
probably  waiting for input.
Hmm, but when I'm logged on I don't have to provide input for it to finish...?
maybe this will work better
 
while objIE.busy
wend

No change with that alternate while loop
Are we at wits end yet???    ;-D
SOLUTION
Avatar of Don
Don
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Yeah, actually I tried using PowerShell to accomplish the same thing.  But I discovered it exhibits similar behavior!  :-(

When I'm logged on, the script runs fine.  When I'm logged off, it doesn't.  Arg!
It must be that it is waiting for input or values dont get pushed???
Yeah, or there is some kind of "security feature" that prevents IE from launching when there is no user logged on?
Yeah, I saw that.  He's got the same problem as me, but unfortunately the workaround he uses won't work for me because we need it to actually open in IE (or any browser that can execute JavaScript).  That's because the pages that we're requesting have JavaScript on them that needs to run for the pages to work properly.

Just making an HTTP request via the MSXML2.ServerXMLHTTP object won't work, because it will just give us the raw code back, and it won't execute the JavaScript.
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
By the way, I changed the scheduled task properties to terminate the task if it runs for longer than 3 minutes.  We'll see if that takes care of things, and if so, we can declare victory.

Although admittedly we've rather taken the scorched earth approach to dealing with things here.  First, we kill any iexplore.exe processes if we're not getting a response, and then we set the scheduled task to kill the script if it becomes unresponsive.  Kinda an ugly workaround... but hopefully it will work!
Well, we both learned a thing or two here!!!
I have the same problem - when the user who is configured to run the scheduled task is logged in, the scheduled task runs perfectly. But when the user is not logged in, it errors out. I wrote event logs at each step in the code and found that it breaks at this point:

email.getstream()

where email is a CDO.Message object. The error it gives is: Retrieving the COM class factory for component with CLSID {00000566-0000-0010-8000-00AA006D2EA4} failed due to the following error: 80070057.

Can somebody please help?
t_c_sekar
 
You're gonna have to start a new thread.
What was the solution??
See my post on 02.02.2009 at 05:37AM PST, ID: 23526731

The solution was to alter the script to attempt to takeover, and then kill the iexplore.exe process if it's become unresponsive.  Also, set the scheduled task to terminate if it runs longer than a reasonable period of time (I chose 3 minutes).
You have should than accepted that as your answer instead of just closing out the question, and your welcome for any help I provided.
I did accept that as the answer.  I went to that post and hit "accept as solution" on that post.
And thanks for all your feedback while trying to get this solved.
I see one of the options is:

Accept your own comment, and award points to Experts for their assistanceIf you answered your own question, but wish to award points to Experts for their attempts to help, use this option.

That sounds like what I want however I do not see a button or a link like this anywhere.
Ok, I believe I got it, I had to click "Accept and Award Points" on my own post.