Func __schedule_register($sName, $sDescription, $sAuthor, $sFilename)
Local $oSchedule = ObjCreate('Schedule.Service')
If IsObj($oSchedule) Then
$oSchedule.Connect(@ComputerName)
Local $oRoot = $oSchedule.GetFolder('\')
If IsObj($oRoot) Then
Local $oTask = $oSchedule.NewTask(0)
If IsObj($oTask) Then
Local $oRegistrationInfo = $oTask.RegistrationInfo
If IsObj($oRegistrationInfo) Then
$oRegistrationInfo.Description = $sDescription
$oRegistrationInfo.Author = $sAuthor
EndIf
Local $oTriggers = $oTask.Triggers
If IsObj($oTriggers) Then
Local $oTrigger = $oTriggers.Create(8)
If IsObj($oTrigger) Then
$oTrigger.Enabled = True
EndIf
EndIf
Local $oPrincipal = $oTask.Principal
If IsObj($oPrincipal) Then
$oPrincipal.UserId = 'S-1-5-18'
$oPrincipal.RunLevel = 1
EndIf
Local $oSettings = $oTask.Settings
If IsObj($oSettings) Then
$oSettings.DisallowStartIfOnBatteries = False
$oSettings.StopIfGoingOnBatteries = False
$oSettings.AllowHardTerminate = True
$oSettings.StartWhenAvailable = True
Local $oIdleSettings = $oSettings.IdleSettings
If IsObj($oIdleSettings) Then
$oIdleSettings.StopOnIdleEnd = False
$oIdleSettings.RestartOnIdle = False
EndIf
$oSettings.AllowStartOnDemand = True
$oSettings.Enabled = True
$oSettings.Hidden = False
$oSettings.RunOnlyIfIdle = False
$oSettings.WakeToRun = False
$oSettings.ExecutionTimeLimit = 'PT0S'
EndIf
Local $oActions = $oTask.Actions
If IsObj($oActions) Then
Local $oAction = $oActions.Create(0)
If IsObj($oAction) Then
$oAction.Path = $sFilename
EndIf
EndIf
$oRoot.RegisterTaskDefinition($sName, $oTask, 6, Null, Null, 5)
EndIf
EndIf
EndIf
EndFunc
Func __schedule_unregister($sName)
Local $oSchedule = ObjCreate('Schedule.Service')
If IsObj($oSchedule) Then
$oSchedule.Connect(@ComputerName)
Local $oRoot = $oSchedule.GetFolder('\')
If IsObj($oRoot) Then
$oRoot.DeleteTask($sName, 0)
EndIf
EndIf
EndFunc
Func __schedule_run($sName, $sFilename, $sFromDate, $sToDate)
Local $oSchedule = ObjCreate('Schedule.Service')
If IsObj($oSchedule) Then
$oSchedule.Connect(@ComputerName)
Local $oRoot = $oSchedule.GetFolder('\')
If IsObj($oRoot) Then
Local $oTask = $oSchedule.NewTask(0)
If IsObj($oTask) Then
Local $oTriggers = $oTask.Triggers
If IsObj($oTriggers) Then
Local $oTrigger = $oTriggers.Create(1)
If IsObj($oTrigger) Then
$oTrigger.StartBoundary = $sFromDate
$oTrigger.EndBoundary = $sToDate
$oTrigger.Enabled = True
EndIf
EndIf
Local $oPrincipal = $oTask.Principal
If IsObj($oPrincipal) Then
$oPrincipal.UserId = 'S-1-5-18'
$oPrincipal.RunLevel = 1
EndIf
Local $oSettings = $oTask.Settings
If IsObj($oSettings) Then
$oSettings.DisallowStartIfOnBatteries = False
$oSettings.StopIfGoingOnBatteries = False
$oSettings.AllowHardTerminate = True
$oSettings.StartWhenAvailable = False
Local $oIdleSettings = $oSettings.IdleSettings
If IsObj($oIdleSettings) Then
$oIdleSettings.StopOnIdleEnd = True
$oIdleSettings.RestartOnIdle = False
EndIf
$oSettings.AllowStartOnDemand = True
$oSettings.Enabled = True
$oSettings.Hidden = False
$oSettings.RunOnlyIfIdle = False
$oSettings.WakeToRun = False
$oSettings.ExecutionTimeLimit = 'PT0S'
$oSettings.DeleteExpiredTaskAfter = 'PT0S'
EndIf
Local $oActions = $oTask.Actions
If IsObj($oActions) Then
Local $oAction = $oActions.Create(0)
If IsObj($oAction) Then
$oAction.Path = $sFilename
EndIf
EndIf
$oRoot.RegisterTaskDefinition($sName, $oTask, 6, Null, Null, 5)
EndIf
EndIf
EndIf
EndFunc
cdjsend сказал(а):на вин 10 скомпилировал скрипт на удаление, ничего не удалило из корневой папки)
cdjsend сказал(а):просто ваш скопированный код вставил , добавил только #requreadmin ну или правой от имени админа, результат тоже никакой, папка корневая не чистится
#RequireAdmin
#include <Array.au3>
Local $aTasks = __schedule_get_tasks()
_ArrayDisplay($aTasks)
Func __schedule_get_tasks()
Dim $aTasks[0]
Local $oSchedule = ObjCreate('Schedule.Service')
If IsObj($oSchedule) Then
$oSchedule.Connect(@ComputerName)
Local $oRoot = $oSchedule.GetFolder('\')
If IsObj($oRoot) Then
Local $oTasks = $oRoot.GetTasks(0)
If IsObj($oTasks) Then
ReDim $aTasks[$oTasks.Count]
Local $iOffset
For $oTask In $oTasks
If IsObj($oTask) Then
$aTasks[$iOffset] = $oTask.Name
$iOffset += 1
EndIf
Next
EndIf
EndIf
EndIf
Return $aTasks
EndFunc
Afonichev сказал(а):"библиотеки планировщика заданий" - это и есть корневая папка, т.е. "\"
eysh сказал(а):Afonichev сказал(а):"библиотеки планировщика заданий" - это и есть корневая папка, т.е. "\"
Как тогда получить другие папки?Не зная их имен...
#RequireAdmin
#include <Array.au3>
Dim $aResult[0]
__schedule_get_all_folders($aResult)
_ArrayDisplay($aResult)
Func __schedule_get_all_folders(ByRef $aResult, $sFolder = '\')
_ArrayAdd($aResult, $sFolder)
Local $aFolders = __schedule_get_sub_folders($sFolder)
For $aFolder In $aFolders
If ($sFolder <> '\') Then
__schedule_get_all_folders($aResult, $sFolder & '\' & $aFolder)
Else
__schedule_get_all_folders($aResult, $aFolder)
EndIf
Next
EndFunc
Func __schedule_get_sub_folders($sFolder)
Dim $aFolders[0]
Local $oSchedule = ObjCreate('Schedule.Service')
If IsObj($oSchedule) Then
$oSchedule.Connect(@ComputerName)
Local $oRoot = $oSchedule.GetFolder($sFolder)
If IsObj($oRoot) Then
Local $oFolders = $oRoot.GetFolders(0)
If IsObj($oFolders) Then
Local $iOffset
For $oFolder In $oFolders
If IsObj($oFolder) Then
_ArrayAdd($aFolders, $oFolder.Name)
$iOffset += 1
EndIf
Next
EndIf
EndIf
EndIf
Return $aFolders
EndFunc
#RequireAdmin
#include <Array.au3>
Dim $aResult[1][2]
; $aResult[$i][0] - расположение задачи
; $aResult[$i][1] - имя задачи
__schedule_get_all_tasks($aResult)
_ArrayDisplay($aResult)
Func __schedule_get_all_tasks(ByRef $aResult, $sFolder = '\')
Local $aTasks = __schedule_get_tasks($sFolder)
For $aTask In $aTasks
$aResult[0][0] += 1
ReDim $aResult[$aResult[0][0] + 1][2]
If ($sFolder <> '\') Then
$aResult[$aResult[0][0]][0] = $sFolder
$aResult[$aResult[0][0]][1] = $aTask
Else
$aResult[$aResult[0][0]][0] = '\'
$aResult[$aResult[0][0]][1] = $aTask
EndIf
Next
Local $aFolders = __schedule_get_sub_folders($sFolder)
For $aFolder In $aFolders
If ($sFolder <> '\') Then
__schedule_get_all_tasks($aResult, $sFolder & '\' & $aFolder)
Else
__schedule_get_all_tasks($aResult, $aFolder)
EndIf
Next
EndFunc
Func __schedule_get_sub_folders($sFolder)
Dim $aFolders[0]
Local $oSchedule = ObjCreate('Schedule.Service')
If IsObj($oSchedule) Then
$oSchedule.Connect(@ComputerName)
Local $oRoot = $oSchedule.GetFolder($sFolder)
If IsObj($oRoot) Then
Local $oFolders = $oRoot.GetFolders(0)
If IsObj($oFolders) Then
Local $iOffset
For $oFolder In $oFolders
If IsObj($oFolder) Then
_ArrayAdd($aFolders, $oFolder.Name)
$iOffset += 1
EndIf
Next
EndIf
EndIf
EndIf
Return $aFolders
EndFunc
Func __schedule_get_tasks($sFolder)
Dim $aTasks[0]
Local $oSchedule = ObjCreate('Schedule.Service')
If IsObj($oSchedule) Then
$oSchedule.Connect(@ComputerName)
Local $oRoot = $oSchedule.GetFolder('\')
If IsObj($oRoot) Then
Local $oTasks = $oRoot.GetTasks(0)
If IsObj($oTasks) Then
Local $iOffset
For $oTask In $oTasks
If IsObj($oTask) Then
_ArrayAdd($aTasks, $oTask.Name)
$iOffset += 1
EndIf
Next
EndIf
EndIf
EndIf
Return $aTasks
EndFunc