Jump to content

Window handle and ProcessID


Recommended Posts

First let me ask this question...

For any processid, is there an associated window handle?

If the answer is no, then I probably need to look no further.

What I'm trying to do is get a window handle based on a processid. Something that has been asked many times on the forum. I believe I may have hit two road blocks.

1. The processid I'm trying to get a window handle to is a Windows Service

2. If I remote desktop into a server, will the WinList() function see only windows related to my sessionID or can it retrieve all windows from all sessions (including the console session)?

The ProcessList() function will return the PID of the service. I'm trying to use the UDF '_ProcessGetHWnd' but it does not return a valid window handle.

An example process to try would be clipsrv.exe

Thanks

Link to comment
Share on other sites

  • Moderators

First let me ask this question...

For any processid, is there an associated window handle?

If the answer is no, then I probably need to look no further.

Not all processes are GUI...

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.

Link to comment
Share on other sites

$PID = WinGetProcess("Windows Live Messenger")

$HWnd = _ProcessGetHWnd($PID)

MsgBox(0,"title", WinGetTitle($HWnd))





Func _ProcessGetHWnd($PID)
    
    local $WinList = WinList()
    
    local $Return = 0
    
    for $i = 1 to $WinList[0][0]
        if WinGetProcess($WinList[$i][1]) = $PID Then 
            $Return = $WinList[$i][1]
            ExitLoop
        EndIf
    Next
    
    Return $Return
    
EndFunc

Link to comment
Share on other sites

  • Moderators

$PID = WinGetProcess("Windows Live Messenger")

$HWnd = _ProcessGetHWnd($PID)

MsgBox(0,"title", WinGetTitle($HWnd))





Func _ProcessGetHWnd($PID)
    
    local $WinList = WinList()
    
    local $Return = 0
    
    for $i = 1 to $WinList[0][0]
        if WinGetProcess($WinList[$i][1]) = $PID Then 
            $Return = $WinList[$i][1]
            ExitLoop
        EndIf
    Next
    
    Return $Return
    
EndFunc
He's already stated he's used that kip

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.

Link to comment
Share on other sites

  • Moderators

that script was my own script, and not the UDF he found somewhere.

Which will return the same exact results....

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.

Link to comment
Share on other sites

A process like clipsrv.exe doesnt have a Gui, like most services.

@oktoberfest2: Is the process ,you want to do stuff with, in the processlist of the taskmanager? (something different than "System.exe")

The process is an executable file that runs as a service. It may very well be that the process is not a Gui. What I'm trying to do is run the SQL Server profiler utility and filter based on certain criteria, one of which is application name. This particular process/service runs but has no application name. I was trying to see if it was possible to get a handle to it and somehow set a title or something so that the profiler utility would pick it up so I could filter on it. Right now the only thing I have to go on is the client process id which can change when the computer is rebooted or the service is stopped and restarted.

Thanks.

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...