Jump to content

Task Scheduler UDF


dbzfanatic
 Share

Recommended Posts

I've looked at that but when you look at the references then actions it says "Minimum Supported Client: Windows Vista" so that's why I said that.

Well I was bored last night. I tested on win2k, winxp and win2k3, also tested with a remote computername. Function _TaskAddScheduleWMI() work, but still need some work to get done.

@dbzfanatic there is one little bug with your script. If you have another cmd.exe process running your script freeze.

Change ProcessExists("cmd.exe")

$hRun = Run("cmd.exe /c at " & $sName & " " & $iID & " " & " " & $sDay & " " & $sInteract & " " & $sOccur & " " & $hProgram, @SystemDir, @SW_HIDE)
    
    While ProcessExists("cmd.exe")oÝ÷ Ùú+>ºzËÆ+-±Ê%¢ºM4ÒÊZËroÝ÷ ØIã£(­jëh×6Global $wbemFlagReturnImmediately = 0x10
Global $wbemFlagForwardOnly = 0x20

Func _TaskAddScheduleWMI($hProgram, $sTime, $sDay = '********', $strComputer = "localhost", $iOccurrence = False, $sDaysofweek = '', $sDaysOfMonth = '', $bInteractive = False)
    Local $iJobID, $sMsg, $iBais
    
    If $sDay = '' Or $sDay = -1 Or $sDay = Default Then $sDay = '********'
    If $strComputer = '' Or $strComputer = -1 Or $strComputer = Default Then $strComputer = 'localhost'
    $iBais = $sDay & $sTime & '.000000' & _TimeZoneGetBiasWMI($strComputer)
    $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2")
    $objNewJob = $objWMIService.Get("Win32_ScheduledJob")
    ConsoleWrite($hProgram & ', ' & $iBais & ', ' & $iOccurrence & ', ' & $sDaysofweek & ', ' & $sDaysOfMonth & ', ' & $bInteractive & @CRLF)
    $iReturnCode = $objNewJob.Create($hProgram, $iBais, True, $sDaysofweek, $sDaysOfMonth, $bInteractive, $iJobID)
    
    If $iReturnCode = 0 Then
        Return (SetError(0, $iReturnCode, $iJobID))
    Else
        $sMsg = _TaskScheduleGetReturnValue($iReturnCode)
        Return (SetError(1, $iReturnCode, $sMsg))
    EndIf
EndFunc   ;==>_TaskAddScheduleWMI

; #FUNCTION#;===============================================================================
;
; Name...........: _TaskGetScheduledWMI
; Description ...: Returns an array of scheduled tasks.
; Syntax.........: _TaskGetScheduledWMI()
; Parameters ....:
; Return values .: Success - Returns the list of scheduled tasks.
;                  Failure - Sets @Error:
;                  |1 - No WMI Objects Found
; Author ........: Danny35d
; Modified.......:
; Remarks .......:
; Related .......: _TaskAddScheduleWMI(), _TaskDelScheduleWMI()
; Link ..........;
; Example .......; Yes
;
;;==========================================================================================
Func _TaskGetScheduledWMI($strComputer = 'localhost')
    Local $iCount = 1
    Dim $Output[1][20]
    
    If $strComputer = '' Or $strComputer = -1 Or $strComputer = Default Then $strComputer = 'localhost'
    $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2")
    $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_ScheduledJob", "WQL", _
            $wbemFlagReturnImmediately + $wbemFlagForwardOnly)

    If IsObj($colItems) Then
        For $objItem In $colItems
            ReDim $Output[UBound($Output) + 1][20]
            $Output[$iCount][1] = $objItem.Caption
            $Output[$iCount][2] = $objItem.Command
            $Output[$iCount][3] = _GetDaysOfMonth($objItem.DaysOfMonth)
            $Output[$iCount][4] = _GetDaysOfWeek($objItem.DaysOfWeek)
            $Output[$iCount][5] = $objItem.Description
            $Output[$iCount][6] = WMIDateStringToDate($objItem.ElapsedTime)
            $Output[$iCount][7] = WMIDateStringToDate($objItem.InstallDate)
            $Output[$iCount][8] = _GetBoolean($objItem.InteractWithDesktop)
            $Output[$iCount][9] = $objItem.JobId
            $Output[$iCount][10] = $objItem.JobStatus
            $Output[$iCount][11] = $objItem.Name
            $Output[$iCount][12] = $objItem.Notify
            $Output[$iCount][13] = $objItem.Owner
            $Output[$iCount][14] = $objItem.Priority
            $Output[$iCount][15] = _GetBoolean($objItem.RunRepeatedly)
            $Output[$iCount][16] = WMIDateStringToDate($objItem.StartTime)
            $Output[$iCount][17] = $objItem.Status
            $Output[$iCount][18] = WMIDateStringToDate($objItem.TimeSubmitted)
            $Output[$iCount][19] = WMIDateStringToDate($objItem.UntilTime)
            $iCount += 1
        Next
        If UBound($Output) - 1 Then
            $Output[0][0] = UBound($Output) - 1
        Else
            $Output = ''
        EndIf
    Else
        Return (SetError(1, 1, 'No WMI Objects Found for class: Win32_ScheduledJob'))
    EndIf
    Return ($Output)
