I have a scheduled task (generated by kix) that shuts the loacl PC down at 3:00am... but it does pop up a msgbox before hand to avert the shutdown, if it is in use at the time...
Code:
;? "Set Logoff Policy"
$file ="%windir%\logoff.kix"
$time ="0330"
$days =1+2+4+8+16+32+64 ; m,t,w,th,f,sa,su
$command="kix32.exe $file"
$mstime ="********"+$time+"00.000000-240" ; MS notation for time yyyymmdd is passed with *
$message='Click the OK Button, or the computer will shutdown in 30 seconds'
$title ='Restart Warning from AHCA Information Technology'
del $file ;delete this line after March 1, 2004
if not exist($file)
$=open(1,$file,5)
$=writeline(1,'$=setconsole("hide")'+@CRLF)
$=writeline(1,'$box=messagebox("$message","$title",0+48+4096,30)'+@CRLF)
$=writeline(1,'if $box=-1'+@CRLF)
$=writeline(1,' $=shutdown("","The system is being shutdown",10,1,2)'+@CRLF)
$=writeline(1,' endif'+@CRLF)
$=writeline(1,''+@CRLF)
$=close(1)
endif
$objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
if $objWMIService
$colItems = $objWMIService.ExecQuery("Select * from Win32_ScheduledJob",,48)
$taskexist=0
For each $objItem in $colItems
if $objItem.Command = $command
if $objItem.DaysOfWeek=$days
if $objItem.StartTime=$mstime
$taskexist=$objItem.JobId
else
$=$objItem.delete
endif
else
$=$objItem.delete
endif
endif
next
if not $taskexist
$runrpt = 0 ; boolean for run repeatedly
$daymon = 0 ; used for specific dates
$interact=1 ; boolean for interactive with desktop
$objNewJob = $objWMIService.get("Win32_ScheduledJob")
$errJobCreated = $objNewJob.Create($command,$mstime,$runrepeatedly,$days,$daymon,$interact)
$objWMIService = 0
endif
endif