Luigi Posted December 5, 2014 Share Posted December 5, 2014 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 Visit my repository Link to comment Share on other sites More sharing options...
JohnOne Posted December 5, 2014 Share Posted December 5, 2014 Make some code, it will not blow up your computer. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
Luigi Posted December 5, 2014 Author Share Posted December 5, 2014 JohnOne, some times I want blow up it! But, a thor's hammer already serves. Visit my repository Link to comment Share on other sites More sharing options...
kylomas Posted December 6, 2014 Share Posted December 6, 2014 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 Link to comment Share on other sites More sharing options...
jguinch Posted December 6, 2014 Share Posted December 6, 2014 @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 Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted December 6, 2014 Moderators Share Posted December 6, 2014 @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. Link to comment Share on other sites More sharing options...
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