EndFunc   ;==>_TaskGetScheduledWMI

; #FUNCTION#;===============================================================================
;
; Name...........: _TaskDelScheduleWMI
; Description ...: Deletes a scheduled task or all schedule task.
; Syntax.........: _TaskDelScheduleWMI($strComputer = 'localhost', $iJobID = -1, $iDelAll = False)
; Parameters ....: $sName - The name of the computer to execute the deletion on.
;                     $iID - [Optional] The id of the task to delete. If blank will delete the first scheduled task.
;                     $iDelete - [Optional] Integer value to determine deletion type. If 0 will delete all tasks, 1 will delete on the specified task.
; Return values .: Success - Deletes the specified task.
;                  Failure - Sets @Error:
;                  |1 -
; Author ........: Danny35d
; Modified.......:
; Remarks .......:
; Related .......: _TaskAddScheduleWMI(), _TaskGetSchedule()
; Link ..........;
; Example .......; Yes
;
;;==========================================================================================
Func _TaskDelScheduleWMI($strComputer = 'localhost', $iJobID = -1, $iDelAll = False)
    Local $iReturnCode, $iError = 1, $sMsg, $iFoundID = False
    
    If $iJobID = '' Or $iJobID = Default Then $iJobID = -1
    If $strComputer = '' Or $strComputer = -1 Or $strComputer = Default Then $strComputer = 'localhost'
    $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2")
    $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_ScheduledJob", "WQL", _
            $wbemFlagReturnImmediately + $wbemFlagForwardOnly)

    If IsObj($colItems) Then
        For $objItem In $colItems
            $intJobID = $objItem.JobId
            If $iJobID = $intJobID Or $iDelAll Then
                $iFoundID = True
                $objInstance = $objWMIService.Get('Win32_ScheduledJob.JobID=' & $intJobID)
                $iReturnCode = $objInstance.Delete
            EndIf
        Next
    Else
        Return (SetError(1, 3, 'No WMI Objects Found for class: Win32_ScheduledJob'))
    EndIf
    
    If Not $iFoundID Then $iReturnCode = 4
    If $iReturnCode = 0 Then $iError = 0
    $sMsg = _TaskScheduleGetReturnValue($iReturnCode)
    
    Return (SetError($iError, $iReturnCode, $sMsg))
EndFunc   ;==>_TaskDelScheduleWMI

Func WMIDateStringToDate($dtmDate)
    If $dtmDate = '' Then
        Return ($dtmDate)
    Else
        Return (StringMid($dtmDate, 5, 2) & "/" & _
                StringMid($dtmDate, 7, 2) & "/" & StringLeft($dtmDate, 4) _
                 & " " & StringMid($dtmDate, 9, 2) & ":" & StringMid($dtmDate, 11, 2) & ":" & StringMid($dtmDate, 13, 2))
    EndIf
