Jump to content
Sign in to follow this  
Aslak

Get WinHandle from PID

Recommended Posts

Aslak

Hello,

I could hardly find what I want in the doc or by searching the forums, so I post my question:

Is there a way to get the WinHandle from a window by using it's PID ?

I'm in a situation where I have several windows with same titles (and no text) and I must interact with only a certain one.

I've got the PID from this window.

Any help will be welcomed!

aslak

Share this post


Link to post
Share on other sites
SmOke_N

Hello,

I could hardly find what I want in the doc or by searching the forums, so I post my question:

Is there a way to get the WinHandle from a window by using it's PID ?

I'm in a situation where I have several windows with same titles (and no text) and I must interact with only a certain one.

I've got the PID from this window.

Any help will be welcomed!

aslak

Topic is clear enough, is the search button? :P

Advanced search ... Keywords you used in your topic

Results = http://www.autoitscript.com/forum/index.ph...%2BPID%2BHandle


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.

Share this post


Link to post
Share on other sites
Aslak

Topic is clear enough, is the search button? :P

Advanced search ... Keywords you used in your topic

Results = http://www.autoitscript.com/forum/index.ph...%2BPID%2BHandle

OK. I did a "normal" search and got so many results far away from the subject.

Will use the Advanced search next time !

thanks, and sorry...

Share this post


Link to post
Share on other sites
SmOke_N

OK. I did a "normal" search and got so many results far away from the subject.

Will use the Advanced search next time !

thanks, and sorry...

No problem, I was being a bit of a smart ass...

I generally start with this approach:

Advanced search

Keywords (usually if I don't know the author I'm looking for, example: +PID+Handle )

Author (Only if I know who wrote it)

Click Titles only

Choose a forum if you want (I usually start in the example script forum)

Click perform search


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.

Share this post


Link to post
Share on other sites
PsaltyDS

Reformatted SmOke_N's replay for clarity:

No problem, I was being a bit of a smart ass... I generally start with this approach.

:P


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites
SmOke_N

Reformatted SmOke_N's replay for clarity:

:P

Ha... I agree! :P

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.

Share this post


Link to post
Share on other sites
Gar

Ironically, now searches for 'WinHandle from PID' turn up this thread about searching for WinHandle from PID... and not the actual answer. That link doesn't work.

Share this post


Link to post
Share on other sites
dryper

I need help about this to :P can anyone show how i can do this? Thnx

Share this post


Link to post
Share on other sites
ProgAndy

Well, you have to search for window handle by PID :P

Then, you get e.g this: http://www.autoitscript.com/forum/index.ph...st&p=523874


*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Share this post


Link to post
Share on other sites
Monamo

Ironically, now searches for 'WinHandle from PID' turn up this thread about searching for WinHandle from PID... and not the actual answer. That link doesn't work.

Example using Calculator:

#include <Constants.au3>
$hWnd = ""
$iPID = ProcessExists("calc.exe")
If $iPID <> 0 Then
    $aWinList = WinList()

    For $i = 1 To $aWinList[0][0]
        If WinGetProcess($aWinList[$i][0]) = $iPID Then
            $hWnd = $aWinList[$i][1]
            ExitLoop
        EndIf
    Next
EndIf

If $hWnd <> "" Then
    MsgBox(0, 0, WinGetTitle($hWnd) & @CRLF & $hWnd)
Else
    MsgBox(64, "Not Found", "No matching process found.")
EndIf

- MoChr(77)& Chr(97)& Chr(100)& Chr(101)& Chr(32)& Chr(121)& Chr(97)& Chr(32)& Chr(108)& Chr(111)& Chr(111)& Chr(107)-------I've told you 100,000 times not to exaggerate!-------Don't make me hit you with my cigarette hand...-------My scripts:Random Episode Selector, Keyboard MouseMover, CopyPath v2.1, SmartRename for XP,Window Tracer[sup]New![/sup]

Share this post


Link to post
Share on other sites
dryper

When i read thats not what i want :P What i want is to use control send on two application that have the SAME name..

ive figured out the PID thingy but controlSend doesnt work with PIDS, so is there any alternative way to send keystrokes to the specefied PID ?..

Thanks

Dryper

Share this post


Link to post
Share on other sites
ProgAndy

Well.

1) Get list of processes and PIDs -> ProcessList ( 2d Array with Names + PIDs)

2) For each PID you can get it's UNIQUE window HANDLES -> ProcessGetWindows ( 2d-Array with Titles + Handles)

3) Now you can send to the Window identified by HWND, even if they have same title :P


*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Share this post


Link to post
Share on other sites
dryper

ProgAndy srry im nooby :P i can give the code i got atm

$list = ProcessList("wow.exe")
Func ToggleHealer()
    $Paused = NOT $Paused
    While $Paused
    ToolTip('Healer is Paused"',0,0)
    WEnd
    ToolTip("Healer is Started",0,0)
    Sleep(1550)
    ControlSend("World of Warcraft","", $list[1][1] ,"8")
EndFunc

ControlSend("World of Warcraft","", $list[1][1] ,"8")

I want my this function to send Some keystrokes to the specified PID, and i also have another function that sends keystrokes to another session of the application..

How can i do this?

Edited by dryper

Share this post


Link to post
Share on other sites
dryper

anyone?

Share this post


Link to post
Share on other sites
dryper

bump

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
Sign in to follow this  

×