Jump to content

Recommended Posts

Posted (edited)

I have an autoit script compiled and set to run as a scheduled task using the credentials of a domain account we use for scheduled tasks. When the logged in user runs the task they get the msgbox, when the scheduled task runs the msgbox never appears for the user to interact with. However, the msgbox does seem to be timing out properly. I don't know if it is a problem with my scheduled task, or with my autoit script, so here is the code if that helps:

#include <Array.au3>
#Include <date.au3>
;declare variables

$rebootanswer=0
$systemuptime=0
$uptimetest=iniread("\scripts\rebootscript\Reboot.ini", "options", "rebootdays","7")
$rebootmessage=string(iniread("\scripts\rebootscript\Reboot.ini", "options", "message","Error"))
$timeout=string(iniread("\scripts\rebootscript\Reboot.ini", "options", "timeout","Error"))
dim $ADlocation
Dim $list[1]

$ADlocation=string(iniread("\scripts\rebootscript\Reboot.ini", "options", "ADlocation","Error"))

$systemuptime=_uptime()

;check for system uptime and exit if less then the number of days specified in the ini file.

if($systemuptime < $uptimetest) then
;msgbox(0,"test","system does not need a reboot" & $uptimetest)
    Exit
    EndIf

If Processexists("Explorer.exe")==0 Then
Shutdown(6)
Else

;display a dialogue box, return the value of their response to the variable, 17 declares that the user can say ok, or cancel, second section is the box title
;third variable is the message that is displayed, 4th variable is the number of seconds before the msgbox times out, if it times out it acts as if they said ok

$rebootanswer = msgbox ( 17, "Reboot Warning", $rebootmessage, $timeout)

;if the user says yes, or does not answer within a minute, reboot the machine.  Otherwise, end script

if ($rebootanswer = 1 or $rebootanswer = -1) Then
shutdown (6)

Else
    Exit
EndIf

func _uptime(); convert system uptime into days.

$time=_gettime();set variable time to equal the uptime of the system in milliseconds, 
;then divide by 86,400,000 which makes the value equal to the number of days since a reboot

$time=($time/86400000)

Return $time
EndFunc

Func _GetTime();retrieve system uptime
    $Dll = DllCall("WinMM.dll", "long", "timeGetTime")
    Return $Dll[0]
EndFunc

EDIT: just talked with someone else in the office, he said his work around was to use AT to schedule the task, but he had a lot of problems getting the response from the message box back into his script (he was using VB I do not know if that applies to this). Would it be best to use AT with the /interactive flag, or is there a better way using schtask? I cannot find anything on how to make scheduled tasks made with schtask interactive in the microsoft technet information.

Edited by daishi5

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
  • Recently Browsing   0 members

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