0Camus0

iexplore.exe Only registers one PID

14 posts in this topic

Hello, 

 

I want to open one IExplorer, set a page, then next open IExplorer and have control over their pids and hwnd.

I found out that once you open once instance of iexplorer, the next instance wont appear on WinList(). Similarly WinGetProcess wont return the pid.

I'm attaching my code but you can check by doing this:

#include <MsgBoxConstants.au3>


Local $InternetExplorer_PID_1 = Run("iexplore.exe")
Sleep(4000)
Local $InternetExplorer_PID_2 = Run("iexplore.exe")
Sleep(4000)

Local $found_1_pid = ExistIEProcess($InternetExplorer_PID_1)
Local $found_2_pid = ExistIEProcess($InternetExplorer_PID_2)

Local $found_1_hwnd =FindCurrentIE($InternetExplorer_PID_1)
Local $found_2_hwnd =FindCurrentIE($InternetExplorer_PID_2)

MsgBox($MB_SYSTEMMODAL, "ExistIEProcess", "PID 1 found: " & $found_1_pid & @CRLF & " PID 2 found: " & $found_2_pid)
MsgBox($MB_SYSTEMMODAL, "FindCurrentIE ", "HWND 1 found: " & $found_1_hwnd & @CRLF & "HWND 2 found: " & $found_2_hwnd)

Func ExistIEProcess($pid_)
    $found_proc = 0
    Local $aProcessList = ProcessList()
    For $i_ = 1 To $aProcessList[0][0]
        If $aProcessList[$i_][1] == $pid_ Then
            $found_proc = 1
        EndIf
    Next
    return $found_proc
EndFunc

Func FindCurrentIE($currentPID)
    Local $aList = WinList("[CLASS:IEFrame]")
    Local $found = 0
    For $i = 1 To $aList[0][0]
        If $aList[$i][0] <> "" Then
            Local $current_hwnd = $aList[$i][1]
            Local $current_PID = WinGetProcess($current_hwnd)
            If $currentPID == $current_PID Then
                $found = 1
            EndIf
        EndIf
    Next
    return $found
EndFunc

 

As you can see, it succeed in finding the pid for the first only, like any other pid of the same .exe aren't registered, and I suppose it's the same map for the HWND list attached to that pids.

 

It would be really helpful to have a similar function to WinGetProcess but something like ProcessGetHWNDListFromThisPID, in other words, a list of the HWND assotiated to that pid.

 

This is really important for me, I was looking for the source code but I didn't find any repo or working branch. Could you help me?

 

Thanks!

HelloWorld.au3

Share this post


Link to post
Share on other sites



Anyone? I use the process list to control specific open windows, with this issue I cannot have two instances of the same program.

Thanks.

Share this post


Link to post
Share on other sites

Can I find the source somewhere to try to fix this?

 

Thanks.

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

On 1/15/2016 at 8:46 PM, 0Camus0 said:

 

#include <MsgBoxConstants.au3>


Local $InternetExplorer_PID_1 = Run("iexplore.exe")
Sleep(4000)
Local $InternetExplorer_PID_2 = Run("iexplore.exe")
Sleep(4000)

Local $found_1_pid = ExistIEProcess($InternetExplorer_PID_1)
Local $found_2_pid = ExistIEProcess($InternetExplorer_PID_2)

Local $found_1_hwnd =FindCurrentIE($InternetExplorer_PID_1)
Local $found_2_hwnd =FindCurrentIE($InternetExplorer_PID_2)

MsgBox($MB_SYSTEMMODAL, "ExistIEProcess", "PID 1 found: " & $found_1_pid & @CRLF & " PID 2 found: " & $found_2_pid)
MsgBox($MB_SYSTEMMODAL, "FindCurrentIE ", "HWND 1 found: " & $found_1_hwnd & @CRLF & "HWND 2 found: " & $found_2_hwnd)

Func ExistIEProcess($pid_)
    $found_proc = 0
    Local $aProcessList = ProcessList()
    For $i_ = 1 To $aProcessList[0][0]
        If $aProcessList[$i_][1] == $pid_ Then
            $found_proc = 1
        EndIf
    Next
    return $found_proc
EndFunc

