Jump to content

Recommended Posts

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 post
Share on other sites

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 post
Share on other sites

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 post
Share on other sites

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 post
Share on other sites

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 post
Share on other sites

I guess i`m late here but i just wrote a snippet.

#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 by monoscout999
Link to post
Share on other sites

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 by RichE

RichE

[font="'Arial Narrow';"]Current projects[/font]

[font="'Arial Narrow';"]are on my site [/font]Sellostring

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
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...