At Wits End with Task Scheduler problem Pls help.

Stephan Ledesma 0 Reputation points
2024-06-17T15:24:32.2433333+00:00

I have a batch script (batch server) that runs a python script (Batch server) to do some shenanigans in a network drive

The script runs perfectly fine when manually run and perfectly fine when 'user is logged on'

but fails at the important final hurdle.

here is a list of everything i have tried/done

I have mapped the environment variables for the relevant directories. - in my log files with extensive debugging for the automatic run (user logging in or not) there seems to be nothing wrong here. The mappings are all correct and it is connecting to the Tdrive. Wat the log does say is it cant locate the necessary file. (it is looking for a file with todays date in it, which is 100% there.) I THINK it gets into the right directory based on my debugging but says the file isnt there.

I have rebuilt the parsing of date and time variables thinking it may be a difference in environmental date time formats. - no avail.

i ran it as another user - no avail.

i reset the environments - no avail.

ive done the standard task master shenanigans.

Please help. There may be something i missed but please im out of ideas.

Capture

Capture2

Windows 10
Windows 10
A Microsoft operating system that runs on personal computers and tablets.
11,067 questions
{count} votes

1 answer

Sort by: Most helpful
  1. MotoX80 32,556 Reputation points
    2024-06-17T21:50:14.26+00:00

    The script runs perfectly fine when manually run and perfectly fine when 'user is logged on'

    The task scheduler does a user impersonation and not a full desktop logon when you set it to "Run whether user is logged in or not". Your network drives are probably not getting mapped. The easiest solution to the drive problem is to use the UNC path to the server (\\ServerName\ShareName\FolderName) instead of the drive letter.

    Add a "dir" statement to the bat file to get a directory list of files. Verify that you can see the files. Echo the environment variables too.

    I like to capture stdout and stderr at the overall task level. Set the task to execute cmd.exe and in the arguments field set it like this. Put this log file on the C drive, not a network drive.

    /c C:\Scripts\MyScript.bat  1>"C:\Scripts\Logs\MyScript.log" 2>&1
    
    
    

    That will capture the "dir" and your "echo" output.