I have a batch file (below) that works perfectly when run, however, when I set up the bat file in the task scheduler it ain't working right. The task scheduler does indeed run the task successfully, so I'm assuming it has to do with permissions for the Administrator regarding the .exe file. I already made sure the admin has permission in the local security options to "logon as a batch job" and I made sure the admin has full control of the entire folder that the .exe is contained in. When I test the batch file manually and it works, I am logged in as the admin.
EDIT: Summary of things asked and answered in comments:
- M:\ is a networked drive. It is physically located on this same server, but per requirements of the program, the networked drive letter must be used.
- moved bat file to C:\ in the theory that having it on the desktop might be an issue: no change.
- When the exe is run, a gui is supposed to launch. This happens when the bat is run manually, but the gui fails to launch when task manager is used. The remainder of the bat runs as intended. Per software developer, gui should be able to run even from task manager and they have not seen this behavior before.
EDIT 2: So I've confirmed that the problem is that the GUI DOES need to launch, contrary to expectations. I can get the task to work by changing to
Run only when user is logged on, which causes the UI to appear. However, since this is a server and the task runs in the wee hours of the morning, there usually is not a user logged in. Is there a way to cause the user to log on and off at a specific time? Or another solution other than always leaving a user logged in?
The batch file (REVISED):
netsh interface set interface "Local Area Connection 2" DISABLED iisreset /stop timeout /t 120 iisreset /start netsh interface set interface "Local Area Connection 2" ENABLED start /d "M:\CBSW" optimize.exe T
The exported XML from the task in task scheduler (revise:
<?xml version="1.0" encoding="UTF-16"?> <Task version="1.2" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task"> <RegistrationInfo> <Date>2012-01-10T09:42:01.9781872</Date> <Author>DOMAIN\Administrator</Author> </RegistrationInfo> <Triggers> <CalendarTrigger> <StartBoundary>2012-01-10T02:00:00</StartBoundary> <Enabled>true</Enabled> <ScheduleByWeek> <DaysOfWeek> <Monday /> <Thursday /> </DaysOfWeek> <WeeksInterval>1</WeeksInterval> </ScheduleByWeek> </CalendarTrigger> </Triggers> <Principals> <Principal id="Author"> <UserId>DOMAIN\Administrator</UserId> <LogonType>InteractiveToken</LogonType> <RunLevel>HighestAvailable</RunLevel> </Principal> </Principals> <Settings> <IdleSettings> <Duration>PT10M</Duration> <WaitTimeout>PT1H</WaitTimeout> <StopOnIdleEnd>true</StopOnIdleEnd> <RestartOnIdle>false</RestartOnIdle> </IdleSettings> <MultipleInstancesPolicy>IgnoreNew</MultipleInstancesPolicy> <DisallowStartIfOnBatteries>true</DisallowStartIfOnBatteries> <StopIfGoingOnBatteries>true</StopIfGoingOnBatteries> <AllowHardTerminate>true</AllowHardTerminate> <StartWhenAvailable>false</StartWhenAvailable> <RunOnlyIfNetworkAvailable>false</RunOnlyIfNetworkAvailable> <AllowStartOnDemand>true</AllowStartOnDemand> <Enabled>true</Enabled> <Hidden>false</Hidden> <RunOnlyIfIdle>false</RunOnlyIfIdle> <WakeToRun>false</WakeToRun> <ExecutionTimeLimit>P3D</ExecutionTimeLimit> <Priority>7</Priority> <RestartOnFailure> <Interval>PT15M</Interval> <Count>3</Count> </RestartOnFailure> </Settings> <Actions Context="Author"> <Exec> <Command>E:\IISRESET+Optimize.bat</Command> <WorkingDirectory>E:\Data\Optimize\</WorkingDirectory> </Exec> </Actions> </Task>
M:a mapped network drive, or a actual drive local to the system the script is run on?