EndFunc   ;==>WMIDateStringToDate

; #FUNCTION#;===============================================================================
;
; Name...........: _TimeZoneGetBiasWMI
; Description ...: Returns current bias for local time translation.  formula: UTC = local time - bias.
; Syntax.........: _TimeZoneGetBiasWMI() or _TimeZoneGetBiasWMI('RemoteComputerName')
; Parameters ....:
; Return values .: Success - Returns Bias time.
;                  Failure - Sets @Error:
;                  |1 - Command Failed
; Author ........: Danny35d
; Modified.......:
; Remarks .......:
; Related .......:
; Link ..........;
; Example .......; Yes
;
;;==========================================================================================
Func _TimeZoneGetBiasWMI($strComputer = 'localhost')
    Local $iBais, $iDayLightBais
    
    $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2")
    $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_TimeZone", "WQL", _
            $wbemFlagReturnImmediately + $wbemFlagForwardOnly)

    If IsObj($colItems) Then
        For $objItem In $colItems
            $iBais = $objItem.Bias
            $iDayLightBais = $objItem.DaylightBias
        Next
    Else
        Return (SetError(1, 'No WMI Objects Found for class: Win32_TimeZone', ''))
    EndIf
    
    Return (Execute($iBais & ' - ' & $iDayLightBais))
EndFunc   ;==>_TimeZoneGetBiasWMI

Func _GetBoolean($iBoolean)
    If Not $iBoolean Then
        Return (False)
    Else
        Return (True)
    EndIf
EndFunc   ;==>_GetBoolean

Func _TaskScheduleGetReturnValue($iReturnCode)
    Local $sMsg
    
    Switch $iReturnCode
        Case 0
            $sMsg = 'The request was accepted.'
        Case 1
            $sMsg = 'The request is not supported.'
        Case 2
            $sMsg = 'The user did not have the necessary access.'
        Case 4
            $sMsg = 'Job ID not found.'
        Case 8
            $sMsg = 'Interactive process.'
        Case 9
            $sMsg = 'The directory path to the service executable file was not found.'
        Case 21
            $sMsg = 'Invalid parameters have been passed to the service.'
        Case 22
            $sMsg = 'The account which this service is to run under is either invalid or lacks the permissions to run the service.'
    EndSwitch
    Return ($sMsg)
EndFunc   ;==>_TaskScheduleGetReturnValue

Func _GetDaysOfMonth($iDaysOfMonth)
    Local $sDaysOfMonth
    Local $aDaysOfMonth = _GetPower2(31)
    
    For $x = $aDaysOfMonth[0] To 1 Step -1
        If $aDaysOfMonth[$x] <= $iDaysOfMonth Then
            $iDaysOfMonth = $iDaysOfMonth - $aDaysOfMonth[$x]
            $sDaysOfMonth = $x & ', ' & $sDaysOfMonth
        EndIf
        If $iDaysOfMonth = 0 Then ExitLoop
    Next
    $sDaysOfMonth = StringTrimRight($sDaysOfMonth, 2)
    Return ($sDaysOfMonth)
EndFunc   ;==>_GetDaysOfMonth

Func _GetDaysOfWeek($iDayOfWeek = 1)
    Local $sDayOfWeek, $sText
    Local $aDays = _GetPower2(7)
    
    For $x = $aDays[0] To 1 Step -1
        If $aDays[$x] <= $iDayOfWeek Then
            $iDayOfWeek = $iDayOfWeek - $aDays[$x]
            Switch $aDays[$x]
                Case 1
                    $sText = 'Monday'
                Case 2
                    $sText = 'Tuesday'
                Case 4
                    $sText = 'Wednesday'
                Case 8
                    $sText = 'Thursday'
                Case 16
                    $sText = 'Friday'
                Case 32
                    $sText = 'Saturday'
                Case 64
                    $sText = 'Sunday'
            EndSwitch
            $sDayOfWeek = $sText & ', ' & $sDayOfWeek
        EndIf
        If $iDayOfWeek = 0 Then ExitLoop
    Next
    $sDayOfWeek = StringTrimRight($sDayOfWeek, 2)
    Return ($sDayOfWeek)
