Ok wenns beabsichtigt war passt das ja.
TaskScheduler / Aufgabenplaner mittels ObjCreate("Schedule.Service") ansteuern
-
- [ gelöst ]
-
KaFu -
22. Januar 2011 um 20:07 -
Geschlossen -
Erledigt
-
-
So, nun habe ich noch einen kleinen Fehler beseitigt.
Wenn man zwei Tasks im gleichen Script hintereinander erstellen wollte, wurde der 2. Task zwar erstellt, jedoch gab es immer eine Fehlermeldung zurück.Man muss zwei Variablen am Ende auf 0 setzen.
Hier die aktuelle UDF:Spoiler anzeigen
[autoit]#include-once
[/autoit] [autoit][/autoit] [autoit]
Dim $oMyError, $ErrorFound = False;==================================================================================
[/autoit] [autoit][/autoit] [autoit]
; Function: _CreateTask($TaskName, $TaskDescription, $TriggerEvent, $StartTrigger, $EndTrigger, $DaysOfWeek, $DaysOfMonth, $MonthOfYear, $WeeksOfMonth, $DaysInterval, $Interval, $RepetitionEnabled, $LogonType, $RunLevel, $Username, $Password, $Program, $WorkingDirectory = "", $Arguments = "", $RunOnlyIfNetworkAvailable = True)
; Description: Creates a scheduled task
; Parameter(s): $h_Window - Handle to the Window to update
; $i_Mode - Update Mode; 0=Small Update; 1=Normal Update.
; Return Value(s): On Success - Return 1, @ERROR = 0
; On Failure - Sets @ERROR = 1, Return 0
; - Wrong OS (Needs Vista or higher) @Error = 2 Return 0
; Author(s): Unknown (http://www.autoit.de/index.php?page…4517#post214517)
; Changes: Veronesi
; Note(s): Works only on Win7 and above (Perhaps also Win Vista, but not tested!)
; Example: _CreateTask("Testname", "Description of this task", 3, "2011-03-30T08:00:00", "", 2, 1, 1, 1, 1, "PT1H", False, 3, 0, "", "", '"c:\windows\system32\notepad.exe"', "", "", True)
;==================================================================================#cs
[/autoit] [autoit][/autoit] [autoit]
$TaskName => String, Free text$TaskDescription => String, Free text
[/autoit] [autoit][/autoit] [autoit]$TriggerEvent => http://msdn.microsoft.com/en-us/library/…v=VS.85%29.aspx
[/autoit] [autoit][/autoit] [autoit]
(0: TASK_TRIGGER_EVENT; Triggers the task when a specific event occurs.) => Not working yet
1: TASK_TRIGGER_TIME; Triggers the task at a specific time of day.
2: TASK_TRIGGER_DAILY; Triggers the task on a daily schedule. For example, the task starts at a specific time every day, every-other day, every third day, and so on.
3: TASK_TRIGGER_WEEKLY; Triggers the task on a weekly schedule. For example, the task starts at 8:00 AM on a specific day every week or other week.
4: TASK_TRIGGER_MONTHLY; Triggers the task on a monthly schedule. For example, the task starts on specific days of specific months.
5: TASK_TRIGGER_MONTHLYDOW; Triggers the task on a monthly day-of-week schedule. For example, the task starts on a specific days of the week, weeks of the month, and months of the year.
6: TASK_TRIGGER_IDLE; Triggers the task when the computer goes into an idle state.
7: TASK_TRIGGER_REGISTRATION; Triggers the task when the task is registered.
8: TASK_TRIGGER_BOOT; Triggers the task when the computer boots. => Needs Admin-Rights!
9: TASK_TRIGGER_LOGON; Triggers the task when a specific user logs on. => Needs Admin-Rights!
11:TASK_TRIGGER_SESSION_STATE_CHANGE; Triggers the task when a specific session state changes. => Needs Admin-Rights!$StartTrigger => String with Start time / date (Year-Month-DayTHour:Min:Sec) E.g. "2011-03-30T08:00:00"
[/autoit] [autoit][/autoit] [autoit]$EndTrigger => String with End time / date (Year-Month-DayTHour:Min:Sec) E.g. "2011-03-30T08:00:00"
[/autoit] [autoit][/autoit] [autoit]$DaysOfWeek => Integer; 1 = Sunday / 2 = Monday / 4 = Tuesday / 8 = Wednesday / 16 = Thursday / 32 = Friday / 64 = Saturday (http://msdn.microsoft.com/en-us/library/…4(v=VS.85).aspx)
[/autoit] [autoit][/autoit] [autoit]
3 = Sunday AND Monday!
This value works only in TriggerEvent 3 or 5$DaysOfMonth => Integer http://msdn.microsoft.com/en-us/library/aa380735(VS.85).aspx
[/autoit] [autoit][/autoit] [autoit]
This value is only noted when $TriggerEvent = 4
Day 1; 1
Day 2; 2
Day 3; 4
Day 4; 8
Day 5; 16
Day 6; 32
Day 7; 64
Day 8; 128
Day 9; 256
Day 10; 512
Day 11; 1024
Day 12; 2048
Day 13; 4096
Day 14; 8192
Day 15; 16384
Day 16; 32768
Day 17; 65536
Day 18; 131072
Day 19; 262144
Day 20; 524288
Day 21; 1048576
Day 22; 2097152
Day 23; 4194304
Day 24; 8388608
Day 25; 16777216
Day 26; 33554432
Day 27; 67108864
Day 28; 134217728
Day 29; 268435456
Day 30; 536870912
Day 31; 1073741824
Last Day; 2147483648$MonthOfYear => http://msdn.microsoft.com/en-us/library/…6(v=VS.85).aspx
[/autoit] [autoit][/autoit] [autoit]
This value is only noted when $TriggerEvent = 4
January; 1
February; 2
March; 4
April; 8
May; 16
June; 32
July; 64
August; 128
September; 256
October; 512
November; 1024
December; 2048
January + February = 3...$WeeksOfMonth => http://msdn.microsoft.com/en-us/library/…3(v=VS.85).aspx
[/autoit] [autoit][/autoit] [autoit]
This value is only noted when $TriggerEvent = 5
First; 1
Second; 2
Third; 4
Fourth; 8
Fifth; 16
Last; 32$DaysInterval => Integer of Days Interval; http://msdn.microsoft.com/en-us/library/…0(v=VS.85).aspx
[/autoit] [autoit][/autoit] [autoit]
This value is only noted when $TriggerEvent = 2$Interval => String for Interval; http://msdn.microsoft.com/en-us/library/…8(v=VS.85).aspx
[/autoit] [autoit][/autoit] [autoit]
P<days>DT<hours>H<minutes>M<seconds>S (for example, "PT5M" is 5 minutes, "PT1H" is 1 hour, and "PT20M" is 20 minutes). The maximum time allowed is 31 days, and the minimum time allowed is 1 minute.$RepetitionEnabled => True = Interval Trigger enabled / False = Interval Trigger disabled
[/autoit] [autoit][/autoit] [autoit]$LogonType => 2 = TASK_LOGON_S4U / Independant from an userlogin
[/autoit] [autoit][/autoit] [autoit]
3 = User must already be logged in
;http://msdn.microsoft.com/en-us/library/…v=VS.85%29.aspx$RunLevel => 0 = lowest, 1 = highest; http://msdn.microsoft.com/en-us/library/…v=VS.85%29.aspx
[/autoit] [autoit][/autoit] [autoit]
Highest Need Admin-Rights!$Username => String with domainname "\" and Username. Use blank string ("") for actual user
[/autoit] [autoit][/autoit] [autoit]$Password => Password for the specified user
[/autoit] [autoit][/autoit] [autoit]$Program => String, Full Path and Programname to run
[/autoit] [autoit][/autoit] [autoit]$WorkingDirectory => Optional String
[/autoit] [autoit][/autoit] [autoit]$Arguments => Optional String
[/autoit] [autoit][/autoit] [autoit]$RunOnlyIfNetworkAvailable => Optional Boolean (Default = True)
[/autoit] [autoit][/autoit] [autoit]#ce
[/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]Func _CreateTask($TaskName, $TaskDescription, $TriggerEvent, $StartTrigger, $EndTrigger, $DaysOfWeek, $DaysOfMonth, $MonthOfYear, $WeeksOfMonth, $DaysInterval, $Interval, $RepetitionEnabled, $LogonType, $RunLevel, $Username, $Password, $Program, $WorkingDirectory = "", $Arguments = "", $RunOnlyIfNetworkAvailable = True)
[/autoit] [autoit][/autoit] [autoit]
If @OSVersion = "WIN_XP" Or @OSVersion = "WIN_XPe" Or @OSVersion = "WIN_2000" Then Return SetError (2, 2, 0)Local $oService, $oFolder, $oTaskDefinition, $oRegistrationInfo, $oSettings
[/autoit] [autoit][/autoit] [autoit]
Local $oPrincipal, $oColActions, $oAction, $oTrigger, $oColTriggers, $oTriggerRepetitionIf $TaskName = "" Or $Program = "" Then Return SetError (1, 1, 0)
[/autoit] [autoit][/autoit] [autoit];http://www.scriptinganswers.com/forum2/forum_posts.asp?TID=3282
[/autoit] [autoit][/autoit] [autoit]
;http://www.autoit.de/index.php?page…4517#post214517
;http://msdn.microsoft.com/en-us/library/…v=VS.85%29.aspx
$oMyError = ObjEvent("AutoIt.Error", "MyCreateTaskErrFunc") ; Initialize a COM error handler
$oService = ObjCreate("Schedule.Service")
$oService.Connect()$oFolder = $oService.GetFolder("\")
[/autoit] [autoit][/autoit] [autoit]
$oTaskDefinition = $oService.NewTask(0)$oRegistrationInfo = $oTaskDefinition.RegistrationInfo()
[/autoit] [autoit][/autoit] [autoit]
$oRegistrationInfo.Description() = $TaskDescription
$oRegistrationInfo.Author() = @LogonDomain & "\" & @UserName$oSettings = $oTaskDefinition.Settings()
[/autoit] [autoit][/autoit] [autoit]
$oSettings.MultipleInstances() = 0 ;Starts a new instance while an existing instance of the task is running.
$oSettings.DisallowStartIfOnBatteries() = False
$oSettings.StopIfGoingOnBatteries() = False
$oSettings.AllowHardTerminate() = True
$oSettings.StartWhenAvailable() = True ;Start task as soon as possible when task missed
$oSettings.RunOnlyIfNetworkAvailable() = $RunOnlyIfNetworkAvailable$oSettings.Enabled() = True ;True ; The task can be performed only when this setting is True.
[/autoit] [autoit][/autoit] [autoit]
$oSettings.Hidden() = False
$oSettings.RunOnlyIfIdle() = False
$oSettings.WakeToRun() = False
$oSettings.ExecutionTimeLimit() = "P1D" ; When this parameter is set to Nothing, the execution time limit is infinite.
$oSettings.Priority() = 5 ;http://msdn.microsoft.com/en-us/library/…0(v=VS.85).aspx 0 = Realtime, 10 = Idle$oPrincipal = $oTaskDefinition.Principal()
[/autoit] [autoit][/autoit] [autoit]
$oPrincipal.Id() = @UserName
$oPrincipal.DisplayName() = @UserName
$oPrincipal.LogonType() = $LogonType
$oPrincipal.RunLevel() = $RunLevel$oColTriggers = $oTaskDefinition.Triggers()
[/autoit] [autoit][/autoit] [autoit]
$oTrigger = $oColTriggers.Create($TriggerEvent)$oTrigger.Id() = "TriggerID"
[/autoit] [autoit][/autoit] [autoit]
$oTrigger.Enabled() = True
$oTrigger.StartBoundary() = $StartTrigger
$oTrigger.EndBoundary() = $EndTrigger
If $TriggerEvent = 3 Or $TriggerEvent = 5 Then
$oTrigger.DaysOfWeek() = $DaysOfWeek
EndIfIf $TriggerEvent = 4 Then
[/autoit] [autoit][/autoit] [autoit]
$oTrigger.DaysOfMonth() = $DaysOfMonth
$oTrigger.MonthsOfYear() = $MonthOfYear
EndIfIf $TriggerEvent = 5 Then
[/autoit] [autoit][/autoit] [autoit]
$oTrigger.WeeksOfMonth() = $WeeksOfMonth
EndIfIf $TriggerEvent = 2 Then
[/autoit] [autoit][/autoit] [autoit]
$oTrigger.DaysInterval() = $DaysInterval
EndIfIf $RepetitionEnabled Then
[/autoit] [autoit][/autoit] [autoit]
$oTriggerRepetition = $oTrigger.Repetition()
$oTriggerRepetition.Interval() = $Interval
EndIf$oColActions = $oTaskDefinition.Actions()
[/autoit] [autoit][/autoit] [autoit]
$oColActions.Context() = @UserName
$oAction = $oTaskDefinition.Actions.Create(0)
$oAction.Path() = $Program
$oAction.WorkingDirectory() = $WorkingDirectory
$oAction.Arguments() = $Arguments; call rootFolder.RegisterTaskDefinition(strTaskName, taskDefinition, FlagTaskCreate, , , LogonTypeInteractive)
[/autoit] [autoit][/autoit] [autoit]
$oFolder.RegisterTaskDefinition($TaskName, $oTaskDefinition, 6, $Username, $Password, $LogonType, "")If $ErrorFound Then Return SetError(3, 3, 0)
[/autoit] [autoit][/autoit] [autoit]
$oService = 0
$oMyError = 0
Return 1
EndFunc ;==>_CreateTaskFunc MyCreateTaskErrFunc()
[/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]
$ErrorFound = True
Return 0;~ MsgBox(0, "AutoItCOM Test", "We intercepted a COM Error !" & @CRLF & @CRLF & _
[/autoit] [autoit][/autoit] [autoit]
;~ "err.description is: " & @TAB & $oMyError.description & @CRLF & _
;~ "err.windescription:" & @TAB & $oMyError.windescription & @CRLF & _
;~ "err.number is: " & @TAB & Hex($oMyError.number, & @CRLF & _
;~ "err.lastdllerror is: " & @TAB & $oMyError.lastdllerror & @CRLF & _
;~ "err.scriptline is: " & @TAB & $oMyError.scriptline & @CRLF & _
;~ "err.source is: " & @TAB & $oMyError.source & @CRLF & _
;~ "err.helpfile is: " & @TAB & $oMyError.helpfile & @CRLF & _
;~ "err.helpcontext is: " & @TAB & $oMyError.helpcontext _
;~ );~ Local $err = $oMyError.number
[/autoit] [autoit][/autoit] [autoit]
;~ Local $g_eventerror
;~ If $err = 0 Then $err = -1;~ $g_eventerror = $err ; to check for after this function returns
[/autoit]
EndFunc ;==>MyCreateTaskErrFuncGrüsse Veronesi
-
hey Veronesi,
musste mich nun erstmal anmelden Dein Code ist der Hammer.. voll toll.. aber wie binde ich ein Argument mit ein? Also sprich: "programm.exe übergabewert"
Es geht nicht, weil der das nicht in das richtige Feld mit einbindet. auch "programm.exe -übergabe" oder "programm.exe - übergabe" mag der auch nicht. oje.. was mach ich falsch? geht das überhaupt?
danke für deine Hilfe. -
Hallo Anna,
[autoit]
also ohne Code kann ich nur raten.
Aber wenn Du Probleme mit der Parameterüberhabe hast, so würde ich mir mal das foldende Beispiel ansehen:#include <Array.au3>
[/autoit][autoit][/autoit][autoit]
If $CmdLine[0] = 0 Then ;Keine Parameter übergeben!
Dim $Parameter[1] = [0]
Else
Dim $Parameter[$CmdLine[0]]
For $i = 1 To $CmdLine[0]
$Parameter[$i - 1] = $CmdLine[$i]
Next
EndIf_ArrayDisplay($Parameter)
[/autoit]So kannst Du in AutoIt Parameter einlesen.
In $CmdLine[0] steht drin, wieviele Parameter (wenn überhaupt) vorhanden sind.
So kannst Du die Parameter einlesen und dann ganz normal eine Funktion mit diesen Parametern aufrufen.Grüsse Veronesi
-
hey,
sorry, da hab ich mich wohl falsch ausgedrückt oder du hast'S falsch verstanden
beim TaskScheduler kann man doch einen Übergabeparameter eingeben. Wie kann ich das bei deinem Code machen?
Bei dir kann ich ja nur das auszuführende Programm als String übergeben. Bei dem TaskScheduler heißt das "Argumente".das mit der CMD-Übergabe in AutoIt ist mir klar
Hier noch ein Bild.. dann wirds klarer:
[Blockierte Grafik: http://www.ewig-drohendes-versagen.de/wp-content/geheim_uploads/2009/12/aufgabenplaner.png]
Siehe "Argumente hinzu"
Danke
-
Warum nimmst Du dann nicht einfach den Parameter $Arguments (Zweitletzter Parameter....)?
Veronesi
-
Ohman, ich habs ja voll überlesen.. peinlich.. da kann man ja echt was anhängen.. supi danke dir
-
gibt es eine möglichkeit auch tasks zu löschen bzw. rauszufinden welche bereits existieren?
-
OK, ich habe da shier mal selber erweitert um die nötigen funktionen.
Den Code/Thread dazu findet Ihr hier: http://www.autoitscript.com/forum/topic/13…askplanner-udf/
- Func TestTaskSchedulerUDF()
- Func TaskSchedulerAutostart();check if the schedulerservice is set to autostart
- Func _TaskFolderCreate($folder);Create folder - only folders that do not already exist can be created without error
- Func _TaskFolderDelete($folder);Delete folder - only folders that do exist and that are empty can be deleted without error
- Func _TaskFolderExists($folder = "\");check if a TaskFolder exists
- Func _TaskExists($taskname, $folder = "\");check if a Task exists
- Func _TaskStop($taskname, $folder = "\");stop a task
- Func _TaskStart($taskname, $folder = "\");start a task
- Func _TaskIsRunning($taskname, $folder = "\");check if a Task is running
- Func _TaskDelete($taskname, $folder = "\");delete an existing task
- Func _TaskListall($folder = "\", $hidden = 1);get a list of all tasks in a given taskfolder (Tasknames only) List is a string with names separeted by "|"
- Func _TaskCreate($taskname, $TaskDescription, $TriggerEvent, $StartTrigger, $EndTrigger, $DaysOfWeek, $DaysOfMonth, $MonthOfYear, $WeeksOfMonth, $DaysInterval, $Interval, $RepetitionEnabled, $LogonType, $RunLevel, $Username, $Password, $Program, $WorkingDirectory = "", $Arguments = "", $RunOnlyIfNetworkAvailable = True, $active = True, $multiinst = 0, $nobatstart = False, $stoponBat = False, $hidden = False, $idle = False, $WakeToRun = False, $timelimit = "P1D", $priority = 5)
EDIT: aktualisierte version angehängt mit bugfixes...soalange kein weiteres feedback kommt bin ich erstmal fertig, für mich klappt alles. Achtung: autoit unterstützt nur einen COM errorhandler, daher vorsicht wenn man mehrere COM basierende UDFs kombiniert die einen errorhandler haben...
-
Hi,
Leider startet das Script aus Post #10 bei mir nicht. Es gibt auch keinerlei Fehlermeldung. Egal, ob ich das Script als Exe kompiliere, und dann als Admin starte, oder als User. Auch aus Scite heraus keine Funktion, keine Fehlermeldung. Die Aufgabe wird einfach nicht erstellt. Nutze Win7Pro 32Bit.
Was kann das Problem sein?
Hier mein Script:
Code
Alles anzeigen#include <IncludeCreateTask.au3> $StrDownloadLink = "http://www.teamviewer.com/download/TeamViewerPortable.zip" $StrDownloadPath = @UserProfileDir & "\Downloads\TeamViewerPortable.zip" $StrExtractPath = StringLeft($StrDownloadPath, StringLen($StrDownloadPath)-4) $StrExtractedFilesPath = @UserProfileDir& "\Downloads\TeamViewerPortable\" $StrOrgExePath = @UserProfileDir & "\Downloads\TeamViewerPortable\TeamViewer.exe" $StrProgFilesPath = @ProgramFilesDir & "\TeamViewerPortable\" $StrExePath = $StrProgFilesPath & "TeamViewer.exe" $StrProgFilesPathEx = StringLeft($StrProgFilesPath, StringLen($StrProgFilesPath)-1) $StrShortcutFileName = "Teamviewer - Fernwartung.lnk" $StrShortcutFilePath = @DesktopCommonDir & "\" & $StrShortcutFileName ... _CreateTask("Teamviewer", "Startet Teamviewer als Admin", 1, $StrExePath, $StrProgFilesPathEx)
und in der IncludeCreateTask.au3:
Code
Alles anzeigen#include-once Dim $oMyError, $ErrorFound = False ;================================================================================== ; Function: _CreateTask($TaskName, $TaskDescription, $TriggerEvent, $StartTrigger, $EndTrigger, $DaysOfWeek, $DaysOfMonth, $MonthOfYear, $WeeksOfMonth, $DaysInterval, $Interval, $RepetitionEnabled, $LogonType, $RunLevel, $Username, $Password, $Program, $WorkingDirectory = "", $Arguments = "", $RunOnlyIfNetworkAvailable = True) ; Description: Creates a scheduled task ; Parameter(s): $h_Window - Handle to the Window to update ; $i_Mode - Update Mode; 0=Small Update; 1=Normal Update. ; Return Value(s): On Success - Return 1, @ERROR = 0 ; On Failure - Sets @ERROR = 1, Return 0 ; - Wrong OS (Needs Vista or higher) @Error = 2 Return 0 ; Author(s): Unknown (http://www.autoit.de/index.php?page=Thread&postID=214517#post214517) ; Changes: Veronesi ; Note(s): Works only on Win7 and above (Perhaps also Win Vista, but not tested!) ; Example: _CreateTask("Testname", "Description of this task", 3, "2011-03-30T08:00:00", "", 2, 1, 1, 1, 1, "PT1H", False, 3, 0, "", "", '"c:\windows\system32\notepad.exe"', "", "", True) ;================================================================================== #cs $TaskName => String, Free text $TaskDescription => String, Free text $TriggerEvent => http://msdn.microsoft.com/en-us/library/aa383898%28v=VS.85%29.aspx (0: TASK_TRIGGER_EVENT; Triggers the task when a specific event occurs.) => Not working yet 1: TASK_TRIGGER_TIME; Triggers the task at a specific time of day. 2: TASK_TRIGGER_DAILY; Triggers the task on a daily schedule. For example, the task starts at a specific time every day, every-other day, every third day, and so on. 3: TASK_TRIGGER_WEEKLY; Triggers the task on a weekly schedule. For example, the task starts at 8:00 AM on a specific day every week or other week. 4: TASK_TRIGGER_MONTHLY; Triggers the task on a monthly schedule. For example, the task starts on specific days of specific months. 5: TASK_TRIGGER_MONTHLYDOW; Triggers the task on a monthly day-of-week schedule. For example, the task starts on a specific days of the week, weeks of the month, and months of the year. 6: TASK_TRIGGER_IDLE; Triggers the task when the computer goes into an idle state. 7: TASK_TRIGGER_REGISTRATION; Triggers the task when the task is registered. 8: TASK_TRIGGER_BOOT; Triggers the task when the computer boots. => Needs Admin-Rights! 9: TASK_TRIGGER_LOGON; Triggers the task when a specific user logs on. => Needs Admin-Rights! 11:TASK_TRIGGER_SESSION_STATE_CHANGE; Triggers the task when a specific session state changes. => Needs Admin-Rights! $StartTrigger => String with Start time / date (Year-Month-DayTHour:Min:Sec) E.g. "2011-03-30T08:00:00" $EndTrigger => String with End time / date (Year-Month-DayTHour:Min:Sec) E.g. "2011-03-30T08:00:00" $DaysOfWeek => Integer; 1 = Sunday / 2 = Monday / 4 = Tuesday / 8 = Wednesday / 16 = Thursday / 32 = Friday / 64 = Saturday (http://msdn.microsoft.com/en-us/library/aa384024(v=VS.85).aspx) 3 = Sunday AND Monday! This value works only in TriggerEvent 3 or 5 $DaysOfMonth => Integer http://msdn.microsoft.com/en-us/library/aa380735(VS.85).aspx This value is only noted when $TriggerEvent = 4 Day 1; 1 Day 2; 2 Day 3; 4 Day 4; 8 Day 5; 16 Day 6; 32 Day 7; 64 Day 8; 128 Day 9; 256 Day 10; 512 Day 11; 1024 Day 12; 2048 Day 13; 4096 Day 14; 8192 Day 15; 16384 Day 16; 32768 Day 17; 65536 Day 18; 131072 Day 19; 262144 Day 20; 524288 Day 21; 1048576 Day 22; 2097152 Day 23; 4194304 Day 24; 8388608 Day 25; 16777216 Day 26; 33554432 Day 27; 67108864 Day 28; 134217728 Day 29; 268435456 Day 30; 536870912 Day 31; 1073741824 Last Day; 2147483648 $MonthOfYear => http://msdn.microsoft.com/en-us/library/aa380736(v=VS.85).aspx This value is only noted when $TriggerEvent = 4 January; 1 February; 2 March; 4 April; 8 May; 16 June; 32 July; 64 August; 128 September; 256 October; 512 November; 1024 December; 2048 January + February = 3... $WeeksOfMonth => http://msdn.microsoft.com/en-us/library/aa380733(v=VS.85).aspx This value is only noted when $TriggerEvent = 5 First; 1 Second; 2 Third; 4 Fourth; 8 Fifth; 16 Last; 32 $DaysInterval => Integer of Days Interval; http://msdn.microsoft.com/en-us/library/aa380660(v=VS.85).aspx This value is only noted when $TriggerEvent = 2 $Interval => String for Interval; http://msdn.microsoft.com/en-us/library/aa381138(v=VS.85).aspx P<days>DT<hours>H<minutes>M<seconds>S (for example, "PT5M" is 5 minutes, "PT1H" is 1 hour, and "PT20M" is 20 minutes). The maximum time allowed is 31 days, and the minimum time allowed is 1 minute. $RepetitionEnabled => True = Interval Trigger enabled / False = Interval Trigger disabled $LogonType => 2 = TASK_LOGON_S4U / Independant from an userlogin 3 = User must already be logged in ;http://msdn.microsoft.com/en-us/library/aa382075%28v=VS.85%29.aspx $RunLevel => 0 = lowest, 1 = highest; http://msdn.microsoft.com/en-us/library/aa382076%28v=VS.85%29.aspx Highest Need Admin-Rights! $Username => String with domainname "\" and Username. Use blank string ("") for actual user $Password => Password for the specified user $Program => String, Full Path and Programname to run $WorkingDirectory => Optional String $Arguments => Optional String $RunOnlyIfNetworkAvailable => Optional Boolean (Default = True) #ce Func _CreateTask($TaskName, $TaskDescription, $RunLevel, $Program, $WorkingDirectory = "", $Arguments = "", $RunOnlyIfNetworkAvailable = False) If @OSVersion = "WIN_XP" Or @OSVersion = "WIN_XPe" Or @OSVersion = "WIN_2000" Then Return SetError (2, 2, 0) ;Inserted by Zoli1972 local $TriggerEvent, $StartTrigger, $EndTrigger, $DaysOfWeek, $DaysOfMonth, $MonthOfYear, $WeeksOfMonth, $DaysInterval, $Interval, $RepetitionEnabled, $LogonType local $Username, $Password ;End Inserted by Zoli1972 Local $oService, $oFolder, $oTaskDefinition, $oRegistrationInfo, $oSettings Local $oPrincipal, $oColActions, $oAction, $oTrigger, $oColTriggers, $oTriggerRepetition If $TaskName = "" Or $Program = "" Then Return SetError (1,1,1) ;http://www.scriptinganswers.com/forum2/forum_posts.asp?TID=3282 ;http://www.autoit.de/index.php?page=Thread&postID=214517#post214517 ;http://msdn.microsoft.com/en-us/library/aa383898%28v=VS.85%29.aspx $oMyError = ObjEvent("AutoIt.Error", "MyCreateTaskErrFunc") ; Initialize a COM error handler $oService = ObjCreate("Schedule.Service") $oService.Connect() $oFolder = $oService.GetFolder("\") $oTaskDefinition = $oService.NewTask(0) $oRegistrationInfo = $oTaskDefinition.RegistrationInfo() $oRegistrationInfo.Description() = $TaskDescription $oRegistrationInfo.Author() = @LogonDomain & "\" & @UserName $oSettings = $oTaskDefinition.Settings() $oSettings.MultipleInstances() = 0 ;Starts a new instance while an existing instance of the task is running. $oSettings.DisallowStartIfOnBatteries() = False $oSettings.StopIfGoingOnBatteries() = False $oSettings.AllowHardTerminate() = True $oSettings.StartWhenAvailable() = True ;Start task as soon as possible when task missed $oSettings.RunOnlyIfNetworkAvailable() = $RunOnlyIfNetworkAvailable $oSettings.Enabled() = True ;True ; The task can be performed only when this setting is True. $oSettings.Hidden() = False $oSettings.RunOnlyIfIdle() = False $oSettings.WakeToRun() = False $oSettings.ExecutionTimeLimit() = "P1D" ; When this parameter is set to Nothing, the execution time limit is infinite. $oSettings.Priority() = 5 ;http://msdn.microsoft.com/en-us/library/aa383070(v=VS.85).aspx 0 = Realtime, 10 = Idle $oPrincipal = $oTaskDefinition.Principal() $oPrincipal.Id() = @UserName $oPrincipal.DisplayName() = @UserName $oPrincipal.LogonType() = $LogonType $oPrincipal.RunLevel() = $RunLevel $oColTriggers = $oTaskDefinition.Triggers() $oTrigger = $oColTriggers.Create($TriggerEvent) $oTrigger.Id() = "TriggerID" $oTrigger.Enabled() = True $oTrigger.StartBoundary() = $StartTrigger $oTrigger.EndBoundary() = $EndTrigger If $TriggerEvent = 3 Or $TriggerEvent = 5 Then $oTrigger.DaysOfWeek() = $DaysOfWeek EndIf If $TriggerEvent = 4 Then $oTrigger.DaysOfMonth() = $DaysOfMonth $oTrigger.MonthsOfYear() = $MonthOfYear EndIf If $TriggerEvent = 5 Then $oTrigger.WeeksOfMonth() = $WeeksOfMonth EndIf If $TriggerEvent = 2 Then $oTrigger.DaysInterval() = $DaysInterval EndIf If $RepetitionEnabled Then $oTriggerRepetition = $oTrigger.Repetition() $oTriggerRepetition.Interval() = $Interval EndIf $oColActions = $oTaskDefinition.Actions() $oColActions.Context() = @UserName $oAction = $oTaskDefinition.Actions.Create(0) $oAction.Path() = $Program $oAction.WorkingDirectory() = $WorkingDirectory $oAction.Arguments() = $Arguments ; call rootFolder.RegisterTaskDefinition(strTaskName, taskDefinition, FlagTaskCreate, , , LogonTypeInteractive) $oFolder.RegisterTaskDefinition($TaskName, $oTaskDefinition, 6, $Username, $Password, $LogonType, "") If $ErrorFound Then Return SetError(1,1,0) Return 1 EndFunc ;==>_CreateTask Func MyCreateTaskErrFunc() $ErrorFound = True Return 0 MsgBox(0, "AutoItCOM Test", "We intercepted a COM Error !" & @CRLF & @CRLF & _ "err.description is: " & @TAB & $oMyError.description & @CRLF & _ "err.windescription:" & @TAB & $oMyError.windescription & @CRLF & _ "err.number is: " & @TAB & Hex($oMyError.number, 8) & @CRLF & _ "err.lastdllerror is: " & @TAB & $oMyError.lastdllerror & @CRLF & _ "err.scriptline is: " & @TAB & $oMyError.scriptline & @CRLF & _ "err.source is: " & @TAB & $oMyError.source & @CRLF & _ "err.helpfile is: " & @TAB & $oMyError.helpfile & @CRLF & _ "err.helpcontext is: " & @TAB & $oMyError.helpcontext _ ) Local $err = $oMyError.number Local $g_eventerror If $err = 0 Then $err = -1 $g_eventerror = $err ; to check for after this function returns EndFunc ;==>MyCreateTaskErrFunc
Ich habe eigentlich nur soviel verändert, daß ich die für mich unnötigen Parameter fest codiert habe. Siehe dazu die von mir hinzugefügten Zeilen.
Was mache ich falsch?
Zoli
-