#include-once ; #FUNCTION# ==================================================================================================================== ; Name...........: _TS_TaskPropertiesGet ; Description ...: Lists all or specified properties of a Task or Task Definition and returns an array or string or writes the properties to the console. ; Syntax.........: _TS_TaskPropertiesGet($oService, $vTask[, $iFormat = 1[, $bIgnoreNoValues = False[, $sQuerySection = ""[, $sQueryProperties = ""]]]]) ; Parameters ....: $oService - Task Scheduler Service object as returned by _TS_Open ; $vTask - Path and name or object of the Registered Task to process or a Task Definition object ; $iFormat - Format of the output. Can be one of the following values ; |1 - User friendly format (default). Please see Remarks ; |2 - Format you can use as input to _TS_TaskPropertiesSet (just the content of the array) ; |3 - Format you can use as input to _TS_TaskPropertiesSet (full AutoIt syntax to define the array - without XML and written to the console) ; $bIgnoreNoValues - Optional: If set to True properties without a value do not get returned (default = False) ; $sQuerySection - Optional: Name of the Scheduler object to retrieve the properties from. If set to "" all objects will be retrieved (default = "") ; $sQueryProperties - Optional: Comma separated list of properties to retrieve from $sSection. If set to "" all properties will be retrieved (default = "") ; Return values .: Success - For $iFormat=1 or 2: Zero based two-dimensional array with the following information ; | 0 - Section related to a COM object ; | 1 - Property name ; | 2 - Property value ; | 3 - Comment ; Success - For $iFormat=3: Writes the AutoIt array definition to the console ; Failure - Returns "" and sets @error ; |1901 - Error returned by _TS_TaskGet. @extended is set to the COM error code. Most probably the Task could not be found ; Author ........: water ; Modified.......: ; Remarks .......: For $iFormat = 1 if you only request a single property you will get a string holding the value of the property. Else you get an array as described above. ; Related .......: ; Link ..........: ; Example .......: Yes ; =============================================================================================================================== Func _TS_TaskPropertiesGet($oTaskService, $vTask, $iFormat = Default, $bIgnoreNoValues = Default, $sQuerySection = Default, $sQueryProperties = Default) Local $oTask, $sTaskState, $sObjectType Local $oTaskDefinition, $cActions, $oTaskAction Local $oPrincipal, $oRegistrationInfo, $oTaskSettings, $oIdleSettings, $oTaskNetworkSettings Local $cTaskTriggers, $oTaskTrigger, $oTaskRepitition, $cAttachments, $cHeaderfields Local $iIndex = 0, $sSection If $iFormat = Default Then $iFormat = 1 If $bIgnoreNoValues = Default Then $bIgnoreNoValues = False If $sQuerySection = Default Then $sQuerySection = "" If $sQueryProperties = Default Then $sQueryProperties = "" If $iFormat = 1 Then Local $aProperties[1000][4] Else Local $aProperties[1000] EndIf If IsObj($vTask) Then $oTask = $vTask ; Dummy. Just to make sure $oTask is set. Else the function would crash for a Task Definition If ObjName($vTask) = "IRegisteredTask" Then ; Registered Task object $sObjectType = "Task" Else ; Task Definition object $oTaskDefinition = $vTask $sObjectType = "Task Definition" EndIf Else $oTask = _TS_TaskGet($oTaskService, $vTask) If @error Then Return SetError(1901, @error, "") $sObjectType = "Task" EndIf With $oTask If $sObjectType = "Task" Then $sSection = "TASK" __TS_PropertyGetWrite($aProperties, $iIndex, $sSection, $sQuerySection, $sQueryProperties, $iFormat, $bIgnoreNoValues, "Name", .Name) __TS_PropertyGetWrite($aProperties, $iIndex, $sSection, $sQuerySection, $sQueryProperties, $iFormat, $bIgnoreNoValues, "Enabled", .Enabled) __TS_PropertyGetWrite($aProperties, $iIndex, $sSection, $sQuerySection, $sQueryProperties, $iFormat, $bIgnoreNoValues, "LastRunTime", .LastRunTime) __TS_PropertyGetWrite($aProperties, $iIndex, $sSection, $sQuerySection, $sQueryProperties, $iFormat, $bIgnoreNoValues, "LastTaskResult", .LastTaskResult) __TS_PropertyGetWrite($aProperties, $iIndex, $sSection, $sQuerySection, $sQueryProperties, $iFormat, $bIgnoreNoValues, "NextRunTime", .NextRunTime) __TS_PropertyGetWrite($aProperties, $iIndex, $sSection, $sQuerySection, $sQueryProperties, $iFormat, $bIgnoreNoValues, "NumberOfMissedRuns", .NumberOfMissedRuns) __TS_PropertyGetWrite($aProperties, $iIndex, $sSection, $sQuerySection, $sQueryProperties, $iFormat, $bIgnoreNoValues, "Path", .Path) Switch (.State) Case $TASK_STATE_UNKNOWN $sTaskState = "Unknown" Case $TASK_STATE_DISABLED $sTaskState = "Disabled" Case $TASK_STATE_QUEUED $sTaskState = "Queued" Case $TASK_STATE_QUEUED $sTaskState = "Ready" Case $TASK_STATE_RUNNING $sTaskState = "Running" EndSwitch __TS_PropertyGetWrite($aProperties, $iIndex, $sSection, $sQuerySection, $sQueryProperties, $iFormat, $bIgnoreNoValues, "State", .State, $sTaskState) If $iFormat <> 3 Then __TS_PropertyGetWrite($aProperties, $iIndex, $sSection, $sQuerySection, $sQueryProperties, $iFormat, $bIgnoreNoValues, "XML", .XML) $oTaskDefinition = .Definition EndIf $sSection = "DEFINITION" With $oTaskDefinition __TS_PropertyGetWrite($aProperties, $iIndex, $sSection, $sQuerySection, $sQueryProperties, $iFormat, $bIgnoreNoValues, "Data", .Data) $cActions = $oTaskDefinition.Actions If IsObj($cActions) Then For $oTaskAction In $cActions With $oTaskAction $sSection = "ACTIONS" __TS_PropertyGetWrite($aProperties, $iIndex, $sSection, $sQuerySection, $sQueryProperties, $iFormat, $bIgnoreNoValues, "ID", .Id) Switch (.Type) Case $TASK_ACTION_EXEC __TS_PropertyGetWrite($aProperties, $iIndex, $sSection, $sQuerySection, $sQueryProperties, $iFormat, $bIgnoreNoValues, "Type", .Type, "Execute / Command Line Operation") __TS_PropertyGetWrite($aProperties, $iIndex, $sSection, $sQuerySection, $sQueryProperties, $iFormat, $bIgnoreNoValues, "Arguments", .Arguments) __TS_PropertyGetWrite($aProperties, $iIndex, $sSection, $sQuerySection, $sQueryProperties, $iFormat, $bIgnoreNoValues, "Path", .Path) __TS_PropertyGetWrite($aProperties, $iIndex, $sSection, $sQuerySection, $sQueryProperties, $iFormat, $bIgnoreNoValues, "WorkingDirectory", .WorkingDirectory) Case $TASK_ACTION_COM_HANDLER __TS_PropertyGetWrite($aProperties, $iIndex, $sSection, $sQuerySection, $sQueryProperties, $iFormat, $bIgnoreNoValues, "Type", .Type, "Handler") __TS_PropertyGetWrite($aProperties, $iIndex, $sSection, $sQuerySection, $sQueryProperties, $iFormat, $bIgnoreNoValues, "ClassId", .ClassId) __TS_PropertyGetWrite($aProperties, $iIndex, $sSection, $sQuerySection, $sQueryProperties, $iFormat, $bIgnoreNoValues, "Data", .Data) Case $TASK_ACTION_SEND_EMAIL __TS_PropertyGetWrite($aProperties, $iIndex, $sSection, $sQuerySection, $sQueryProperties, $iFormat, $bIgnoreNoValues, "Type", .Type, "Email Message") __TS_PropertyGetWrite($aProperties, $iIndex, $sSection, $sQuerySection, $sQueryProperties, $iFormat, $bIgnoreNoValues, "From", .From) __TS_PropertyGetWrite($aProperties, $iIndex, $sSection, $sQuerySection, $sQueryProperties, $iFormat, $bIgnoreNoValues, "ReplyTo", .ReplyTo) __TS_PropertyGetWrite($aProperties, $iIndex, $sSection, $sQuerySection, $sQueryProperties, $iFormat, $bIgnoreNoValues, "To", .To) __TS_PropertyGetWrite($aProperties, $iIndex, $sSection, $sQuerySection, $sQueryProperties, $iFormat, $bIgnoreNoValues, "Cc", .Cc) __TS_PropertyGetWrite($aProperties, $iIndex, $sSection, $sQuerySection, $sQueryProperties, $iFormat, $bIgnoreNoValues, "Bcc", .Bcc) __TS_PropertyGetWrite($aProperties, $iIndex, $sSection, $sQuerySection, $sQueryProperties, $iFormat, $bIgnoreNoValues, "Subject", .Subject) __TS_PropertyGetWrite($aProperties, $iIndex, $sSection, $sQuerySection, $sQueryProperties, $iFormat, $bIgnoreNoValues, "Body", .Body) __TS_PropertyGetWrite($aProperties, $iIndex, $sSection, $sQuerySection, $sQueryProperties, $iFormat, $bIgnoreNoValues, "Server", .Server) ; ==> CHECK $cAttachments = .Attachments $sSection = "ATTACHMENTS" For $sAttachment In $cAttachments __TS_PropertyGetWrite($aProperties, $iIndex, $sSection, $sQuerySection, $sQueryProperties, $iFormat, $bIgnoreNoValues, "Attachment", $sAttachment) Next $cHeaderfields = .HeaderFields $sSection = "HEADERFIELDS" For $oHeaderPair In $cHeaderfields __TS_PropertyGetWrite($aProperties, $iIndex, $sSection, $sQuerySection, $sQueryProperties, $iFormat, $bIgnoreNoValues, "HeaderName|Value", $oHeaderPair.Name & "|" & $oHeaderPair.Value) Next Case $TASK_ACTION_SHOW_MESSAGE __TS_PropertyGetWrite($aProperties, $iIndex, $sSection, $sQuerySection, $sQueryProperties, $iFormat, $bIgnoreNoValues, "Type", .Type, "Message Box") __TS_PropertyGetWrite($aProperties, $iIndex, $sSection, $sQuerySection, $sQueryProperties, $iFormat, $bIgnoreNoValues, "Title", .Title) __TS_PropertyGetWrite($aProperties, $iIndex, $sSection, $sQuerySection, $sQueryProperties, $iFormat, $bIgnoreNoValues, "MessageBody", .MessageBody) EndSwitch EndWith ; oTaskAction Next ; objTaskAction EndIf $oPrincipal = .Principal If IsObj($oPrincipal) Then $sSection = "PRINCIPAL" With $oPrincipal __TS_PropertyGetWrite($aProperties, $iIndex, $sSection, $sQuerySection, $sQueryProperties, $iFormat, $bIgnoreNoValues, "ID", .Id) __TS_PropertyGetWrite($aProperties, $iIndex, $sSection, $sQuerySection, $sQueryProperties, $iFormat, $bIgnoreNoValues, "DisplayName", .DisplayName) __TS_PropertyGetWrite($aProperties, $iIndex, $sSection, $sQuerySection, $sQueryProperties, $iFormat, $bIgnoreNoValues, "GroupId", .GroupId) Switch (.LogonType) Case $TASK_LOGON_NONE __TS_PropertyGetWrite($aProperties, $iIndex, $sSection, $sQuerySection, $sQueryProperties, $iFormat, $bIgnoreNoValues, "LogonType", .LogonType, "None") Case $TASK_LOGON_PASSWORD __TS_PropertyGetWrite($aProperties, $iIndex, $sSection, $sQuerySection, $sQueryProperties, $iFormat, $bIgnoreNoValues, "LogonType", .LogonType, "Password") Case $TASK_LOGON_S4U __TS_PropertyGetWrite($aProperties, $iIndex, $sSection, $sQuerySection, $sQueryProperties, $iFormat, $bIgnoreNoValues, "LogonType", .LogonType, "Service 4 Users") Case $TASK_LOGON_INTERACTIVE_TOKEN __TS_PropertyGetWrite($aProperties, $iIndex, $sSection, $sQuerySection, $sQueryProperties, $iFormat, $bIgnoreNoValues, "LogonType", .LogonType, "Interactive (User must be logged in)") Case $TASK_LOGON_GROUP __TS_PropertyGetWrite($aProperties, $iIndex, $sSection, $sQuerySection, $sQueryProperties, $iFormat, $bIgnoreNoValues, "LogonType", .LogonType, "Group") Case $TASK_LOGON_SERVICE_ACCOUNT __TS_PropertyGetWrite($aProperties, $iIndex, $sSection, $sQuerySection, $sQueryProperties, $iFormat, $bIgnoreNoValues, "LogonType", .LogonType, "Local $Service/System or Network Service") Case $TASK_LOGON_INTERACTIVE_TOKEN_OR_PASSWORD __TS_PropertyGetWrite($aProperties, $iIndex, $sSection, $sQuerySection, $sQueryProperties, $iFormat, $bIgnoreNoValues, "LogonType", .LogonType, "Interactive Token then Try Password") EndSwitch Switch (.RunLevel) Case $TASK_RUNLEVEL_LUA __TS_PropertyGetWrite($aProperties, $iIndex, $sSection, $sQuerySection, $sQueryProperties, $iFormat, $bIgnoreNoValues, "RunLevel", .RunLevel, "Least Privileges (LUA)") Case $TASK_RUNLEVEL_HIGHEST __TS_PropertyGetWrite($aProperties, $iIndex, $sSection, $sQuerySection, $sQueryProperties, $iFormat, $bIgnoreNoValues, "RunLevel", .RunLevel, "Highest Privileges") EndSwitch __TS_PropertyGetWrite($aProperties, $iIndex, $sSection, $sQuerySection, $sQueryProperties, $iFormat, $bIgnoreNoValues, "UserId", .UserId) EndWith ; oPrincipal EndIf $oRegistrationInfo = .RegistrationInfo If IsObj($oRegistrationInfo) Then $sSection = "REGISTRATIONINFO" With $oRegistrationInfo __TS_PropertyGetWrite($aProperties, $iIndex, $sSection, $sQuerySection, $sQueryProperties, $iFormat, $bIgnoreNoValues, "Author", .Author) __TS_PropertyGetWrite($aProperties, $iIndex, $sSection, $sQuerySection, $sQueryProperties, $iFormat, $bIgnoreNoValues, "Date", .Date) __TS_PropertyGetWrite($aProperties, $iIndex, $sSection, $sQuerySection, $sQueryProperties, $iFormat, $bIgnoreNoValues, "Description", .Description) __TS_PropertyGetWrite($aProperties, $iIndex, $sSection, $sQuerySection, $sQueryProperties, $iFormat, $bIgnoreNoValues, "Date", .Date) __TS_PropertyGetWrite($aProperties, $iIndex, $sSection, $sQuerySection, $sQueryProperties, $iFormat, $bIgnoreNoValues, "Documentation", .Documentation) __TS_PropertyGetWrite($aProperties, $iIndex, $sSection, $sQuerySection, $sQueryProperties, $iFormat, $bIgnoreNoValues, "SecurityDescriptor", .SecurityDescriptor) __TS_PropertyGetWrite($aProperties, $iIndex, $sSection, $sQuerySection, $sQueryProperties, $iFormat, $bIgnoreNoValues, "Source", .Source) __TS_PropertyGetWrite($aProperties, $iIndex, $sSection, $sQuerySection, $sQueryProperties, $iFormat, $bIgnoreNoValues, "URI", .URI) __TS_PropertyGetWrite($aProperties, $iIndex, $sSection, $sQuerySection, $sQueryProperties, $iFormat, $bIgnoreNoValues, "Version", .Version) EndWith ; oRegistrationInfo EndIf $oTaskSettings = .Settings If IsObj($oTaskSettings) Then $sSection = "SETTINGS" With $oTaskSettings __TS_PropertyGetWrite($aProperties, $iIndex, $sSection, $sQuerySection, $sQueryProperties, $iFormat, $bIgnoreNoValues, "AllowDemandStart", .AllowDemandStart) __TS_PropertyGetWrite($aProperties, $iIndex, $sSection, $sQuerySection, $sQueryProperties, $iFormat, $bIgnoreNoValues, "AllowHardTerminate", .AllowHardTerminate) Switch (.Compatibility) Case $TASK_COMPATIBILITY_AT __TS_PropertyGetWrite($aProperties, $iIndex, $sSection, $sQuerySection, $sQueryProperties, $iFormat, $bIgnoreNoValues, "Compatibility", .Compatibility, "compatible with the AT command") Case $TASK_COMPATIBILITY_V1 __TS_PropertyGetWrite($aProperties, $iIndex, $sSection, $sQuerySection, $sQueryProperties, $iFormat, $bIgnoreNoValues, "Compatibility", .Compatibility, "compatible with Task Scheduler 1.0") Case $TASK_COMPATIBILITY_V2 __TS_PropertyGetWrite($aProperties, $iIndex, $sSection, $sQuerySection, $sQueryProperties, $iFormat, $bIgnoreNoValues, "Compatibility", .Compatibility, "compatible with Task Scheduler 2.0 (Windows Vista / Windows 2008)") Case 3 ; Not Documented __TS_PropertyGetWrite($aProperties, $iIndex, $sSection, $sQuerySection, $sQueryProperties, $iFormat, $bIgnoreNoValues, "Compatibility", .Compatibility, "compatible with Task Scheduler 2.0 (Windows 7 / Windows 2008 R2)") EndSwitch __TS_PropertyGetWrite($aProperties, $iIndex, $sSection, $sQuerySection, $sQueryProperties, $iFormat, $bIgnoreNoValues, "DeleteExpiredTaskAfter", .DeleteExpiredTaskAfter) __TS_PropertyGetWrite($aProperties, $iIndex, $sSection, $sQuerySection, $sQueryProperties, $iFormat, $bIgnoreNoValues, "DisallowStartIfOnBatteries", .DisallowStartIfOnBatteries) __TS_PropertyGetWrite($aProperties, $iIndex, $sSection, $sQuerySection, $sQueryProperties, $iFormat, $bIgnoreNoValues, "Enabled", .Enabled) __TS_PropertyGetWrite($aProperties, $iIndex, $sSection, $sQuerySection, $sQueryProperties, $iFormat, $bIgnoreNoValues, "ExecutionTimeLimit", .ExecutionTimeLimit) __TS_PropertyGetWrite($aProperties, $iIndex, $sSection, $sQuerySection, $sQueryProperties, $iFormat, $bIgnoreNoValues, "Hidden", .Hidden) Switch (.MultipleInstances) Case $TASK_INSTANCES_PARALLEL __TS_PropertyGetWrite($aProperties, $iIndex, $sSection, $sQuerySection, $sQueryProperties, $iFormat, $bIgnoreNoValues, "MultipleInstances", .MultipleInstances, "Run in parallel") Case $TASK_INSTANCES_QUEUE __TS_PropertyGetWrite($aProperties, $iIndex, $sSection, $sQuerySection, $sQueryProperties, $iFormat, $bIgnoreNoValues, "MultipleInstances", .MultipleInstances, "Add to queue") Case $TASK_INSTANCES_IGNORE_NEW __TS_PropertyGetWrite($aProperties, $iIndex, $sSection, $sQuerySection, $sQueryProperties, $iFormat, $bIgnoreNoValues, "MultipleInstances", .MultipleInstances, "Ignore new") Case $TASK_INSTANCES_STOP_EXISTING __TS_PropertyGetWrite($aProperties, $iIndex, $sSection, $sQuerySection, $sQueryProperties, $iFormat, $bIgnoreNoValues, "MultipleInstances", .MultipleInstances, "Stop existing task") EndSwitch __TS_PropertyGetWrite($aProperties, $iIndex, $sSection, $sQuerySection, $sQueryProperties, $iFormat, $bIgnoreNoValues, "Priority", .Priority, "(0=High / 10=Low)") __TS_PropertyGetWrite($aProperties, $iIndex, $sSection, $sQuerySection, $sQueryProperties, $iFormat, $bIgnoreNoValues, "RestartCount", .RestartCount) __TS_PropertyGetWrite($aProperties, $iIndex, $sSection, $sQuerySection, $sQueryProperties, $iFormat, $bIgnoreNoValues, "RestartInterval", .RestartInterval) __TS_PropertyGetWrite($aProperties, $iIndex, $sSection, $sQuerySection, $sQueryProperties, $iFormat, $bIgnoreNoValues, "RunOnlyIfIdle", .RunOnlyIfIdle) __TS_PropertyGetWrite($aProperties, $iIndex, $sSection, $sQuerySection, $sQueryProperties, $iFormat, $bIgnoreNoValues, "RunOnlyIfNetworkAvailable", .RunOnlyIfNetworkAvailable) __TS_PropertyGetWrite($aProperties, $iIndex, $sSection, $sQuerySection, $sQueryProperties, $iFormat, $bIgnoreNoValues, "StartWhenAvailable", .StartWhenAvailable) __TS_PropertyGetWrite($aProperties, $iIndex, $sSection, $sQuerySection, $sQueryProperties, $iFormat, $bIgnoreNoValues, "StopIfGoingOnBatteries", .StopIfGoingOnBatteries) __TS_PropertyGetWrite($aProperties, $iIndex, $sSection, $sQuerySection, $sQueryProperties, $iFormat, $bIgnoreNoValues, "WakeToRun", .WakeToRun) $oIdleSettings = .IdleSettings $sSection = "IDLESETTINGS" With $oIdleSettings __TS_PropertyGetWrite($aProperties, $iIndex, $sSection, $sQuerySection, $sQueryProperties, $iFormat, $bIgnoreNoValues, "IdleDuration", .IdleDuration) __TS_PropertyGetWrite($aProperties, $iIndex, $sSection, $sQuerySection, $sQueryProperties, $iFormat, $bIgnoreNoValues, "RestartOnIdle", .RestartOnIdle) __TS_PropertyGetWrite($aProperties, $iIndex, $sSection, $sQuerySection, $sQueryProperties, $iFormat, $bIgnoreNoValues, "StopOnIdleEnd", .StopOnIdleEnd) __TS_PropertyGetWrite($aProperties, $iIndex, $sSection, $sQuerySection, $sQueryProperties, $iFormat, $bIgnoreNoValues, "WaitTimeout", .WaitTimeout) EndWith ; oIdleSettings $oTaskNetworkSettings = .NetworkSettings $sSection = "NETWORKSETTINGS" With $oTaskNetworkSettings __TS_PropertyGetWrite($aProperties, $iIndex, $sSection, $sQuerySection, $sQueryProperties, $iFormat, $bIgnoreNoValues, "ID", .Id) __TS_PropertyGetWrite($aProperties, $iIndex, $sSection, $sQuerySection, $sQueryProperties, $iFormat, $bIgnoreNoValues, "Name", .Name) EndWith ; oTaskNetworkSettings EndWith ; oTaskSettings EndIf $cTaskTriggers = .Triggers If IsObj($cTaskTriggers) Then $sSection = "TRIGGERS" For $oTaskTrigger In $cTaskTriggers With $oTaskTrigger __TS_PropertyGetWrite($aProperties, $iIndex, $sSection, $sQuerySection, $sQueryProperties, $iFormat, $bIgnoreNoValues, "Enabled", .Enabled) __TS_PropertyGetWrite($aProperties, $iIndex, $sSection, $sQuerySection, $sQueryProperties, $iFormat, $bIgnoreNoValues, "Id", .Id) __TS_PropertyGetWrite($aProperties, $iIndex, $sSection, $sQuerySection, $sQueryProperties, $iFormat, $bIgnoreNoValues, "StartBoundary", .StartBoundary) __TS_PropertyGetWrite($aProperties, $iIndex, $sSection, $sQuerySection, $sQueryProperties, $iFormat, $bIgnoreNoValues, "EndBoundary", .EndBoundary) __TS_PropertyGetWrite($aProperties, $iIndex, $sSection, $sQuerySection, $sQueryProperties, $iFormat, $bIgnoreNoValues, "ExecutionTimeLimit", .ExecutionTimeLimit) Switch (.Type) Case $TASK_TRIGGER_EVENT __TS_PropertyGetWrite($aProperties, $iIndex, $sSection, $sQuerySection, $sQueryProperties, $iFormat, $bIgnoreNoValues, "Type", .Type, " Event") __TS_PropertyGetWrite($aProperties, $iIndex, $sSection, $sQuerySection, $sQueryProperties, $iFormat, $bIgnoreNoValues, "Delay", .Delay) __TS_PropertyGetWrite($aProperties, $iIndex, $sSection, $sQuerySection, $sQueryProperties, $iFormat, $bIgnoreNoValues, "Subscription", .Subscription) Case $TASK_TRIGGER_TIME __TS_PropertyGetWrite($aProperties, $iIndex, $sSection, $sQuerySection, $sQueryProperties, $iFormat, $bIgnoreNoValues, "Type", .Type, " Time") Case $TASK_TRIGGER_DAILY __TS_PropertyGetWrite($aProperties, $iIndex, $sSection, $sQuerySection, $sQueryProperties, $iFormat, $bIgnoreNoValues, "Type", .Type, " Daily") __TS_PropertyGetWrite($aProperties, $iIndex, $sSection, $sQuerySection, $sQueryProperties, $iFormat, $bIgnoreNoValues, "DaysInterval", .DaysInterval) Case $TASK_TRIGGER_WEEKLY __TS_PropertyGetWrite($aProperties, $iIndex, $sSection, $sQuerySection, $sQueryProperties, $iFormat, $bIgnoreNoValues, "Type", .Type, " Weekly") __TS_PropertyGetWrite($aProperties, $iIndex, $sSection, $sQuerySection, $sQueryProperties, $iFormat, $bIgnoreNoValues, "WeeksInterval", .WeeksInterval) __TS_PropertyGetWrite($aProperties, $iIndex, $sSection, $sQuerySection, $sQueryProperties, $iFormat, $bIgnoreNoValues, "DaysOfWeek", .DaysOfWeek, "=" & __TS_ConvertDaysOfWeek(.DaysOfWeek)) Case $TASK_TRIGGER_MONTHLY __TS_PropertyGetWrite($aProperties, $iIndex, $sSection, $sQuerySection, $sQueryProperties, $iFormat, $bIgnoreNoValues, "Type", .Type, "Monthly") __TS_PropertyGetWrite($aProperties, $iIndex, $sSection, $sQuerySection, $sQueryProperties, $iFormat, $bIgnoreNoValues, "DaysOfMonth", .DaysOfMonth, "=" & __TS_ConvertDaysOfMonth(.DaysOfMonth)) __TS_PropertyGetWrite($aProperties, $iIndex, $sSection, $sQuerySection, $sQueryProperties, $iFormat, $bIgnoreNoValues, "MonthsOfYear", .MonthsOfYear, "=" & __TS_ConvertMonthsOfYear(.MonthsOfYear)) __TS_PropertyGetWrite($aProperties, $iIndex, $sSection, $sQuerySection, $sQueryProperties, $iFormat, $bIgnoreNoValues, "RandomDelay", .RandomDelay) __TS_PropertyGetWrite($aProperties, $iIndex, $sSection, $sQuerySection, $sQueryProperties, $iFormat, $bIgnoreNoValues, "RunOnLastDayOfMonth", .RunOnLastDayOfMonth) Case $TASK_TRIGGER_MONTHLYDOW __TS_PropertyGetWrite($aProperties, $iIndex, $sSection, $sQuerySection, $sQueryProperties, $iFormat, $bIgnoreNoValues, "Type", .Type, "Monthly on Specific Day") __TS_PropertyGetWrite($aProperties, $iIndex, $sSection, $sQuerySection, $sQueryProperties, $iFormat, $bIgnoreNoValues, "DaysOfWeek", .DaysOfWeek, "=" & __TS_ConvertDaysOfWeek(.DaysOfWeek)) __TS_PropertyGetWrite($aProperties, $iIndex, $sSection, $sQuerySection, $sQueryProperties, $iFormat, $bIgnoreNoValues, "MonthsOfYear", .MonthsOfYear, "=" & __TS_ConvertMonthsOfYear(.MonthsOfYear)) __TS_PropertyGetWrite($aProperties, $iIndex, $sSection, $sQuerySection, $sQueryProperties, $iFormat, $bIgnoreNoValues, "RandomDelay", .RandomDelay) __TS_PropertyGetWrite($aProperties, $iIndex, $sSection, $sQuerySection, $sQueryProperties, $iFormat, $bIgnoreNoValues, "RunOnLastWeekOfMonth", .RunOnLastWeekOfMonth) __TS_PropertyGetWrite($aProperties, $iIndex, $sSection, $sQuerySection, $sQueryProperties, $iFormat, $bIgnoreNoValues, "WeeksOfMonth", .WeeksOfMonth, "=" & __TS_ConvertWeeksOfMonth(.WeeksOfMonth)) Case $TASK_TRIGGER_IDLE __TS_PropertyGetWrite($aProperties, $iIndex, $sSection, $sQuerySection, $sQueryProperties, $iFormat, $bIgnoreNoValues, "Type", .Type, "When computer is idle") Case $TASK_TRIGGER_REGISTRATION __TS_PropertyGetWrite($aProperties, $iIndex, $sSection, $sQuerySection, $sQueryProperties, $iFormat, $bIgnoreNoValues, "Type", .Type, "When task is registered") __TS_PropertyGetWrite($aProperties, $iIndex, $sSection, $sQuerySection, $sQueryProperties, $iFormat, $bIgnoreNoValues, "Delay", .Delay) Case $TASK_TRIGGER_BOOT __TS_PropertyGetWrite($aProperties, $iIndex, $sSection, $sQuerySection, $sQueryProperties, $iFormat, $bIgnoreNoValues, "Type", .Type, "Boot") __TS_PropertyGetWrite($aProperties, $iIndex, $sSection, $sQuerySection, $sQueryProperties, $iFormat, $bIgnoreNoValues, "Delay", .Delay) Case $TASK_TRIGGER_LOGON __TS_PropertyGetWrite($aProperties, $iIndex, $sSection, $sQuerySection, $sQueryProperties, $iFormat, $bIgnoreNoValues, "Type", .Type, "Logon") __TS_PropertyGetWrite($aProperties, $iIndex, $sSection, $sQuerySection, $sQueryProperties, $iFormat, $bIgnoreNoValues, "Delay", .Delay) __TS_PropertyGetWrite($aProperties, $iIndex, $sSection, $sQuerySection, $sQueryProperties, $iFormat, $bIgnoreNoValues, "UserId", .UserId) Case $TASK_TRIGGER_SESSION_STATE_CHANGE __TS_PropertyGetWrite($aProperties, $iIndex, $sSection, $sQuerySection, $sQueryProperties, $iFormat, $bIgnoreNoValues, "Type", .Type, "Session State Change") Switch (.StateChange) Case 0 __TS_PropertyGetWrite($aProperties, $iIndex, $sSection, $sQuerySection, $sQueryProperties, $iFormat, $bIgnoreNoValues, "StateChange", .StateChange, "None") Case $TASK_CONSOLE_CONNECT __TS_PropertyGetWrite($aProperties, $iIndex, $sSection, $sQuerySection, $sQueryProperties, $iFormat, $bIgnoreNoValues, "StateChange", .StateChange, "User session connect to local computer") Case $TASK_CONSOLE_DISCONNECT __TS_PropertyGetWrite($aProperties, $iIndex, $sSection, $sQuerySection, $sQueryProperties, $iFormat, $bIgnoreNoValues, "StateChange", .StateChange, "User session disconnect from local computer") Case $TASK_REMOTE_CONNECT __TS_PropertyGetWrite($aProperties, $iIndex, $sSection, $sQuerySection, $sQueryProperties, $iFormat, $bIgnoreNoValues, "StateChange", .StateChange, "User session connect to remote computer") Case $TASK_REMOTE_DISCONNECT __TS_PropertyGetWrite($aProperties, $iIndex, $sSection, $sQuerySection, $sQueryProperties, $iFormat, $bIgnoreNoValues, "StateChange", .StateChange, "User session disconnect from remote computer") Case $TASK_SESSION_LOCK __TS_PropertyGetWrite($aProperties, $iIndex, $sSection, $sQuerySection, $sQueryProperties, $iFormat, $bIgnoreNoValues, "StateChange", .StateChange, "On workstation lock") Case $TASK_SESSION_UNLOCK __TS_PropertyGetWrite($aProperties, $iIndex, $sSection, $sQuerySection, $sQueryProperties, $iFormat, $bIgnoreNoValues, "StateChange", .StateChange, "On workstation unlock") EndSwitch __TS_PropertyGetWrite($aProperties, $iIndex, $sSection, $sQuerySection, $sQueryProperties, $iFormat, $bIgnoreNoValues, "Delay", .Delay) __TS_PropertyGetWrite($aProperties, $iIndex, $sSection, $sQuerySection, $sQueryProperties, $iFormat, $bIgnoreNoValues, "UserId", .UserId) EndSwitch $oTaskRepitition = .Repetition $sSection = "REPETITION" With $oTaskRepitition __TS_PropertyGetWrite($aProperties, $iIndex, $sSection, $sQuerySection, $sQueryProperties, $iFormat, $bIgnoreNoValues, "Duration", .Duration) __TS_PropertyGetWrite($aProperties, $iIndex, $sSection, $sQuerySection, $sQueryProperties, $iFormat, $bIgnoreNoValues, "Interval", .Interval) __TS_PropertyGetWrite($aProperties, $iIndex, $sSection, $sQuerySection, $sQueryProperties, $iFormat, $bIgnoreNoValues, "StopAtDurationEnd", .StopAtDurationEnd) EndWith ; oTaskRepitition EndWith ; oTaskTrigger Next ; oTaskTrigger EndIf EndWith ; oTaskDefinition EndWith ; oTask If $iFormat = 1 Then ReDim $aProperties[$iIndex][4] ; Return a string if just a single property has been queried If $sQueryProperties <> "" And StringInStr($sQueryProperties, ",") = 0 Then If $iIndex = 0 Then $aProperties = "" Else $aProperties = $aProperties[0][2] EndIf EndIf Else ReDim $aProperties[$iIndex] EndIf If $iFormat = 3 Then Local $iLastIndex = UBound($aProperties) - 1 ConsoleWrite("Global $aProperties[] = [ _" & @CRLF) For $i = 0 To $iLastIndex $aProperties[$i] = StringReplace($aProperties[$i], @LF, '" & @CRLF & "') If $i = $iLastIndex Then ConsoleWrite('"' & $aProperties[$i] & '" _' & @CRLF) Else ConsoleWrite('"' & $aProperties[$i] & '", _' & @CRLF) EndIf Next ConsoleWrite('"]' & @CRLF) Return 1 EndIf Return $aProperties EndFunc ;==>_TS_TaskPropertiesGet ; #FUNCTION# ==================================================================================================================== ; Name...........: _TS_TaskRegister ; Description ...: Register a Task created by _TS_TaskCreate in the specified Folder. ; Syntax.........: _TS_TaskRegister($oService, $sFolder, $sName, $oTaskDefinition, $sUserId = "", $sPassword = "", $iLogonType = Default, $bUpdateTask = False) ; Parameters ....: $oService - Task Scheduler Service object as returned by _TS_Open ; $sFolder - Folder where the Task should be created ; $sName - Name of the Task ; $oTaskDefinition - Task Definition object as created by _TS_TaskCreate and filled by _TS_TaskPropertiesSet ; $sUserId - Optional: The user credentials that are used to register the Task. If present, these credentials ; take priority over the credentials specified in the Task Definition object pointed to by the definition parameter ; $sPassword - Optional: The password for the UserId that is used to register the Task. When the TASK_LOGON_SERVICE_ACCOUNT logon type ; is used, the password must be an empty value such as NULL or "" ; $iLogonType - Optional: Can be any of the TASK_LOGON_TYPE constants enumeration. For the default please check Remarks. ; $bUpdateTask - Optional: Update existing task from Task Definition. ; Return values .: Success - Task object ; Failure - Returns 0 and sets @error: ; |2101 - Parameter $oService is not an object or not an ITaskService object ; |2102 - $sFolder does not exist or an error occurred in _TS_FolderExists. @extended is set to the COM error (if any) ; |2103 - $sName already exists (and not being updated) or an error occurred in _TS_TaskExists. @extended is set to the COM error (if any) ; |2104 - Parameter $oTaskDefinition is not an object or not an ITaskDefinition object ; |2105 - Error accessing $sFolder using _TS_FolderGet. @extended is set to the COM error ; |2106 - Error creating the Task. @extended is set to the COM error ; Author ........: water ; Modified.......: AdamUL ; Remarks .......: If the logon type has been set in the Principal sub-object then $TASK_LOGON_NONE is the default to not overwrite the existing setting. ; Else $TASK_LOGON_INTERACTIVE_TOKEN will be used as default. ; Related .......: ; Link ..........: ; Example .......: Yes ; =============================================================================================================================== Func _TS_TaskRegister($oService, $sFolder, $sName, $oTaskDefinition, $sUserId = Default, $sPassword = Default, $iLogonType = Default, $bUpdateTask = False) If $sUserId = Default Then $sUserId = "" If $sPassword = Default Then $sPassword = "" If $iLogonType = Default Then If $oTaskDefinition.Principal.LogonType <> 0 Then $iLogonType = $TASK_LOGON_NONE Else $iLogonType = $TASK_LOGON_INTERACTIVE_TOKEN EndIf EndIf If Not IsObj($oService) Or ObjName($oService) <> "ITaskService" Then Return SetError(2101, 0, 0) If Not _TS_FolderExists($oService, $sFolder) Then Return SetError(2102, @error, 0) If _TS_TaskExists($oService, $sFolder & "\" & $sName) And $bUpdateTask = False Then Return SetError(2103, @error, 0) ;<== Changed ;~ If _TS_TaskExists($oService, $sFolder & "\" & $sName) Then Return SetError(2103, @error, 0) If Not IsObj($oTaskDefinition) Or ObjName($oTaskDefinition) <> "ITaskDefinition" Then Return SetError(2104, 0, 0) ; Register (create) the Task Local $oFolder = _TS_FolderGet($oService, $sFolder) If @error Then Return SetError(2105, @error, 0) Local $oTask = $oFolder.RegisterTaskDefinition($sName, $oTaskDefinition, $TASK_CREATE_OR_UPDATE, $sUserId, $sPassword, $iLogonType) ;<== Changed ;~ Local $oTask = $oFolder.RegisterTaskDefinition($sName, $oTaskDefinition, $TASK_CREATE, $sUserId, $sPassword, $iLogonType) If @error Then Return SetError(2106, @error, 0) Return $oTask EndFunc ;==>_TS_TaskRegister ; #FUNCTION# ==================================================================================================================== ; Name...........: _TS_Wrapper_TaskRegister ; Description ...: Alias for _TS_TaskRegister: Register a Task in the specified Folder. ; Syntax.........: _TS_Wrapper_TaskRegister($oService, $sFolder, $sName, $oTaskDefinition, $sUserId = "", $sPassword = "", $iLogonType = Default) ; Parameters ....: Please see: _TS_TaskRegister ; Return values .: Please see: _TS_TaskRegister ; Author ........: water ; Modified.......: ; Remarks .......: Please see: _TS_TaskRegister ; Related .......: Please see: _TS_TaskRegister ; Link ..........: ; Example .......: Yes ; =============================================================================================================================== Func _TS_Wrapper_TaskRegister($oService, $sFolder, $sName, $oTaskDefinition, $sUserId = Default, $sPassword = Default, $iLogonType = Default) Local $vReturnValue = _TS_TaskRegister($oService, $sFolder, $sName, $oTaskDefinition, $sUserId, $sPassword, $iLogonType) Return SetError(@error, @extended, $vReturnValue) EndFunc ;==>_TS_Wrapper_TaskRegister ; #FUNCTION# ==================================================================================================================== ; Name...........: _TS_TaskUpdateRegister ; Description ...: Alias for _TS_TaskRegister: Update a Registered Task in the specified Folder. ; Syntax.........: _TS_TaskUpdateRegister($oService, $sFolder, $sName, $oTaskDefinition, $sUserId = "", $sPassword = "", $iLogonType = Default) ; Parameters ....: Please see: _TS_TaskRegister ; Return values .: Please see: _TS_TaskRegister ; Author ........: AdamUL ; Modified.......: ; Remarks .......: Please see: _TS_TaskRegister ; Related .......: Please see: _TS_TaskRegister ; Link ..........: ; Example .......: Yes ; =============================================================================================================================== Func _TS_TaskUpdateRegister($oService, $sFolder, $sName, $oTaskDefinition, $sUserId = Default, $sPassword = Default, $iLogonType = Default) Local $vReturnValue = _TS_TaskRegister($oService, $sFolder, $sName, $oTaskDefinition, $sUserId, $sPassword, $iLogonType, True) Return SetError(@error, @extended, $vReturnValue) EndFunc