EndFunc   ;==>_GetDaysOfWeek

Func _GetPower2($iMaxPower2)
    Dim $aPower2[$iMaxPower2 + 1]
    $aPower2[0] = $iMaxPower2
    For $x = 1 To $iMaxPower2
        $aPower2[$x] = 2 ^ ($x - 1)
    Next
    Return ($aPower2)
EndFunc   ;==>_GetPower2
AutoIt Scripts:NetPrinter - Network Printer UtilityRobocopyGUI - GUI interface for M$ robocopy command line
Link to comment
Share on other sites

It seems this is no longer my project. I wanted to do this with minimal influence and assistance from others as a learning experience for myself. The above code is rewritten entirely,leaving nothing of my own and thus, is no longer mine (as shown in the "author" portion of the function headers). I appreciate the time, effort and assistance from everyone. Feel free to use whichever you see fit or more understandable.

Link to comment
Share on other sites

It seems this is no longer my project.

You are the one who came out with the idea of making Task Scheduler UDF. If it wasn't for you I will never make the WMI version, like Emiel Wieldraaijer said you are the father of this project.

I wanted to do this with minimal influence and assistance from others as a learning experience for myself.

As of learning you can go through the code and learn from it.

The above code is rewritten entirely,leaving nothing of my own and thus, is no longer mine (as shown in the "author" portion of the function headers).

It was not my intention to make you feel left out I just follow your headers templates. There is a lot of work to be done with the WMI version. _TaskAddScheduleWMI() is not even half way done, the other functions need error checking and more testing. After reading post 17

Ok, from what I can see in order to use the scripting COM API for Task Scheduler the client has to be vista. I want this to be more universal so I think I'll leave it with commands for now. I might update it a bit more with schtask.exe or just make it a bit more streamlined but I don't know when that's going to be. Hope you all like it as-is for now :mellow:.

and all other post after that which Emiel Wieldraaijer is pointing out it can be done with win2k and above. I assume you are not going to do COM API for Task Scheduler. If you feel I hijack your thread in any way let me know and I will remove my post.
AutoIt Scripts:NetPrinter - Network Printer UtilityRobocopyGUI - GUI interface for M$ robocopy command line
Link to comment
Share on other sites

No I don't feel like you hijacked my thread, and I can't really be called the father since the idea came from ken82m, he wanted to know if there was one and there didn't appear to be so I decided to try my hand, as I said in post 1 (I think). I know I can learn from the code as to why things work but I still don't entirely understand the Object portions, which I may have if I had developed the WMI version myself. I'm not saying that anyone should feel bad or that they took my project from me, I'm simply saying it seems to have gone beyond my current scope. I'm grateful to Danny35d for developing that and saving me some time, and I'd be willing to work on a co-op project at some point.

Link to comment
Share on other sites

Strange

http://msdn.microsoft.com/en-us/library/aa383614(VS.85).aspx

"Task Scheduler 1.0: Client requires Windows Vista, Windows XP, Windows 2000 Professional, Windows Me, or Windows 98. Server requires Windows Server 2008, Windows Server 2003 or Windows 2000 Server. "

Confusion found:

spudw2k's link was pointing to Task Scheduler 2.0, which requires minimally Windows Vista or Windows Server 2008.

Just stick to Task Scheduler 1.0 then Emiel's reply applies.

Link to comment
Share on other sites

Confusion found:

spudw2k's link was pointing to Task Scheduler 2.0, which requires minimally Windows Vista or Windows Server 2008.

