Modify

Opened 5 years ago

Last modified 4 years ago

#3015 new Bug

Object Schedule.Service

Reported by: syperjazz@… Owned by:
Milestone: Component: AutoIt
Version: 3.3.13.20 Severity: None
Keywords: Schedule.Service GetTask Cc:

Description

I did not test all Beta versions. On 3.3.13.5 it is working. And on 3.3.13.19 and 3.3.13.20 it does not work.

Example code:

Func _TaskExists($taskname, $folder = "\");check if a Task exists

;If Not _TaskIsValidPlatfrom() Then Return SetError(2, 2, 0)
Local $oService, $oFolder
$oService = ObjCreate("Schedule.Service")
$oService.Connect()
$oFolder = $oService.GetFolder($folder)
If IsObj($oFolder) Then

$oTask = $oFolder.GetTask($taskname) ;here is the error with newer beta versions
If IsObj($oTask) Then

$oService = 0
Return 1

Else

$oService = 0
SetError(1)
Return 0

EndIf

Else

$oService = 0
SetError(1)
Return 0

EndIf

EndFunc

_TaskExists("test")

Attachments (0)

Change History (2)

comment:1 Changed 4 years ago by mLipok

https://msdn.microsoft.com/en-us/library/windows/desktop/aa381353(v=vs.85).aspx

Global $oMyErrorHandler = ObjEvent("AutoIt.Error", 'COMErrorHandler')

MsgBox(0, '', _TaskExists("test"))

Func _TaskExists($taskname, $folder = "\");check if a Task exists
	;If Not _TaskIsValidPlatfrom() Then Return SetError(2, 2, 0)
	Local $oService, $oFolder, $oTask, $oTasks
	$oService = ObjCreate("Schedule.Service")
	$oService.Connect()
	$oFolder = $oService.GetFolder($folder)
	Local $TASK_ENUM_HIDDEN = 1
	If IsObj($oFolder) Then
		$oTasks = $oFolder.GetTasks($TASK_ENUM_HIDDEN)
		If IsObj($oTasks) Then
			For $oTask In $oTasks
				ConsoleWrite('$oTask.name = ' & $oTask.name & @CRLF)
			Next
		EndIf

		$oTask = $oFolder.GetTask('\Adobe Acrobat Update Task') ;here is the error with newer beta versions
		If IsObj($oTask) Then
			$oService = 0
			Return 1
		Else
			$oService = 0
			SetError(1)
			Return 0
		EndIf
	Else
		$oService = 0
		SetError(1)
		Return 0
	EndIf
EndFunc   ;==>_TaskExists

Func COMErrorHandler($oError)
	ConsoleWrite(@ScriptName & " (" & $oError.scriptline & ") : ==> COM Error intercepted !" & @CRLF & _
			@TAB & "err.number is: " & @TAB & @TAB & "0x" & Hex($oError.number) & @CRLF & _
			@TAB & "err.windescription:" & @TAB & $oError.windescription & @CRLF & _
			@TAB & "err.description is: " & @TAB & $oError.description & @CRLF & _
			@TAB & "err.source is: " & @TAB & @TAB & $oError.source & @CRLF & _
			@TAB & "err.helpfile is: " & @TAB & $oError.helpfile & @CRLF & _
			@TAB & "err.helpcontext is: " & @TAB & $oError.helpcontext & @CRLF & _
			@TAB & "err.lastdllerror is: " & @TAB & $oError.lastdllerror & @CRLF & _
			@TAB & "err.scriptline is: " & @TAB & $oError.scriptline & @CRLF & _
			@TAB & "err.retcode is: " & @TAB & "0x" & Hex($oError.retcode) & @CRLF & @CRLF)

EndFunc   ;==>COMErrorHandler

My console output:

>"C:\Program Files (x86)\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.exe" /run /prod /ErrorStdOut /in "Z:\TOOLs\Macro\PROGRAMY\test.au3" /UserParams    
+>20:23:32 Starting AutoIt3Wrapper v.15.725.1310.0 SciTE v.3.5.4.0   Keyboard:00000415  OS:WIN_7/Service Pack 1  CPU:X64 OS:X64    Environment(Language:0415)
+>         SciTEDir => C:\Program Files (x86)\AutoIt3\SciTE   UserDir => C:\Users\user\AppData\Local\AutoIt v3\SciTE\AutoIt3Wrapper   SCITE_USERHOME => C:\Users\user\AppData\Local\AutoIt v3\SciTE 
>Running AU3Check (3.3.14.0)  from:C:\Program Files (x86)\AutoIt3  input:Z:\TOOLs\Macro\PROGRAMY\test.au3
+>20:23:32 AU3Check ended.rc:0
>Running:(3.3.14.0):C:\Program Files (x86)\AutoIt3\autoit3.exe "Z:\TOOLs\Macro\PROGRAMY\test.au3"    
--> Press Ctrl+F11 to Restart or Ctrl+Break -or- F11 to Stop
$oTask.name = Adobe Acrobat Update Task
$oTask.name = Adobe Flash Player Updater
$oTask.name = GoogleUpdateTaskMachineCore
$oTask.name = GoogleUpdateTaskMachineCore1d04199bb88b909
$oTask.name = GoogleUpdateTaskMachineCore1d091bb87ea7560
$oTask.name = GoogleUpdateTaskMachineUA1cf8c055af8ed65
$oTask.name = GoogleUpdateTaskMachineUA1d04199bba457c1
$oTask.name = Trojan Killer
$oTask.name = {27DD22F2-F184-493F-A162-F07A14E9683F}
$oTask.name = {36CB3CD5-C70E-406F-B1BE-FD1E70EBB8D9}
+>20:23:33 AutoIt3.exe ended.rc:0
+>20:23:33 AutoIt3Wrapper Finished.
>Exit code: 0    Time: 1.666

You should enumerate Tasks something like this:

$oTasks = $oFolder.GetTasks($TASK_ENUM_HIDDEN)
If IsObj($oTasks) Then
	For $oTask In $oTasks
		If StringInStr($oTask.name,$taskname) Then Return True
	Next
EndIf
Return False

comment:2 Changed 4 years ago by mLipok

I also test on 3.3.12.0
Your examples give the same error in $oFolder.GetTask($taskname)

as:
https://msdn.microsoft.com/en-us/library/windows/desktop/aa381353(v=vs.85).aspx
saying that you must set "The path (location) to the task in a folder."

For clarity I would like to say: Full Path to the an EXISTING task in a folder.

You are using only $taskname without folder, and you do not check if this task exists.

Guidelines for posting comments:

  • You cannot re-open a ticket but you may still leave a comment if you have additional information to add.
  • In-depth discussions should take place on the forum.

For more information see the full version of the ticket guidelines here.

Add Comment

Modify Ticket

Action
as new The ticket will remain with no owner.
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.