PhamTanTien Posted July 20, 2011 Share Posted July 20, 2011 I have a tool with a loop to open a multiple program. When open a multiple program, a tool reads PID of it and records PID to .txt file. But sometimes i open this program before and when i run tool it reads PID of all programs are opened. I just want the PID of program which a tool opens. Some1 help me, pls. Sorry for bad English! Link to comment Share on other sites More sharing options...
tlman12 Posted July 20, 2011 Share Posted July 20, 2011 I have a tool with a loop to open a multiple program. When open a multiple program, a tool reads PID of it and records PID to .txt file.But sometimes i open this program before and when i run tool it reads PID of all programs are opened. I just want the PID of program which a tool opens. Some1 help me, pls.Sorry for bad English!without seeing you code this is just a guess, but if your program is opening other programs with Run("..") then all you have to do is $Pid = Run("...") and $Pid will become the pid of the application that was started not of all that match that name. Link to comment Share on other sites More sharing options...
RichE Posted July 20, 2011 Share Posted July 20, 2011 use $procarray = processlist("your process") and it will only list that particular process and then $proarray[0][0] for the count of how many of that process are open, tha'ts what I did for my multi-session utils. RichE [font="'Arial Narrow';"]Current projects[/font] [font="'Arial Narrow';"]are on my site [/font]Sellostring Link to comment Share on other sites More sharing options...
PhamTanTien Posted July 20, 2011 Author Share Posted July 20, 2011 (edited) For ex: I have open IE before with PID 1021, after that I use my tool to open multi IEs with PID 200, 1200, 1032. I just want close all IEs which are opened by my tool. Edited July 20, 2011 by PhamTanTien Link to comment Share on other sites More sharing options...
RichE Posted July 20, 2011 Share Posted July 20, 2011 try this: $pid = ProcessExists("iexplore.exe") If $pid Then MsgBox(48, "Warning!", "iexplore processes found, killing them", 2) Do ProcessClose(""iexplore.exe") $pid = ProcessList(""iexplore.exe") Until $pid[0][0] = 0 EndIf Exit this will close any iexplore.exe process open and then exit the gui RichE [font="'Arial Narrow';"]Current projects[/font] [font="'Arial Narrow';"]are on my site [/font]Sellostring Link to comment Share on other sites More sharing options...
AdamUL Posted July 20, 2011 Share Posted July 20, 2011 If you know how many processes you are going to run at one time, then you can create an array of PIDs. Like this example for a single EXE file. Local $iNumOfProcesses = 10 Local $aiPIDs[$iNumOfProcesses + 1] = [$iNumOfProcesses] For $iNumProcess = 1 To $aiPIDs[0] Step 1 $aiPIDs[$iNumProcess] = Run("Test.exe") Next You will then have a 1D array of PIDs for the process that you have started, instead of reading and writing to a file. If you need it for different EXE files, then create more PID arrays for those processes. Adam Link to comment Share on other sites More sharing options...
PhamTanTien Posted July 20, 2011 Author Share Posted July 20, 2011 Thanks AdamUL. I will improve my code. Thanks RichE, but I want IE that I opened before still run! Link to comment Share on other sites More sharing options...
monoscout999 Posted July 20, 2011 Share Posted July 20, 2011 (edited) I guess i`m late here but i just wrote a snippet. expandcollapse popup#include <ButtonConstants.au3> #include <GuiListView.au3> Global $Msg, $Pid[1] = [0] Local $hGUI, $New, $CloseOne, $CloseAll $hGUI = GUICreate("Process Close Example by monoscout999", -1, 170) $New = GUICtrlCreateButton("Open a New IExplorer", 10, 10, 150, 50) $CloseOne = GUICtrlCreateButton("Close one IExplorer" & @LF & "From the List", 10, 60, 150, 50, $BS_MULTILINE) $CloseAll = GUICtrlCreateButton("Close all the IExplorers", 10, 110, 150, 50) $PidList = GUICtrlCreateListView(" PID |INSTANCE", 170, 10, 220, 150) WinSetOnTop($hGUI, "", 1) GUISetState() While True $Msg = GUIGetMsg() Switch $Msg Case -3 If Not $Pid[0] = 0 Then MsgBox(262144, "Closing", "Closing all the notepad windows before exit", 2) _CloseAll() EndIf WinSetOnTop($hGUI, "", 0) Exit Case $New _New() Case $CloseOne _CloseOne() Case $CloseAll _CloseAll() EndSwitch WEnd Func _New() $Pid[0] += 1 ReDim $Pid[$Pid[0] + 1] $Pid[$Pid[0]] = Run("notepad.exe") GUICtrlCreateListViewItem($Pid[$Pid[0]] & "|" & $Pid[0], $PidList) EndFunc ;==>_New Func _CloseOne() Local $SelItem = GUICtrlRead($PidList) If $SelItem = 0 Then MsgBox(262144, "Error", "Select an Item from the list before" & @CRLF & "trying to delete", 2) Else Local $ItemText = GUICtrlRead($SelItem) Local $SelPid = StringSplit($ItemText, "|") ProcessClose($Pid[$SelPid[2]]) $Pid[$SelPid[2]] = "" GUICtrlDelete($SelItem) $Pid[0] -= 1 EndIf EndFunc ;==>_CloseOne Func _CloseAll() For $i = 1 To UBound($Pid) - 1 If Not $Pid[$i] = "" Then ProcessClose($Pid[$i]) Next $Pid[0] = 0 GUICtrlSendMsg($PidList, $LVM_DELETEALLITEMS, 0, 0) Return True EndFunc ;==>_CloseAll The ListView feature can be improved more. Edited July 20, 2011 by monoscout999 Link to comment Share on other sites More sharing options...
RichE Posted July 20, 2011 Share Posted July 20, 2011 (edited) or you could just run a check on app startup to find the current PID of the existing ie process like so and store that info and then processclose where the pid is not equal to the process already open. code below shows the existing open IE PID. $ie = ProcessExists("iexplore.exe") Edited July 20, 2011 by RichE RichE [font="'Arial Narrow';"]Current projects[/font] [font="'Arial Narrow';"]are on my site [/font]Sellostring Link to comment Share on other sites More sharing options...
PhamTanTien Posted July 20, 2011 Author Share Posted July 20, 2011 Thanks monoscout999 so much! 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