A script/windows command to Gracefully Wait/Shut down

  command, pos, powershell, script, windows

I am trying to implement a script / command that would gracefully shut down an application and relaunch moments later (lets say 30 seconds). So far, I’ve got the script to do a graceful shut down and have not worked on the relaunch of the application yet.

The issue I am having is, this application is on about 100 terminals (different stores with POS stations – this is meant to gracefully shutdown their POS terminal app). However, I am struggling to figure out how to make this program wait for the user in the terminal to log off if their in the middle of a transaction. Right now, there is a delay and the execution ends if the user is logged in and does not wait for the user to log off.

Is there a way to make the executed script wait until a user is logged off to gracefully shut down the application rather than quit? Here is a sample of the xml I have:

<?xml version="1.0" encoding="UTF-16"?>
<Task version="1.2" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
  <RegistrationInfo>
    <Author>S3Admin</Author>
    <URI> Gracefull Shutdown</URI>
  </RegistrationInfo>
  <Triggers>
    <CalendarTrigger>
      <Enabled>true</Enabled>
      <ScheduleByDay>
        <DaysInterval>1</DaysInterval>
      </ScheduleByDay>
    </CalendarTrigger>
  </Triggers>
  <Principals>
    <Principal id="Author">
      <UserId></UserId>
      <LogonType>Password</LogonType>
      <RunLevel>HighestAvailable</RunLevel>
    </Principal>
  </Principals>
  <Settings>
    <MultipleInstancesPolicy>IgnoreNew</MultipleInstancesPolicy>
    <DisallowStartIfOnBatteries>true</DisallowStartIfOnBatteries>
    <StopIfGoingOnBatteries>true</StopIfGoingOnBatteries>
    <AllowHardTerminate>true</AllowHardTerminate>
    <StartWhenAvailable>false</StartWhenAvailable>
    <RunOnlyIfNetworkAvailable>false</RunOnlyIfNetworkAvailable>
    <IdleSettings>
      <StopOnIdleEnd>true</StopOnIdleEnd>
      <RestartOnIdle>false</RestartOnIdle>
    </IdleSettings>
    <AllowStartOnDemand>true</AllowStartOnDemand>
    <Enabled>true</Enabled>
    <Hidden>false</Hidden>
    <RunOnlyIfIdle>false</RunOnlyIfIdle>
    <WakeToRun>false</WakeToRun>
    <ExecutionTimeLimit>PT72H</ExecutionTimeLimit>
    <Priority>7</Priority>
  </Settings>
  <Actions Context="Author">
    <Exec>

//SLShutdown.exe is a shutdown command from the application

      <Command>C:userApplicationsSLShutdown.exe</Command>



      <Arguments>/T</Arguments>
    </Exec>
  </Actions>
</Task>

Source: Windows Questions

LEAVE A COMMENT