Jump to content

Taskplaner/Taskscheduler COM UDF


Recommended Posts

thank you for the script Allow2010 .

i working on a project these day , who basically disable unwanted things loaded on startup , especially updaters .

i solved my needs for windows xp using the old microsoft jt.exe (referring here only for the scheduled tasks part)

but , in windows seven my script dont work properly.

i try to change/complete your script , but probaly i do not find/apply the right methods and/or properties .

i cant find much info on the net for theese .

if dont want bother yoy , but some new functions like

  • Func _TaskEnable($taskname, $folder = ""); enable a Task
  • Func _TaskDisable($taskname, $folder = ""); disable a Task
  • Func _TaskCheckIsEnabled($taskname, $folder = "");check if a Task is enabled
can help me and other when i finish/publish my project

i suppose all 3 function will set/check

$oSettings.Enabled() = $active ;True ; The task can be performed only when this setting is True.

.

thank you !

oneLess

Link to post
Share on other sites
  • Replies 48
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Popular Posts

Hi all, i needed an UDF for using the Windows Taskplaner / Task Scheduler. Everything i found was based on at.exe (outdated) or based on schtasks.exe (limited in functionality) or using WMI (which c

  • Func _TaskEnable($taskname, $folder = ""); enable a Task
  • Func _TaskDisable($taskname, $folder = ""); disable a Task
  • Func _TaskCheckIsEnabled($taskname, $folder = "");check if a Task is enabled
i found the right property here : http://msdn.microsoft.com/en-us/library/windows/desktop/aa380757(v=vs.85).aspx

$oTask.Enabled = False ; [= 0 , will disable the task]

$oTask.Enabled = True ; [=-1 , will enable the task]

$_a = $oTask.Enabled ; [will read the status of the task , 0=False=Disabled , -1=True=Enabled]

more options in reading of status here : http://msdn.microsoft.com/en-us/library/windows/desktop/aa380770(v=vs.85).aspx

$oTask.State is the property ; [TASK_STATE_DISABLED = 1 = Disabled]

oneLess

Link to post
Share on other sites
  • 2 months later...

after a long time i checked this tread and i thank everybody for the comments and ideas...

I will try to update the UDF and if someone has done some of those modifications already or has other useful hints, please post here soon, so i do not have to do something that is already done:-))

Link to post
Share on other sites

Looks like a useful UDF Allow2010. Thanks ;)

A very small suggestion: The _TaskCreate function has a dayof month parameter which has to be some power of 2. It would be easier (for me at least) if this parameter were just the actual day of the month. To keep it compatible with previous versions you could say that if a negative value is used it means the actual day number (1 - 31). Use -32 for "last day". Then in the function you could have

if $DaysOfMonth < 0 then
$DaysOfMonth = 2^(-$DaysOfMonth - 1)

maybe i get it wrong:

when i want to set day 10 and day 11 for a task to run i will combine 512+1024=1536

If i use real day numbers like -10 + -11 = -21 and then do

$DaysOfMonth = 2^(-$DaysOfMonth - 1)

2^(- (-21) -1)= 2^20= 1048576

this will not work?!

Link to post
Share on other sites

I am impressed with your UDF and I think it is much better than schtasks.exe

I want to create a daily task, which

  • starts at 6:30
  • repeats every 6 hours, for a duration of one day
At the moment I can create a daily task which starts at 6:30, repeats every 6 hours but indefinately. I would like to change that to a duration of one day if possible?

_TaskCreate("Smart-NetSmartRAS Monitor Script", "Report in info about the Smart-RAS to SNID", 2, "2000-01-01T06:30:00", "", "", "", "", "", 1, "PT6H", True, 1, 0, $username,$password, """"&$app&"""", "", "", False, True,0,True,True,False,False,False,"P3D",5)

EDIT

Have modified the UDF to support $Duration

If $RepetitionEnabled Then
$oTriggerRepetition = $oTrigger.Repetition()
$oTriggerRepetition.Interval() = $Interval
$oTriggerRepetition.Duration() = $Duration
EndIf

Now I am running this code to do what I need

_TaskCreate("Smart-NetSmartRAS Monitor Script", "Report in info about the Smart-RAS to SNID", 2, "2000-01-01T06:30:00", "", "", "", "", "", 1, "PT6H","P1D", True, 1, 0, $username,$password, """"&$app&"""", "", "", False, True,0,True,True,False,False,False,"P3D",5)

Thanks for the code, its extremely useful. BTW if others want to modify the code I recommend using powershell script here to enumerate the schedule task objects

i implented you changes, but duration was added to the end of the paramter list for taskcreate in order to not break compatibillity...

Thanks!

Link to post
Share on other sites

Just came across this today and have to say very impressive. Thanks for posting it. There is room for improvement e.g. _TaskSchedulerAutostart() can be consolidated into one line or three if you count Func and EndFunc.

Func _TaskSchedulerAutostart()
    Return RegRead("HKEY_LOCAL_MACHINESYSTEMCurrentControlSetServicesSchedule", "Start") > 0 ; Returns True or False.
EndFunc ;==>_TaskSchedulerAutostart

You are right, i know a lot of my code can be more elegant, but for me, most important is that i and all others can read it well, even after months :-) Edited by Allow2010
Link to post
Share on other sites

i found the right property here : http://msdn.microsoft.com/en-us/library/windows/desktop/aa380757(v=vs.85).aspx

$oTask.Enabled = False ; [= 0 , will disable the task]

$oTask.Enabled = True ; [=-1 , will enable the task]

$_a = $oTask.Enabled ; [will read the status of the task , 0=False=Disabled , -1=True=Enabled]

more options in reading of status here : http://msdn.microsoft.com/en-us/library/windows/desktop/aa380770(v=vs.85).aspx

$oTask.State is the property ; [TASK_STATE_DISABLED = 1 = Disabled]

oneLess

Thanks, will be included, but _TaskCheckIsEnabled will be _TaskIsEnabled
Link to post
Share on other sites

You are right, i know a lot of my code can be more elegant, but for me, most important is that i and all others can read it well, even after months :-)

