We help IT Professionals succeed at work.

Error running scheduled task in Windows Server 2008

Hello -
I have a batch file scheduled to run every Monday morning at 4am that is failing when it is only scheduled with an error of (0x1) in the Last Run Result row.  If I run the task manually it runs like it is supposed to.  The contents of the batch file are below.  The archive folder that it calls is in the same folder as the batch file.  In the Actions tab I have the following set as the path to the file.  I also have "Run with highest privileges" checked under the General tab.  Any ideas what I am doing wrong?  Thanks in advance.

"G:\INS\License\LIC Share\Run_GetFingerPrintRprt.bat"
ftp -s:ftp.txt 
copy *.csv archive\*.csv
exit

Open in new window

Comment
Watch Question

Full stack Software Engineer
Commented:
instead of schedule the task to run: "G:\INS\License\LIC Share\Run_GetFingerPrintRprt.bat"
change it to run: "G:\INS\License\LIC Share\Run_GetFingerPrintRprt.bat" > c:\temp\task.log

and check what the log states upon error

Author

Commented:
This is what I received.  I ran it in with the command line and I also added it as an argument and it still did not create the log.  
Capture.PNG

Author

Commented:
Ok, I figured it out.  The server was not wanting to create the temp folder.  This is what I received in the log.


C:\Windows\system32>ftp -s:ftp.txt  
C:\Windows\system32>copy *.csv archive\*.csv
*.csv
        0 file(s) copied.
C:\Windows\system32>exit

Author

Commented:
It looks like to me that the task is running the batch file from the system32 folder and not the folder where the file is located at.  How do I get it to run from the folder that the batch is located in?  
Meir RivkinFull stack Software Engineer
Commented:
the task is not running the script from system32, the script run its code from system32 cause it uses "cmd.exe".

so you want to first change the directory, so add to the beginning of your script:

cd <folder where the file is located at>

Author

Commented:
Thank you very much!  I have spent hours on this.  Your last comment is what really helped me.  Weird that this exact same task worked in Windows Server 2003 and not 2008 but it's working now.  Thanks again!
Meir RivkinFull stack Software Engineer

Commented:
your alternative is to pass the folder path to the script:
"G:\INS\License\LIC Share\Run_GetFingerPrintRprt.bat" "G:\INS\License\LIC Share" > c:\temp\task.log

and your script should look like this:

cd %0   -> change to the script directory first
ftp -s:ftp.txt
copy *.csv archive\*.csv
exit