rc1986 Posted July 29, 2013 Posted July 29, 2013 Hi, I'm trying to find a way to query the setup Windows Scheduled Tasks on a local machine. I have used scriptomatic's tool to find the WMI call as can be seen below: expandcollapse popup; Generated by AutoIt Scriptomatic $wbemFlagReturnImmediately = 0x10 $wbemFlagForwardOnly = 0x20 $colItems = "" $strComputer = "localhost" $Output="" $Output = $Output & "Computer: " & $strComputer & @CRLF $Output = $Output & "==========================================" & @CRLF $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2") $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_ScheduledJob", "WQL", _ $wbemFlagReturnImmediately + $wbemFlagForwardOnly) If IsObj($colItems) then For $objItem In $colItems $Output = $Output & "Caption: " & $objItem.Caption & @CRLF $Output = $Output & "Command: " & $objItem.Command & @CRLF $Output = $Output & "DaysOfMonth: " & $objItem.DaysOfMonth & @CRLF $Output = $Output & "DaysOfWeek: " & $objItem.DaysOfWeek & @CRLF $Output = $Output & "Description: " & $objItem.Description & @CRLF $Output = $Output & "ElapsedTime: " & WMIDateStringToDate($objItem.ElapsedTime) & @CRLF $Output = $Output & "InstallDate: " & WMIDateStringToDate($objItem.InstallDate) & @CRLF $Output = $Output & "InteractWithDesktop: " & $objItem.InteractWithDesktop & @CRLF $Output = $Output & "JobId: " & $objItem.JobId & @CRLF $Output = $Output & "JobStatus: " & $objItem.JobStatus & @CRLF $Output = $Output & "Name: " & $objItem.Name & @CRLF $Output = $Output & "Notify: " & $objItem.Notify & @CRLF $Output = $Output & "Owner: " & $objItem.Owner & @CRLF $Output = $Output & "Priority: " & $objItem.Priority & @CRLF $Output = $Output & "RunRepeatedly: " & $objItem.RunRepeatedly & @CRLF $Output = $Output & "StartTime: " & WMIDateStringToDate($objItem.StartTime) & @CRLF $Output = $Output & "Status: " & $objItem.Status & @CRLF $Output = $Output & "TimeSubmitted: " & WMIDateStringToDate($objItem.TimeSubmitted) & @CRLF $Output = $Output & "UntilTime: " & WMIDateStringToDate($objItem.UntilTime) & @CRLF if Msgbox(1,"WMI Output",$Output) = 2 then ExitLoop $Output="" Next Else Msgbox(0,"WMI Output","No WMI Objects Found for class: " & "Win32_ScheduledJob" ) Endif Func WMIDateStringToDate($dtmDate) Return (StringMid($dtmDate, 5, 2) & "/" & _ StringMid($dtmDate, 7, 2) & "/" & StringLeft($dtmDate, 4) _ & " " & StringMid($dtmDate, 9, 2) & ":" & StringMid($dtmDate, 11, 2) & ":" & StringMid($dtmDate,13, 2)) EndFunc When running this on any machine I appear to get nothing. Can anyone advise into how I'd use this to find out for example the statuses of the current scheduled tasks on my machine? Thanks, Rob Thanks Rob
AdamUL Posted July 29, 2013 Posted July 29, 2013 Have a look at the >Taskplaner/Taskscheduler COM UDF. It works with systems Vista and higher. Also, look at the SCHTASKS command. Adam rc1986 1
rc1986 Posted July 30, 2013 Author Posted July 30, 2013 Thanks, I did look at this post but ideally didn't want to use a UDF. Ideally I want to make use of the WMI queries I'm just unsure of how best to use it. Thanks again. Thanks Rob
spudw2k Posted July 30, 2013 Posted July 30, 2013 (edited) Perhaps this may be of use to you? (uses schtasks) Not a perfect app/script, but may give you some ideas Edited July 30, 2013 by spudw2k Spoiler Things I've Made: Always On Top Tool ◊ AU History ◊ Deck of Cards ◊ HideIt ◊ ICU ◊ Icon Freezer ◊ Ipod Ejector ◊ Junos Configuration Explorer ◊ Link Downloader ◊ MD5 Folder Enumerator ◊ PassGen ◊ Ping Tool ◊ Quick NIC ◊ Read OCR ◊ RemoteIT ◊ SchTasksGui ◊ SpyCam ◊ System Scan Report Tool ◊ System UpTime ◊ Transparency Machine ◊ VMWare ESX Builder Misc Code Snippets: ADODB Example ◊ CheckHover ◊ Detect SafeMode ◊ DynEnumArray ◊ GetNetStatData ◊ HashArray ◊ IsBetweenDates ◊ Local Admins ◊ Make Choice ◊ Recursive File List ◊ Remove Sizebox Style ◊ Retrieve PNPDeviceID ◊ Retrieve SysListView32 Contents ◊ Set IE Homepage ◊ Tickle Expired Password ◊ Transpose Array Projects: Drive Space Usage GUI ◊ LEDkIT ◊ Plasma_kIt ◊ Scan Engine Builder ◊ SpeeDBurner ◊ SubnetCalc Cool Stuff: AutoItObject UDF ◊ Extract Icon From Proc ◊ GuiCtrlFontRotate ◊ Hex Edit Funcs ◊ Run binary ◊ Service_UDF
AdamUL Posted July 31, 2013 Posted July 31, 2013 Have a look at MSDN for the Win32_ScheduledJob class on how to use the Properties and Methods.
rc1986 Posted July 31, 2013 Author Posted July 31, 2013 Thank you both very much, very helpful I'll attempt to get something going! Thanks Rob
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now