Jump to content
Sign in to follow this  
Luigi

Help to verify if a windows tasks exist

Recommended Posts

I build a function to check if a windows tasks exist, it work fine.

Its simple, "schtasks.exe /query /tn box_monitor".

It execute a Run, catch output, when I see... But the output is very big!

the output

Nome da tarefa                           Hora da próxima execuç Status         
======================================== ====================== ===============
box_monitor                              N/A                    Não foi possíve

Is possible do a StringInStr($output, $taskname), if True, ok, my tasks exist, or False, it not exist, simple.

Have this option too: "schtasks.exe /ShowSid /tn box_monitor", but the output is big:

ÊXITO: O SID "S-1-5-87-3121426652-2308929281-1992053499-2165363102-272372632" para o nome de usuário "box_monitor" foi computado com êxito.

The question is: there are another way to check if a windows task exists? One with short output?
 

Obs: this is not lazy or sloth to do a long code, but I'm afraid to make an inaccurate code.

Br, Detefon

Share this post


Link to post
Share on other sites

Detefon,

On way to do it...

ConsoleWrite('Task UninstallDeviceTask was ' & ( _ChkTsk('UninstallDeviceTask') ? ' Found' : ' Not Found') & @CRLF)

func _ChkTsk($task)

    local $out
    $rslt = Run(@ComSpec & " /c schtasks ", "", @SW_HIDE, 0x2 + 0x4)
    While 1
        $out &= StdoutRead($rslt)
        If @error then exitloop
    WEnd

    return stringinstr($out, $task) ? true : false

endfunc

kylomas


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites

@kylomas : you would control that the task name is exactly the same than which was entered :

ConsoleWrite('Task UninstallDeviceTask was ' & ( _ChkTsk('UninstallDeviceTask') ? ' Found' : ' Not Found') & @CRLF)

func _ChkTsk($task)
    local $out
    ; $rslt = Run(@ComSpec & ' /c schtasks', "", @SW_HIDE, 0x2 + 0x4)
    $rslt = Run(@ComSpec & ' /c schtasks /query /FO list', "", @SW_HIDE, 0x2 + 0x4)
    While 1
        $out &= StdoutRead($rslt)
        If @error then exitloop
    WEnd

    return StringRegExp($out, "(?i)\Q" & $task & "\E\R") ? true : false
endfunc

:)

Share this post


Link to post
Share on other sites

@jguinch, that string is huge, no sense to put unnecessary bytes into it ;)

ConsoleWrite('Task UninstallDeviceTask was ' & ( _ChkTsk('UninstallDeviceTask') ? ' Found' : ' Not Found') & @CRLF)

func _ChkTsk($task)
    local $out, $sresult
    ; $rslt = Run(@ComSpec & ' /c schtasks', "", @SW_HIDE, 0x2 + 0x4)
    $rslt = Run(@ComSpec & ' /c schtasks /query /FO list', "", @SW_HIDE, 0x2 + 0x4)
    While 1
        $sresult = StdoutRead($rslt)
        If @error then exitloop
        If $sresult Then $out &= $sresult
    WEnd
    
    Return StringRegExp($out, "(?i)\Q" & $task & "\E\R") ? True : False
EndFunc

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

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  

×
×
  • Create New...