Link to home
Start Free TrialLog in
Avatar of JazIT
JazIT

asked on

Run a batch file as a scheduled task in Windows Server 2008

I am embarrassed at having to ask for help here but I have spent enough time on it myself.
All that I am trying to do is run a batch file as a scheduled task in Windows server 2008. I have read most of the other similar issues on this site with no success. This server is the AD server & is logged on as the Administrator. The batch file is a very simple xcopy from one mapped drive to a local drive.
cd \
cd c:\users\administrator.DOMAIN
xcopy g:\mergedata\*.* d:\guardebackup\backup /e /d /i /y > c:\merge.txt

According to the task scheduler history the script has completed with the result 0x0

Log Name:      Microsoft-Windows-TaskScheduler/Operational
Source:        Microsoft-Windows-TaskScheduler
Date:          12/10/2009 7:52:42 PM
Event ID:      201
Task Category: Action completed
Level:         Information
Keywords:      
User:          ROYALPARK\administrator
Computer:      RPSrv01.chevronglass.com.au
Description:
Task Scheduler successfully completed task "\Hourly Backup of Guarde Data" , instance "{1d1a713f-8433-45ac-b39f-f19548e29a2d}" , action "C:\Windows\SYSTEM32\cmd.exe" with return code 4.
Event Xml:
<Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event">
  <System>
    <Provider Name="Microsoft-Windows-TaskScheduler" Guid="{de7b24ea-73c8-4a09-985d-5bdadcfa9017}" />
    <EventID>201</EventID>
    <Version>0</Version>
    <Level>4</Level>
    <Task>201</Task>
    <Opcode>2</Opcode>
    <Keywords>0x8000000000000000</Keywords>
    <TimeCreated SystemTime="2009-10-12T09:22:42.127Z" />
    <EventRecordID>900309</EventRecordID>
    <Correlation ActivityID="{1D1A713F-8433-45AC-B39F-F19548E29A2D}" />
    <Execution ProcessID="8076" ThreadID="7684" />
    <Channel>Microsoft-Windows-TaskScheduler/Operational</Channel>
    <Computer>Server.domain.com.au</Computer>
    <Security UserID="S-1-5-21-436374069-308236825-1801674531-500" />
  </System>
  <EventData Name="ActionSuccess">
    <Data Name="TaskName">\Hourly Backup of Guarde Data</Data>
    <Data Name="TaskInstanceId">{1D1A713F-8433-45AC-B39F-F19548E29A2D}</Data>
    <Data Name="ActionName">C:\Windows\SYSTEM32\cmd.exe</Data>
    <Data Name="ResultCode">4</Data>
  </EventData>
</Event>

There is a second action configured, that sends me an e-mail & I receive that so the task completes but the batch file does not run. If I double click on the script it works. If I enter the script file into a command prompt it works.
I have tried the following.
1) Changing the .bat to a .cmd
2) Within the "Action" I have tried placing just the script file name, ie MergeDataHouly.bat & placing the location in "start in", ie C:\scripts as per another post.
3) I have edited the script to not change the current directory, ie just xcopy .....

Please assist in what should be a simple task
ASKER CERTIFIED SOLUTION
Avatar of oBdA
oBdA

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
Avatar of JazIT
JazIT

ASKER

The UNC change seems to have sorted it. I will confirm tomorrow.
I didn't know that UNC conventions were essential within a script that runs within Task Schduler!Thankyou