Jump to content
Sign in to follow this  
LapidusCreatorium

Scheduler Task issues

Recommended Posts

LapidusCreatorium

Hello,

I am new to AutoIT, and don't know much about it.

So I am asking your help.

I am trying to schedule an application execution after a few minutes or hours after the scheduled task was added.

I use this code.

I have modified it a little to take current computer time:

Local $oMyError = ObjEvent("AutoIt.Error", "MyErrFunc")
Local $objWMIService, $objShare, $objInParam, $objOutParams
Local $strComputer = @ComputerName ; "." "localhost"

Local $scheduledprog = @SystemDir & "\file.exe"
Local $time = @HOUR & @MIN   ; 24hr Time: 1:20PM
Local $tzo = "000"   ; Timezone: EST (5 * 60)

$objWMIService = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\" & $strComputer & "\root\cimv2")
$objShare = $objWMIService.Get("Win32_ScheduledJob")
$objInParam = $objShare.Methods_("Create").inParameters.SpawnInstance_()
$objInParam.Properties_.Item("Command") = $scheduledprog
$objInParam.Properties_.Item("DaysOfMonth") =  "" ; only for scheduling repeat events
$objInParam.Properties_.Item("DaysOfWeek") = ""   ; only for scheduling repeat events
$objInParam.Properties_.Item("InteractWithDesktop") = False ; False = Run process as System
$objInParam.Properties_.Item("RunRepeatedly") =  False     ; False = Run one time only
$objInParam.Properties_.Item("StartTime") =  "********" & $time &"00.000000+" & $tzo
                                            ; YYYYMMDDHHMMSS.MMMMMM-/+TZO - cant use Year/Month/Day or Seconds
$objOutParams = $objWMIService.ExecMethod("Win32_ScheduledJob", "Create", $objInParam)
ConsoleWrite("Out Parameters: " & @CRLF)
ConsoleWrite("JobId: " & $objOutParams.JobId & @CRLF)
ConsoleWrite("ReturnValue: " & $objOutParams.ReturnValue & @CRLF)

Func MyErrFunc()
   Local $HexNumber = Hex($oMyError.number,8)
   ConsoleWrite("Debug:  Intercepted COM Error:  Number = " & $HexNumber & _
        "  Windescription = " & $oMyError.windescription & @LF)
   SetError(1)
Endfunc

The problem is with Daylight Savings - $tzo variable.

The computers are all around the world and Win32_ScheduledJob adds it according to GMT.

I need it to be able to run x minutes after the scheduled task has been added.

I got it working on my computer by setting $tzo according to my time zone, but i have no idea how to make it run to not depend on that.

Can you please help me?

Thank you.

Edited by LapidusCreatorium

Share this post


Link to post
Share on other sites
PsaltyDS

Hello,

I am new to AutoIT, and don't know much about it.

So I am asking your help.

I am trying to schedule an application execution after a few minutes or hours after the scheduled task was added.

I use this code.

I have modified it a little to take current computer time:

Local $oMyError = ObjEvent("AutoIt.Error", "MyErrFunc")
Local $objWMIService, $objShare, $objInParam, $objOutParams
Local $strComputer = @ComputerName ; "." "localhost"

Local $scheduledprog = @SystemDir & "\file.exe"
Local $time = @HOUR & @MIN   ; 24hr Time: 1:20PM
Local $tzo = "000"   ; Timezone: EST (5 * 60)

$objWMIService = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\" & $strComputer & "\root\cimv2")
$objShare = $objWMIService.Get("Win32_ScheduledJob")
$objInParam = $objShare.Methods_("Create").inParameters.SpawnInstance_()
$objInParam.Properties_.Item("Command") = $scheduledprog
$objInParam.Properties_.Item("DaysOfMonth") =  "" ; only for scheduling repeat events
$objInParam.Properties_.Item("DaysOfWeek") = ""   ; only for scheduling repeat events
$objInParam.Properties_.Item("InteractWithDesktop") = False ; False = Run process as System
$objInParam.Properties_.Item("RunRepeatedly") =  False     ; False = Run one time only
$objInParam.Properties_.Item("StartTime") =  "********" & $time &"00.000000+" & $tzo
                                            ; YYYYMMDDHHMMSS.MMMMMM-/+TZO - cant use Year/Month/Day or Seconds
$objOutParams = $objWMIService.ExecMethod("Win32_ScheduledJob", "Create", $objInParam)
ConsoleWrite("Out Parameters: " & @CRLF)
ConsoleWrite("JobId: " & $objOutParams.JobId & @CRLF)
ConsoleWrite("ReturnValue: " & $objOutParams.ReturnValue & @CRLF)

Func MyErrFunc()
   Local $HexNumber = Hex($oMyError.number,8)
   ConsoleWrite("Debug:  Intercepted COM Error:  Number = " & $HexNumber & _
        "  Windescription = " & $oMyError.windescription & @LF)
   SetError(1)
Endfunc

The problem is with Daylight Savings - $tzo variable.

The computers are all around the world and Win32_ScheduledJob adds it according to GMT.

I need it to be able to run x minutes after the scheduled task has been added.

I got it working on my computer by setting $tzo according to my time zone, but i have no idea how to make it run to not depend on that.

Can you please help me?

Thank you.

Get the TZ offset and do the math:
#Include <Date.au3>
#include <Array.au3>; Only for _ArrayDisplay()

$avTZ = _Date_Time_GetTimeZoneInformation()
_ArrayDisplay($avTZ, "$avTZ")

MsgBox(64, "TZ Offset", "Your offset from GMT is: " & $avTZ[1] & " minutes")

:)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites
LapidusCreatorium

Get the TZ offset and do the math:

#Include <Date.au3>
#include <Array.au3>; Only for _ArrayDisplay()

$avTZ = _Date_Time_GetTimeZoneInformation()
_ArrayDisplay($avTZ, "$avTZ")

MsgBox(64, "TZ Offset", "Your offset from GMT is: " & $avTZ[1] & " minutes")

:)

OH. That simple it was :P

Thanks a lot. :P

Share this post


Link to post
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
Sign in to follow this  

×