Process ID from Process Handle 
Author Message
 Process ID from Process Handle

I'm drawing a blank, and I'm also running short on time. I have a process handle. I need
the process ID. (Actually, I need the top-level window for that process). Quick pointer?
I'm just drawing a blank and I've got a ton of code to write in the next six hours.
                thanks
                        joe

Joseph M. Newcomer [MVP]

Web: http://www.*-*-*.com/ ~newcomer
MVP Tips: http://www.*-*-*.com/ ~newcomer/mvp_tips.htm



Wed, 13 Apr 2005 04:10:03 GMT  
 Process ID from Process Handle
Hey Folks,

Times change.  Old functions get documented, new ones get created.

NtQueryInformationProcess for 2000.
GetProcessId()  XP SP1 and .Net

There still isn't anything for Win9x/ME.  They won't be changing with the
times. :)

David Janson
Microsoft Developers Support



Wed, 13 Apr 2005 08:38:27 GMT  
 Process ID from Process Handle
Hi Joe,

I've never tried this suggestion, but maybe this will be of some help to
you:
http://groups.google.com/groups?hl=en&lr=lang_en&ie=UTF-8&selm=OqG45o...
.1668%40cpmsftngp03

Since it uses ntdll, obviously you are dead in the water for 9x, but judging
from your previous rants about those 'toy operating systems', you probably
want NT anyway :). I too wish 9x would disappear from the face of the earth.

You'd think the API would have a plain vanilla GetPid() or
ProcessIdFromHandle() function. That would be just *too* easy.

Regards,
Mike



Quote:
> I'm drawing a blank, and I'm also running short on time. I have a process
handle. I need
> the process ID. (Actually, I need the top-level window for that process).
Quick pointer?
> I'm just drawing a blank and I've got a ton of code to write in the next
six hours.
> thanks
> joe

> Joseph M. Newcomer [MVP]

> Web: http://www3.pgh.net/~newcomer
> MVP Tips: http://www3.pgh.net/~newcomer/mvp_tips.htm



Wed, 13 Apr 2005 08:31:08 GMT  
 Process ID from Process Handle

Quote:
>Times change.  Old functions get documented, new ones get created.

>NtQueryInformationProcess for 2000.
>GetProcessId()  XP SP1 and .Net

>There still isn't anything for Win9x/ME.  They won't be changing with the
>times. :)

What about NT4 too? I suspect that many of us still have to write code
that supports all those non-supported OS's, so those functions
wouldn't be an option unless...

It would be nice if these newer facilities were available via some
redistributable DLL wrapper - similar to what's done for a few other
useful APIs.

Dave Lowndes
--
MVP VC++ FAQ: http://www.mvps.org/vcfaq



Wed, 13 Apr 2005 14:06:58 GMT  
 Process ID from Process Handle
Yes, that's the problem; the customer base for this app is still largely MS-DOS-based,
alas.
                                joe

Quote:

>>Times change.  Old functions get documented, new ones get created.

>>NtQueryInformationProcess for 2000.
>>GetProcessId()  XP SP1 and .Net

>>There still isn't anything for Win9x/ME.  They won't be changing with the
>>times. :)

>What about NT4 too? I suspect that many of us still have to write code
>that supports all those non-supported OS's, so those functions
>wouldn't be an option unless...

>It would be nice if these newer facilities were available via some
>redistributable DLL wrapper - similar to what's done for a few other
>useful APIs.

>Dave Lowndes

Joseph M. Newcomer [MVP]

Web: http://www3.pgh.net/~newcomer
MVP Tips: http://www3.pgh.net/~newcomer/mvp_tips.htm


Thu, 14 Apr 2005 00:14:19 GMT  
 Process ID from Process Handle
ShellExecuteEx discards this critical piece of information and does not deliver it back.
                                joe

Quote:


>>I'm drawing a blank, and I'm also running short on time. I have a process
>handle. I need
>>the process ID. (Actually, I need the top-level window for that process).
>Quick pointer?
>>I'm just drawing a blank and I've got a ton of code to write in the next
>six hours.
>> thanks
>> joe

>But how  are you getting the handle in the first place? There is a winapi
>function for getting a processes own ID, but nothing about getting it from
>handle.

>Maybe you should search for that project that collect PID of everything on
>your system.

>PS: If you give me some time, I can have a definite solution in 8 hours. :)

>V-man

Joseph M. Newcomer [MVP]

Web: http://www3.pgh.net/~newcomer
MVP Tips: http://www3.pgh.net/~newcomer/mvp_tips.htm


Thu, 14 Apr 2005 00:13:33 GMT  
 Process ID from Process Handle
I despise the toy operating systems. But I don't control the customer base, and this app
is selling well into that market, alas. What I like and what I have to program to often
differ. Which is one of the main reasons I totally despise having to deal with these
systems. My life would be vastly more pleasant if they all disappeared tomorrow.
                                joe


Quote:
>Hi Joe,

>I've never tried this suggestion, but maybe this will be of some help to
>you:
>http://groups.google.com/groups?hl=en&lr=lang_en&ie=UTF-8&selm=OqG45o...
>.1668%40cpmsftngp03

>Since it uses ntdll, obviously you are dead in the water for 9x, but judging
>from your previous rants about those 'toy operating systems', you probably
>want NT anyway :). I too wish 9x would disappear from the face of the earth.

>You'd think the API would have a plain vanilla GetPid() or
>ProcessIdFromHandle() function. That would be just *too* easy.

>Regards,
>Mike