I agree, this is what it's good to use comments instead.

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to post
Share on other sites
  • 1 month later...
  • 2 months later...
  • 3 months later...
  • 1 month later...

I am trying to create a scheduled task as SYSTEM user under Windows 8 but not having any luck.

Could you fix my script?

#include <CCBtaskplanerudf.au3>
#RequireAdmin

$program = "C:\Windows\Setup\scripts\profile\LUService.exe"

If @OSVersion = "WIN_2003" Or @OSVersion = "WIN_XP" Or @OSVersion = "WIN_XPe" Or @OSVersion = "WIN_2000" Then
    MsgBox(0,"Error", @ScriptName & " is not supported on NT5 platforms")
    Exit
ElseIf @OSVersion = "WIN_2008R2" Or @OSVersion = "WIN_7" Or @OSVersion = "WIN_8" Or @OSVersion = "WIN_2008" Then
    $result = _TaskCreate("LU Service","Loop Users Service",8,"","","","","","","","","","",2,1,"SYSTEM","",""""&$program&"""","","",False,True,2,False,False,False,False,False,False,"P3D",5)
    
    ConsoleWrite("$result: "& $result & @CRLF)
    If $result = 1 Then
        MsgBox(0, "Success", "LUService was installed successfully",5)
    Else
        MsgBox(32, "Failure", "LUService was not installed successfully")
    EndIf
EndIf
Link to post
Share on other sites

From what I could tell $RunLevel takes either a 0 or 1.  You have passed "SYSTEM" instead.

Edit: Scratch that actually.  I think I was off by one parameter.

It does look like your paramters are off.  I'm pretty that that you give $RunLevel a 2 when it does take 0 or 1.

Edited by jaberwocky6669
Link to post
Share on other sites

I have arranged them like this to make it easier to follow.  I hope the forum preserves the formatting.

Edit: Ok, looks like you're giving it one too many arguments.

     _TaskCreate("LU Service",        "Loop Users Service",               8,                      _
                 "",                  "",                                 "",                     _
                 "",                  "",                                 "",                     _
                 "",                  "",                                 "",                     _
                 "",                  2,                                  1,                      _
                 "SYSTEM",            "",                                 """" & $program & """", _
                 "",                  "",                                 False,                  _
                 True,                2,                                  False,                  _
                 False,               False,                              False,                  _
                 False,               False,                              "P3D",                  _
                 5)

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,                      $Duration = "")
Edited by jaberwocky6669
Link to post
Share on other sites
  • 2 months later...

FYI:

it seems that the UDF is not working with betas 3.3.9.10 and above.

I found out that beta 3.3.9.9 works fine, but 3.3.9.10 and all later betas fail.

the changelog does not help:

3.3.9.10 (21 July, 2013) (Beta) AutoIt:

- Changed: #NoAutoItExecute option replaced with #pragma compile(AutoItExecuteAllowed, true). Default is false.

- Fixed #2286 GuiCtrtlGetState without a controlID parameter runs but aborts AutoIt.

- Fixed #2350 Strange issue when using $SS_ETCHEDVERT and $SS_ETCHEDHORZ.

Aut2Exe:

- Changed: Compiling uses a subfolder of %localappdata% instead of %temp% for temporary files. Hopefully this fixes warnings from over-zealous AV.

3.3.9.9 (19 July, 2013) (Beta) AutoIt: - Added: FuncName().

- Fixed: Subtle bugs with Ping() Aut2Exe:

- Changed: FileInstall() files are now stored in the Resources section along with the script. No overlays are used anymore.

- Changed: Default changed to not use UPX.

UDFs:

- Added: Example for _VersionCompare.

- Fixed #2320: Incorrect return values for certain IE functions.

any idea what i could do here?
 

Edited by Allow2010
Link to post
Share on other sites

"Not working" is a bit vague of a problem description. Do you get an error? Does it run at all? Does it not pass Au3Check? What exactly isn't working?

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to post
Share on other sites

Oh, i think i tricked my self:-)

 

Func _TaskIsValidPlatfrom()
    If @OSVersion = "WIN_XP" Or @OSVersion = "WIN_XPe" Or @OSVersion = "WIN_2000" Or @AutoItVersion < "3.3.9.4" Then ;win Vusta or newer and Autoit 3.3.9.4 needed for this uDF to work
        Return 0
    Else
        Return 1
    EndIf
EndFunc   ;==>_TaskIsValidPlatfrom

 

I think this will fail when the version is 3.3.9.10 

10  compares as < 4 because the 1 in 10 is compared...

oh man stupid me...

Link to post
Share on other sites

You should be using _VersionCompare().

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

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
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...