batch file runs fine manually, but line that launches exe fails when batch run in task scheduler

3

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:

  1. 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.
  2. moved bat file to C:\ in the theory that having it on the desktop might be an issue: no change.
  3. 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>

tlynnec

Posted 2015-02-20T18:00:52.217

Reputation: 31

Is M: a mapped network drive, or a actual drive local to the system the script is run on? – Ƭᴇcʜιᴇ007 – 2015-02-20T18:04:37.830

it's the actual drive local to the system the script is run on. – tlynnec – 2015-02-20T18:06:46.657

Which account are you using to run the task? you user account or ???. – Ƭᴇcʜιᴇ007 – 2015-02-20T18:09:07.787

I'm not sure what you mean by "the local user" exactly -- the account you're currently logged in as? When you setup the task you have to assign a user to it, just go look a the task's General tab to see which user is assigned to run the task... – Ƭᴇcʜιᴇ007 – 2015-02-20T18:14:34.390

OK, you're right. Don't know where my brain was. Task is scheduled to run under the network Administrator account, which is the same one I use to test the batch file manually. I'm editing my question to reflect this as well. – tlynnec – 2015-02-20T18:16:21.690

Does the optimize.exe have a GUI? Also, perhaps Export your Task (right-click -> export) and then edit the exported XML into your question, it'll let us see all the settings used for the task. :) – Ƭᴇcʜιᴇ007 – 2015-02-20T18:21:06.363

xml added! the optimize.exe opens our billing program on the screen and then runs a set of optimizations of the databases – tlynnec – 2015-02-20T18:32:18.030

Similar to my question about M: -- is E: also a real local drive, or a mapped netowrk/subst'd drive? Also, have you tried without the 'Use Highest Available Privileges' set in the task (it does weird things sometimes). Another thought, have you tried moving the batch file to someplace other than your user's desktop? Like say into a new folder off the root of C:? – Ƭᴇcʜιᴇ007 – 2015-02-20T18:41:55.710

@tlynnec Can you add the main question to your post? – kenorb – 2015-02-20T18:55:45.267

Can you expand on what "it opens out billing program" means? I'm thinking that the billing program may not start if the task doesn't allow it's GUI (it's run in a session with no desktop for example) (if the optimize.exe is attempting to show/interact with it). – Ƭᴇcʜιᴇ007 – 2015-02-20T19:09:34.197

@Techie007 Yes, E: is also a real local drive. Without highest privileges, the network adapter cannot be enabled/disabled. I'll tested moving the location in an hour or so (gotta do it at lunch when I can kick everyone else out of the billing system). Thanks for the clues so far! – tlynnec – 2015-02-20T19:12:31.280

@Techie007. Ok, so moving the bat file did not make a difference. I spent a long time on the phone with the developers of the software, who indicated that the .exe line needs to use the mapped network drive, not the physical local drive (even though they are one and the same) due to the way the program is designed. So, I changed to the mapped drive and reordered the bat as shown in my question above. Again, it works fine when run manually, but when run via task manager the GUI fails to launch when it gets to the exe line. The software developers are totally stumped too. :( – tlynnec – 2015-02-20T23:31:45.800

For convenience, I've summarized key parts of these comments into the question above. – tlynnec – 2015-02-20T23:46:35.823

@Ƭᴇcʜιᴇ007 thanks for your help so far. I've found part of my problem and edited my question above. Any additional solutions you may have based on this new info I'd really appreciate! – tlynnec – 2015-02-23T19:24:04.007

1I would like to know why you don't want to keep a user logged in. I got a very similar situation in the past and resolved the problem by the combination of auto login and auto-locking (like Win-L). If you have a dedicated Windows account to perform this, everything will be fine. – Scott Rhee – 2015-03-10T22:23:22.240

The server in question runs a program that is accessed by 30+ workstations and a webserver all day long and, for whatever indeterminable reason, the workstations experience slowness in the program when the server is left logged in. Being able to auto-logon just before the task runs and auto-logoff after would be ideal for both running the necessary task and not slowing down the workstation users. – tlynnec – 2015-03-11T16:52:47.670

Can you update us with what happened? – Mr Ethernet – 2019-11-14T11:37:18.067

Answers

0

A GUI only app needs a desktop and you only get one of those when you're a logged in user.

But you may find some additional resources here: https://stackoverflow.com/questions/53232/how-can-i-run-a-windows-gui-application-on-as-a-service

user254395

Posted 2015-02-20T18:00:52.217

Reputation: