Jump to content

No Pop-up when running AutoIT script via Scheduled Task


Recommended Posts

I am using the following script to restart computers at a specific time each day using Scheduled Task to create the event that would call the Script (Compiled .exe)

#include <AutoItConstants.au3>
#include <Misc.au3>
#NoTrayIcon
;Begin Script
Local $L_V_Scalar_Variant_Message = "This computer will restart in the next 2 minutes; save  all open documents immediately!"
SplashTextOn("Restart Computer", $L_V_Scalar_Variant_Message, -1, -1, -1, -1, $DLG_TEXTLEFT, "", 24)
Sleep(120000) ;120 seconds
M_S_Restart()
SplashOff()
Func M_S_Restart()
Shutdown(6)
EndFunc

When i run the script by double clicking on the exe it just works fine.

image.png.6ad815baa2a316cbd172229965e615d3.png


Now i've added the complied script to Scheduled Task and set it to run daily at 4 am. User should be notified, if they are logged in or in locked state. but apparently the user doesnot get any notification and the computer is restarted which is a big problem, as their work is not saved.

I am attaching the XML code for the Task.

<?xml version="1.0" encoding="UTF-16"?>
<Task version="1.2" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
  <RegistrationInfo>
    <Description>Restart computer daily at 4AM</Description>
    <URI>\U_A_A_WindowsRestartCore</URI>
  </RegistrationInfo>
  <Triggers>
    <CalendarTrigger>
      <StartBoundary>2019-03-08T04:00:00+00:00</StartBoundary>
      <Enabled>true</Enabled>
      <ScheduleByDay>
        <DaysInterval>1</DaysInterval>
      </ScheduleByDay>
    </CalendarTrigger>
  </Triggers>
  <Principals>
    <Principal id="Author">
      <UserId>S-1-5-21-209663586-3969970584-2577160918-9632</UserId>
      <LogonType>InteractiveToken</LogonType>
      <RunLevel>LeastPrivilege</RunLevel>
    </Principal>
  </Principals>
  <Settings>
    <MultipleInstancesPolicy>IgnoreNew</MultipleInstancesPolicy>
    <DisallowStartIfOnBatteries>true</DisallowStartIfOnBatteries>
    <StopIfGoingOnBatteries>true</StopIfGoingOnBatteries>
    <AllowHardTerminate>true</AllowHardTerminate>
    <StartWhenAvailable>false</StartWhenAvailable>
    <RunOnlyIfNetworkAvailable>false</RunOnlyIfNetworkAvailable>
    <IdleSettings>
      <Duration>PT10M</Duration>
      <WaitTimeout>PT1H</WaitTimeout>
      <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>
      <Command>C:\U_BayVL00\Programs\U_A_A_WindowsRestartCore.exe</Command>
    </Exec>
  </Actions>
</Task>

Any solution?

Link to comment
Share on other sites

  • Developers

That is not really an AutoIt3 Question, but rather a Windows Scheduler one. ;)

Maybe: https://docs.microsoft.com/en-us/windows/desktop/taskschd/taskschedulerschema-hidden-settingstype-element ?

Jos

Edited by Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

  • Developers

Understood..  but like I said, this is not really an Autoit3 question but rather a Window question.

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

  • 2 weeks later...
On 3/14/2019 at 4:54 PM, Bert said:

Simple solution to this problem - create a second exe that launches your rebooter at the time you want using the task scheduler. The EXE launcher will be hidden yet your rebooter won't be. 

Hi Bert, I seem to have spoken too soon.

Today I deployed the schedule task that calls the other exe that should show up the message that system is restarting.

But when I ran the scheduled task it didn't pop up the message neither. 

basically there are 2 EXE files 

image.png.4c907e92bacc3aa9434bb68afff40e72.png

The RestartScheduler calls the RestartCore which should display the popup notification, and when i run it manually it does and works as expected.

But running the same in Task Scheduler, does not show any GUI.

image.png.dbd59b4e74d29e19ce4ea089be21963a.png

even though i can see it running in Task Manager, i even tried changing from SYSTEM to my Username and that didn't help either.

image.png.ed008c19014e659f71d94068e9b06b8b.png

 

I am adding the code here if someone can help me tweak this, I would appreciate it a lot.

;This script is necessary even though the only thing that it does is call another script because if the other script ran directly it would run under the user  account and therefore the message would not appear on the logged-on user's screen.
#include <AutoItConstants.au3>
#include <Misc.au3>
#NoTrayIcon
M_S_RestartWindows()
Func M_S_RestartWindows()
   Run("C:\Programs\U_A_A_WindowsRestartCore.exe")
EndFunc
#include <AutoItConstants.au3>
#include <Misc.au3>
#NoTrayIcon

Local $sMessage = "This computer will restart in the next 2 minutes; save  all open documents immediately!"
SplashTextOn("Restart Computer", $sMessage, -1, -1, -1, -1, $DLG_TEXTLEFT, "", 24)
Sleep(120000) ;120 seconds
M_S_Restart()
SplashOff()


Func M_S_Restart()
Shutdown(6)
EndFunc

 

Link to comment
Share on other sites

Well I just tested it directly (without using a second .exe) and it worked fine : splash showed out as intended.  Use your code except for the restart.  Compiled x86.  Win7.  So the problem is not autoit, but the way the task has been scheduled.

Edited by Nine
Link to comment
Share on other sites

7 hours ago, AasimPathan said:

@Nine can you try creating a scheduled task in windows & see if you can still see the GUI as you do when running the exe? 

This is what I did.  I created a base task running every day at a few minutes after creation and it worked perfectly. 

Edited by Nine
Link to comment
Share on other sites

On 3/26/2019 at 5:59 PM, Nine said:

This is what I did.  I created a base task running every day at a few minutes after creation and it worked perfectly. 

Change it to a different user and please test it if you can.

I created the task as the local user and ran it and it works just fine. but remember we are doing this through GPO and it uses an administrator account, so when i changed the user in the scheduled task it doesn't work.

Link to comment
Share on other sites

Works like a charm.  Create the task with User A (with admin rights).  Logged off. Logged in with User B.  And the splash showed up at the specified time. No problem.  But I do not use GPO tho.

Link to comment
Share on other sites

5 minutes ago, AasimPathan said:

can you export and paste the xml from schedule task? maybe something is wrong on my end. or maybe it works in windows 7 and not 10

<?xml version="1.0" encoding="UTF-16"?>
<Task version="1.3" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
  <RegistrationInfo>
    <Date>2019-03-28T08:01:37.4475448</Date>
    <Author>NINE\Nine</Author>
  </RegistrationInfo>
  <Triggers>
    <CalendarTrigger>
      <StartBoundary>2019-03-28T08:11:00</StartBoundary>
      <Enabled>true</Enabled>
      <ScheduleByDay>
        <DaysInterval>1</DaysInterval>
      </ScheduleByDay>
    </CalendarTrigger>
  </Triggers>
  <Principals>
    <Principal id="Author">
      <GroupId>S-1-5-32-545</GroupId>
      <RunLevel>LeastPrivilege</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>
    <DisallowStartOnRemoteAppSession>false</DisallowStartOnRemoteAppSession>
    <UseUnifiedSchedulingEngine>false</UseUnifiedSchedulingEngine>
    <WakeToRun>false</WakeToRun>
    <ExecutionTimeLimit>P3D</ExecutionTimeLimit>
    <Priority>7</Priority>
  </Settings>
  <Actions Context="Author">
    <Exec>
      <Command>C:\Applications\AutoIt\TaskScheduler.exe</Command>
    </Exec>
  </Actions>
</Task>

 

Link to comment
Share on other sites

24 minutes ago, AasimPathan said:

Well thank you, that did the trick I suppose, changing the user from using an administrative account i set it to "Users" and it worked.

:)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...