I beg your pardon, but the link I posted was to the Task Scheduler Interfaces page, which covers both 2.0 and 1.0 if you read it fully.
Link to comment
Share on other sites

  • 3 weeks later...

I don't know if it help you or not but here is something I wrote for a script of my own recently.

It uses schtasks.exe which is built into XP and Vista.

The script is able to collect all details of scheduled jobs and return them in an array.

-Kenny

#include <Constants.au3>
#include <Array.au3>
Local $line
Local $line2
;                        Add /NH to command to remove headers
Local $foo = Run(@ComSpec & ' /c schtasks.exe /query /FO csv /V', @SystemDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)
    
While ProcessExists($foo)
    $line = StdoutRead($foo, True)
    $line2 = StderrRead($foo, True)
WEnd

For $i = 1 To 3
    If StringLeft($line,  1)  = @CR OR StringLeft($line,  1)  = @CRLF OR StringLeft($line,  1)  = @LF Then $line  = StringTrimLeft($line,  1)
    If StringLeft($line2, 1)  = @CR OR StringLeft($line2, 1)  = @CRLF OR StringLeft($line2, 1)  = @LF Then $line2 = StringTrimLeft($line2, 1)
    If StringRight($line, 1)  = @CR OR StringRight($line, 1)  = @CRLF OR StringRight($line, 1)  = @LF Then $line  = StringTrimRight($line, 1)
    If StringRight($line2,1)  = @CR OR StringRight($line2,1)  = @CRLF OR StringRight($line2,1)  = @LF Then $line2 = StringTrimRight($line2,1)
Next

$line = _CSVToArray(0, ",", $line)

_ArrayDisplay($line)



;UDF Needed For CSV Functions

;===============================================================================
;
; Description:    Reads a CSV file into a 2D array
; Parameter(s):  $sType    - Type of data to parse
;                                       0 - String
;                                       1 - CSV File
;                  $cSeparator  - Separator character, default is comma (,)
;                  $sString  - String to be processed      (If $Stype = 0)
;                  $sPath      - Path to the CSV file to read (If $Stype = 1)
; Requirement(s):   None
; Return Value(s):  On Success - 2D CSV array
;                  On Failure - 0  and Set
;                                  @ERROR to:  1 - File not found/openable
;                                              2 - File read error
;                                              3 - CSV format error
; Author(s):        Ed Fletcher
; Note(s):        Pattern based on work by Jeffrey E. F. Friedl in
;                  "Mastering Regular Expressions, 2nd Edition"
;===============================================================================
Func _CSVToArray( $sType, $cSeparator=',', $sString = "", $sPath = "" )

If $sType = 1 And $sPath = "" Then
    SetError(1)
    Return 0
ElseIf $sType = 0 And $sString = "" Then
    SetError(3)
    Return 0
EndIf

;; open the file and read the entire CSV dataset into one string.
If $sType = 1 Then
;; open the file and read the entire CSV dataset into one string.

    Local $hFile = FileOpen( $sPath, 0 )
    If $hFile == -1 Then
        SetError( 1 )
        Return 0
    EndIf

    Local $sRawData = FileRead( $hFile )
    If @error > 0 Then
        FileClose( $hFile )
        SetError( 2 )
        Return 0
    EndIf

    FileClose( $hFile )
Else
    $sRawData = $sString
EndIf

;; parse the string into an array of matched fields

    Local $pattern = '(?m)'                 ; multi-line search mode
    $pattern &= '\G(?:^|[' & $cSeparator & '])' ; start of line or start of field
    $pattern &= '(?:'                         ; one of two options:
    $pattern &= '"'                         ;   a field starting with at double quote
    $pattern &= '([^"]*+(?:""[^"]*+)*+)'    ;   (quote-pairs and any non-quote chars)
    $pattern &= '"'                         ;   a double quote ending the field
    $pattern &= '(\r?\n?)'                   ;   (any sort of line ending here?)
    $pattern &= '|'                         ; or:
    $pattern &= '([^"' & $cSeparator & '\r\n]*+)';   (a simple CSV field, no quotes or commas)
    $pattern &= '(\r?\n?)'                   ;   (any sort of line ending here?)
    $pattern &= ')'                         ; note that we should have 4 captures per CSV element

    Local $aRawData = StringRegExp( $sRawData, $pattern, 4 )
    If @error <> 0 Then
