Sign in to follow this  
Followers 0
rc1986

Windows Scheduled Tasks

6 posts in this topic

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:

; 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

Share this post


Link to post
Share on other sites



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

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Perhaps this may be of use to you?  (uses schtasks)

Not a perfect app/script, but may give you some ideas

Edited by spudw2k

Share this post


Link to post
Share on other sites

Thank you both very much, very helpful I'll attempt to get something going!


Thanks

Rob

Share this post


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
Sign in to follow this  
Followers 0