gracea Posted August 19, 2014 Share Posted August 19, 2014 How can i stop the message box if process already detected...? The purpose of the script is to detect the listed process. Notepad.exe run (once only) - message box with notepad.exe name on it shows. I closed the message box - message with notepad.exe name on it should not show again (because it should be detected once). Unless notepad.exe run again (second instance) then message box should show. #include <array.au3> Local $ProcessNameList[3] $ProcessNameList[0] = "CALC.EXE" $ProcessNameList[1] = "NOTEPAD.EXE" $ProcessNameList[2] = "MSPAINT.EXE" While 1 For $ProcessName IN $ProcessNameList If ProcessExists($ProcessName) Then MsgBox(0,"",$ProcessName & " is running.") EndIf Next WEnd I cant figure out how to do it despite already look from the samples from google and forums. :P " Loved It ! " :wub: Link to comment Share on other sites More sharing options...
JohnOne Posted August 19, 2014 Share Posted August 19, 2014 #include <array.au3> $Notepadcount = 0 Local $ProcessNameList[3] $ProcessNameList[0] = "CALC.EXE" $ProcessNameList[1] = "NOTEPAD.EXE" $ProcessNameList[2] = "MSPAINT.EXE" While 1 For $ProcessName In $ProcessNameList If ProcessExists($ProcessName) Then $Notepadcount += 1 If $Notepadcount >= 2 Then MsgBox(0, "", $ProcessName & " is running.") EndIf EndIf Next WEnd You might want to add a Sleep() to your loop. 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...
gracea Posted August 19, 2014 Author Share Posted August 19, 2014 JohnOne Maybe i am not clear or maybe you are just giving me a clue or maybe both. I see the logic but cant understood it. Tried several times think almost with it.. then failed. Thank You. #include <array.au3> $SameProcessNameTotalCount = 0 Local $ProcessNameList[3] $ProcessNameList[0] = "CALC.EXE" $ProcessNameList[1] = "NOTEPAD.EXE" $ProcessNameList[2] = "MSPAINT.EXE" While 1 For $ProcessName IN $ProcessNameList If ProcessExists($ProcessName) Then $SameProcessNameTotalCount += 1 If $SameProcessNameTotalCount >= 2 Then MsgBox(0,"",$ProcessName & " is running.") $SameProcessNameTotalCount = 0 EndIf EndIf Next Sleep (1000) WEnd Anyone else please.. :P " Loved It ! " :wub: Link to comment Share on other sites More sharing options...
ViciousXUSMC Posted August 19, 2014 Share Posted August 19, 2014 (edited) Can you elaborate "what failed" is it not working as you had intended and if so explain your intentions a bit better. Else, if an error what was the error? I think you want a pop up one time if the application is running when you start the script, and for that pop up to come again if another instance is launched or the original instance is closed and then a new one open. If that is the case, then yes I do not think the above will work. But also I wonder if a GUI may be better equipped for what you want to do. Perhaps a GUI that simply shows if a given process is currently running or not. I just threw this together, I am a noob so I am sure it can be spruced up and made better. expandcollapse popup#include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <ColorConstants.au3> #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Form1", 253, 51, 192, 124) $Button1 = GUICtrlCreateButton("Notepad", 0, 0, 81, 49) $Button2 = GUICtrlCreateButton("Calc", 86, 0, 81, 49) $Button3 = GUICtrlCreateButton("Paint", 170, 0, 81, 49) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 If ProcessExists("Notepad.exe") Then GUICtrlSetColor($Button1, $Color_Green) Else GUICtrlSetColor($Button1, $Color_Red) EndIf If ProcessExists("calc.exe") Then GUICtrlSetColor($Button2, $Color_Green) Else GUICtrlSetColor($Button2, $Color_Red) EndIf If ProcessExists("mspaint.exe") Then GUICtrlSetColor($Button3, $Color_Green) Else GUICtrlSetColor($Button3, $Color_Red) EndIf $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch Sleep(1000) WEnd Edited August 19, 2014 by ViciousXUSMC Link to comment Share on other sites More sharing options...
sahsanu Posted August 19, 2014 Share Posted August 19, 2014 If I understood the question, I think this could fit your needs (comments in code): Local $ProcessNameList[3][2] = [["CALC.EXE", ""], ["NOTEPAD.EXE", ""], ["MSPAINT.EXE", ""]] ;Define a 2D array to store the process name and in the second column the pids of running applications While 1 For $i = 0 To UBound($ProcessNameList) - 1 ;read the array in a for loop If ProcessExists($ProcessNameList[$i][0]) Then ;if the process exists then we will check it $aPid = ProcessList($ProcessNameList[$i][0]) ;get the pids for all instances of process name If IsArray($aPid) Then ;if we got the list continue For $x = 1 To $aPid[0][0] ;we will check in a for loop if the pid process is already in our list If Not StringInStr($ProcessNameList[$i][1], "|" & $aPid[$x][1] & "|") Then ;if the pid process is not in our list (second column of our process name array)... MsgBox(0, "Process running", $ProcessNameList[$i][0] & " is running with pid " & $aPid[$x][1]) ;... then show a message... $ProcessNameList[$i][1] &= "|" & $aPid[$x][1] & "|" ; ... and add the pid in our list (second column of our process name array) EndIf Next EndIf EndIf Next Sleep(500) WEnd Cheers, sahsanu Link to comment Share on other sites More sharing options...
Solution gracea Posted August 20, 2014 Author Solution Share Posted August 20, 2014 To ViciousXUSMC. I did not test your script as i look into it there is a series of processexists command that i used before but i preferred now the arrays. I need less code and more fine lookout for the lists. So far i am not into gui yet. Thank You. To sahsanu. Yours what i need and just work. Thank You. Perhaps how can i made in this format. Local $ProcessNameList[3][2] = [["CALC.EXE", ""], ; CALCULATOR ["NOTEPAD.EXE", ""], ; NOTEPAD ["MSPAINT.EXE", ""]] ; MSPAINT As we can see it is practically more cleaner and easy to look at than your original and my posted script. Also those comments will be needed so that i will instantly know what does the process do by commenting on it. And the lists surely will be more than 10. If array format is not possible to this current script, my posted script does but the message box part required a good editing. :P " Loved It ! " :wub: Link to comment Share on other sites More sharing options...
gracea Posted August 20, 2014 Author Share Posted August 20, 2014 Ey! Please disregard the format i wanted to elements/items. I created a new thread just for that from here: '?do=embed' frameborder='0' data-embedContent>> Thank You. :P " Loved It ! " :wub: Link to comment Share on other sites More sharing options...
sahsanu Posted August 20, 2014 Share Posted August 20, 2014 To sahsanu.Yours what i need and just work. Thank You. You are welcome. And regarding the format, I see someone give to you the answer in another thread so... Have a nice day Cheers, sahsanu 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