;Die( 'Error: ' & @error )
        SetError( 3 )
        Return 0
    EndIf

    $sRawData = ''; we're done with this, and it might be large

; $aRawData is a 1D array containing every field in the CSV file.  Each element
; in $aRawData is an array of 5 strings, like so:
; 0 - all of the characters consumed while matching this field
; 1 - field contents, if the field was double quoted
; 2 - a line ending, if the field was double quoted and this is the end of the line
; 3 - field contents, if the field was *not* double quoted
; 4 - a line ending, if the field was *not* double quoted and this is the end of the line


;; pass through the results once to determine the number of rows and the max number of columns

    Local $i, $aMatch
    Local $colCount = 0, $maxCols = 0
    Local $rowCount = 0

    For $i=0 To UBound($aRawData)-1
        $aMatch = $aRawData[$i]

        If $colCount == 0 Then
            $rowCount += 1  ; we're looking at the first field on the current row
        EndIf

        $colCount += 1

        If $colCount > $maxCols Then
            $maxCols = $colCount; longest row so far...
        EndIf

        If $aMatch[2] <> '' OR (UBound($aMatch) > 3 AND $aMatch[4] <> '') Then
            $colCount = 0   ; row complete, we might start a new one
        EndIf
    Next

;; we now know how large to make our 2D output array
    
    Local $aCsvData[$rowCount][$maxCols]


;; finally, populate our output array

    Local $row = 0, $col = 0

    For $i=0 To UBound($aRawData)-1
        $aMatch = $aRawData[$i]

        If UBound($aMatch) > 3 AND $aMatch[3] <> '' Then
    ; It was a simple field, no processing required
            $aCsvData[$row][$col] = $aMatch[3]
        Else
    ; It was a quoted value, so take care of embedded double quotes
            $aCsvData[$row][$col] = StringReplace($aMatch[1], '""', '"')
        EndIf

        $col += 1

; now look for a line ending that ends the current data row
        If $aMatch[2] <> '' OR (UBound($aMatch) > 3 AND $aMatch[4] <> '') Then
            $row += 1
            $col = 0
        EndIf
    Next

    Return $aCsvData
EndFunc
Edited by ken82m

 "I believe that when we leave a place, part of it goes with us and part of us remains... Go anywhere, when it is quiet, and just listen.. After a while, you will hear the echoes of all our conversations, every thought and word we've exchanged.... Long after we are gone our voices will linger in these walls for as long as this place remains."

Link to comment
Share on other sites

Oh geeze what have I done? Is a Task Scheduler UDF going to be a new fad around the forums? :mellow: lol The one I wrote seemed to work ok with vista but I didn't test extensively (I don't use the TS so I didn't have much need) but I'm glad it seems to be such a copycat-friendly project (joke,I hope I didn't offend anyone).

Link to comment
Share on other sites

sorry :) That's what you get for responding to one of my posts, always trouble lol

Actually yours worked great but for the script I needed it for.

But I found later it could not work with any jobs listed in scheduled tasks, being jobs I didn't create with it.

Just because the AT command is a legacy command that uses it's own scheduling system

Edited by ken82m

 "I believe that when we leave a place, part of it goes with us and part of us remains... Go anywhere, when it is quiet, and just listen.. After a while, you will hear the echoes of all our conversations, every thought and word we've exchanged.... Long after we are gone our voices will linger in these walls for as long as this place remains."

Link to comment
Share on other sites