Func FindCurrentIE($currentPID)
    Local $aList = WinList("[CLASS:IEFrame]")
    Local $found = 0
    For $i = 1 To $aList[0][0]
        If $aList[$i][0] <> "" Then
            Local $current_hwnd = $aList[$i][1]
            Local $current_PID = WinGetProcess($current_hwnd)
            If $currentPID == $current_PID Then
                $found = 1
            EndIf
        EndIf
    Next
    return $found
EndFunc

 

 

Both of your returns return $found, NOT the PID... so, that'll never work.  

 

For the Hwnd, look into  WinGetHandle.

Edited by kaisies

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

The example is just to show 0 if isn't found or 1 if it is found, it's just a flag, the comparison of the PID is here:

 

If $currentPID == $current_PID Then
                $found = 1
            EndIf

 

 

Edit:

 

I used  WinGetHandle but it only retrieves the last active window, if you have more than 2 instances of the same program it only returns the latest, thats why I'm using this.

Edited by 0Camus0

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

6 minutes ago, 0Camus0 said:

The example is just to show 0 if isn't found or 1 if it is found, it's just a flag, the comparison of the PID is here:

 

If $currentPID == $current_PID Then
                $found = 1
            EndIf

 

I see. When I run this, it properly finds both the PID's of IExplore.

Edited by kaisies

Share this post


Link to post
Share on other sites

This shows all processes started by _IECreate:

#include <ie.au3>
#include <array.au3>
$oIE1 = _iecreate()
$oIE2 = _iecreate()
$aList = ProcessList("iexplore.exe")
_ArrayDisplay($aList)

 


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

BTW: Why don't you use the IE UDF that comes with AutoIt?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
1 hour ago, kaisies said:

I see. When I run this, it properly finds both the PID's of IExplore.

Really? My output is one for the first process and zero for the second, in other words the second PID is not in the

ProcessList()

 

Can you run my example and paste the output just to confirm?

 

Quote

BTW: Why don't you use the IE UDF that comes with AutoIt?

 

Because I want to do this for every other programs, not just IE. My purpose with this is to have co related the PIDs and the HWND, that way I can say, instance_x of X program, give me your HWND so I can minimize it or whatever. If you know a way of have control (HWND) over several instances of the same program let me know.

 

Thanks in advance.

 

 

Share this post


Link to post
Share on other sites

I closed all my instances of Iexplorer and run the example I posted above and I got this results, see the attachment.

 

You see something wrong with my example, it clearly fail to find the second PID and the second HWND.

instances.png

Share this post


Link to post
Share on other sites

@0Camus0 this is called GIGO:

For the start you do not run IE (one instance or two),  do not check the help file and do not have any error checking.

Do not be surprised by the results You get what you deserve.

 

 

1 person likes this

Share this post


Link to post
Share on other sites
On 1/23/2016 at 8:57 PM, PACaleala said:

@0Camus0 this is called GIGO:

For the start you do not run IE (one instance or two),  do not check the help file and do not have any error checking.

Do not be surprised by the results You get what you deserve.

 

 

Can you elaborate, I posted here because there are no more functions to deal with HWND/PID. Why I should not have one or more instances of IE? The program I posted is an example, not the actual code I'm using.

 

Quote

You get what you deserve.

 

Ok I'm done asking for help here.

Share this post


Link to post
Share on other sites
On 1/23/2016 at 8:57 PM, PACaleala said:

@0Camus0 this is called GIGO:

For the start you do not run IE (one instance or two),  do not check the help file and do not have any error checking.

Do not be surprised by the results You get what you deserve.

 

 

Can you elaborate, I posted here because there are no more functions to deal with HWND/PID. Why I should not have one or more instances of IE? The program I posted is an example, not the actual code I'm using.

 

Quote

You get what you deserve.

 

Ok I'm done asking for help here.

Share this post


Link to post
Share on other sites
On 1/23/2016 at 8:57 PM, PACaleala said:

@0Camus0 this is called GIGO:

For the start you do not run IE (one instance or two),  do not check the help file and do not have any error checking.

Do not be surprised by the results You get what you deserve.

 

 

Can you elaborate, I posted here because there are no more functions to deal with HWND/PID. Why I should not have one or more instances of IE? The program I posted is an example, not the actual code I'm using.

 

Quote

You get what you deserve.

 

Ok I'm done asking for help here.

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