>> I'm drawing a blank, and I'm also running short on time. I have a process
>handle. I need
>> the process ID. (Actually, I need the top-level window for that process).
>Quick pointer?
>> I'm just drawing a blank and I've got a ton of code to write in the next
>six hours.
>> thanks
>> joe

>> Joseph M. Newcomer [MVP]

>> Web: http://www3.pgh.net/~newcomer
>> MVP Tips: http://www3.pgh.net/~newcomer/mvp_tips.htm

Joseph M. Newcomer [MVP]

Web: http://www3.pgh.net/~newcomer
MVP Tips: http://www3.pgh.net/~newcomer/mvp_tips.htm


Thu, 14 Apr 2005 00:15:47 GMT  
 Process ID from Process Handle


Quote:
> I'm drawing a blank, and I'm also running short on time. I have a process handle. I need
> the process ID. (Actually, I need the top-level window for that process). Quick pointer?
> I'm just drawing a blank and I've got a ton of code to write in the next six hours.
> thanks

Joe,

SWAG, but could you use EnumWindows/GetWindowThreadProcessId followed by an OpenProcess until you
get a match with your process HANDLE?

--
Jeff Partch [MVP]



Thu, 14 Apr 2005 01:38:11 GMT  
 Process ID from Process Handle

Quote:



> > I'm drawing a blank, and I'm also running short on time. I have a process handle. I need
> > the process ID. (Actually, I need the top-level window for that process). Quick pointer?
> > I'm just drawing a blank and I've got a ton of code to write in the next six hours.
> > thanks

> Joe,

> SWAG, but could you use EnumWindows/GetWindowThreadProcessId followed by an OpenProcess until you
> get a match with your process HANDLE?

FWIW, I'm not getting any satisfaction from it at all, Joe. Sorry for the lame post.

--
Jeff Partch [MVP]



Thu, 14 Apr 2005 04:11:00 GMT  
 Process ID from Process Handle
    Do you have a window associated with this process ? If yes, then you can
try the GetWindowThreadProcessId() API.

--
Cheers
Check Abdoul [ VC++ MVP ]
-----------------------------------



Quote:
> I'm drawing a blank, and I'm also running short on time. I have a process
handle. I need
> the process ID. (Actually, I need the top-level window for that process).
Quick pointer?
> I'm just drawing a blank and I've got a ton of code to write in the next
six hours.
> thanks
> joe

> Joseph M. Newcomer [MVP]

> Web: http://www3.pgh.net/~newcomer
> MVP Tips: http://www3.pgh.net/~newcomer/mvp_tips.htm



Thu, 14 Apr 2005 19:47:06 GMT  
 Process ID from Process Handle


Quote:
> | > > I'm drawing a blank, and I'm also running short on time. I have a
> process handle. I need
> | > > the process ID. (Actually, I need the top-level window for that
> process). Quick pointer?
> | > > I'm just drawing a blank and I've got a ton of code to write in the
> next six hours.
> | > > thanks
> | >
> | > Joe,
> | >
> | > SWAG, but could you use EnumWindows/GetWindowThreadProcessId followed
> by an OpenProcess until you
> | > get a match with your process HANDLE?

> This can't work.  OpenProcess() will give you a new handle.  It won't match
> an existing handle.

Thanks, that's why I replied to my own post an apology (which you seem to have deleted for some
reason). :)

--
Jeff Partch [MVP]



Sat, 16 Apr 2005 03:07:07 GMT  
 Process ID from Process Handle
| > > I'm drawing a blank, and I'm also running short on time. I have a
process handle. I need
| > > the process ID. (Actually, I need the top-level window for that
process). Quick pointer?
| > > I'm just drawing a blank and I've got a ton of code to write in the
next six hours.
| > > thanks
| >
| > Joe,
| >
| > SWAG, but could you use EnumWindows/GetWindowThreadProcessId followed
by an OpenProcess until you
| > get a match with your process HANDLE?

This can't work.  OpenProcess() will give you a new handle.  It won't match
an existing handle.

Dave



Sat, 16 Apr 2005 01:52:19 GMT  
 Process ID from Process Handle
Amen!

Isn't that one of the main points of an operating system.  And wouldn't this
be a better use of Microsoft's development resource than some of the GUI
"enhancements" that seem to dominate the newer releases.

TFM3

Note: Spam-resistant e-mail address


Quote:
> >| What about NT4 too? I suspect that many of us still have to write code
> >| that supports all those non-supported OS's, so those functions
> >| wouldn't be an option unless...

> >Hey Dave,

> >Don't hold your breath.  It will very much be the exception case when an
> >API (or API set) is back-ported to older platforms.  The test matrix
> >becomes impossible.

> Hi Dave,

> Ah well, if we don't ask, we won't get it :)

> I think we can all appreciate the testing difficulty, but just to
> counter that, isn't it less effort for MS to incur it rather than all
> the developers who need such functionality and have to roll their own
> solutions? You do it once (or twice, or however many times it's
> needed), but the duplication from the number of customers who end up
> doing it must be considerably higher.

> Dave
> --
> MVP VC++ FAQ: http://www.mvps.org/vcfaq



Sat, 16 Apr 2005 13:44:19 GMT  
 
 [ 13 post ] 

 Relevant Pages 

1. Process id from process handle (how to get)?

2. Process ID from Process Handle

3. Getting process ID from process handle

4. How to obtain Process ID If I have process handle

5. process path from process id

6. How to get Process Information given Process ID

7. Solution for retrieving the process name based on its process ID

8. process path from process id.

9. getting process ID of the current process

10. Closing a process when all you have is a process id

11. process handles and ids

12. Create Handle from process ID

 

 
Powered by phpBB® Forum Software