lol yeah I guess so. I'm glad it worked for you at least once but like I said I didn't get to do much testing. I didn't know the at command used its own system otherwise I may have used schtasks to begin with. At least there are now 3 different versions and people can choose which one they like. My version may work with older windows versions while yours and Danny's should work with XP/Vista. Perhaps the three of us could speak and get drunk, I MEAN...work on a new version...yeah...that's it >.> (hope someone thinks that's funny). A collaboration between us probably wouldn't be such a bad idea, at least in terms of theory and basic practice.

Link to comment
Share on other sites

Yeah drunken scripting, who's machine should we blue screen LOL

 "I believe that when we leave a place, part of it goes with us and part of us remains... Go anywhere, when it is quiet, and just listen.. After a while, you will hear the echoes of all our conversations, every thought and word we've exchanged.... Long after we are gone our voices will linger in these walls for as long as this place remains."

Link to comment
Share on other sites

Maybe we should make an autoit version of the BSODomizer XD. Hopefully we don't fry my machine, I'm running my website off of it so I need that 870GB of storage :).

Link to comment
Share on other sites

  • 5 months later...

Dim $sFile = '"' &  @ProgramFilesDir & '\internet explorer\iexplore.exe"'
_TaskSchedule("M, T, W", "1200", $sFile, "", "", "", 1)oÝ÷ Ø:'ßÛd0«b²ØZ·­Ø^¶)×hzÉ÷öضëu©òÁ¬Ø­ý³è­{^­§-÷¢*.Á©í¶zØ^{^®w­{e¢·«Â)Ý£®¶­seõF6µ66VGVÆRgV÷C´ÒÂBÂrgV÷C²ÂgV÷C³#gV÷C²Âb33c·4fÆRÂgV÷C²gV÷C²ÂgV÷C²gV÷C²ÂG'VRÂ

Edited by Authenticity
Link to comment
Share on other sites

@Danny35D

i did not use you example before .. because i did not needed it ..now i have some time to investigate your code and i've got a little question ..

you said _TaskAddScheduleWMI () works but i only get the following error

$iReturnCode = $objNewJob.Create($hProgram, $iBais, True, $sDaysofweek, $sDaysOfMonth, $bInteractive, $iJobID)

$iReturnCode = $objNewJob.Create($hProgram, $iBais, True, $sDaysofweek, $sDaysOfMonth, $bInteractive, $iJobID)^ ERROR

could you tell me the exact syntax to use an example please ?

Thnx

Emiel

Best regards,Emiel Wieldraaijer

Link to comment
Share on other sites

  • 2 years later...

Hi Friends,

I am using Windows 7 64 bit machine. I wanted to create a task with the trigger option "on workstation unlock". can some one help me on this? wil this UDF help me? For your reference i have attached the screen shot of how the event should be. That was the event i created manually!

Thanks in advance!

Edited by Syed23

Thank you,Regards,[font="Garamond"][size="4"]K.Syed Ibrahim.[/size][/font]

Link to comment
Share on other sites

  • 2 months later...

Thanks for the UDF, but I have noticed a small issue which was fixed.

Issue:

When there is no command prompt exits, then the udf is working fine.. however when user has already opened a command prompt, it basically doing nothing...

So, I have modified the function which was as

Func _TaskGetScheduled()

Local $hAt

$hAt = Run("cmd.exe /c at", @SystemDir, @SW_HIDE, 8)

While ProcessExists("cmd.exe")

$sRet = StdoutRead($hAt, True)

WEnd

If $hAt = 0 Then

Return SetError(1)

EndIf

Return $sRet

EndFunc;==>_TaskGetScheduled

to

Func _TaskGetScheduled()

Local $hAt

$hAt = Run("cmd.exe /c at", @SystemDir, @SW_HIDE, 8)

While ProcessExists($hAt)

$sRet = StdoutRead($hAt, True)

WEnd

If $hAt = 0 Then

Return SetError(1)

EndIf

Return $sRet

EndFunc;==>_TaskGetScheduled

I have made changes in while loop to check for process Id instead of process name and it is working as expected.

Link to comment
Share on other sites

  • 4 years later...

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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...