How to get the HANDLE hProcess about my process itself? 
Author Message
 How to get the HANDLE hProcess about my process itself?

Appreciate for any messages.


Sat, 26 Mar 2005 21:27:53 GMT  
 How to get the HANDLE hProcess about my process itself?

Quote:
> Appreciate for any messages.

1. Go to msdn.microsoft.com (this should always be your first step in
finding answers).
2. Type "current process handle" into the search box.

After a few false hits, you'll find the "GetCurrentProcess()" API function.
Following that link and reading the remarks on that function will tell you
everything you need to know:

The GetCurrentProcess function retrieves a pseudo handle for the current
process.
HANDLE GetCurrentProcess(void);

Parameters

This function has no parameters.

Return Values

The return value is a pseudo handle to the current process.

Remarks

A pseudo handle is a special constant, currently (HANDLE)-1, that is
interpreted as the current process handle. For compatibility with future
operating systems, it is best to call GetCurrentProcess instead of
hard-coding this constant value. The calling process can use a pseudo handle
to specify its own process whenever a process handle is required. Pseudo
handles are not inherited by child processes.

This handle has the maximum possible access to the process object. For
systems that support security descriptors, this is the maximum access
allowed by the security descriptor for the calling process. For systems that
do not support security descriptors, this is PROCESS_ALL_ACCESS. For more
information, see Process Security and Access Rights.

A process can create a "real" handle to itself that is valid in the context
of other processes, or that can be inherited by other processes, by
specifying the pseudo handle as the source handle in a call to the
DuplicateHandle function. A process can also use the OpenProcess function to
open a real handle to itself.

The pseudo handle need not be closed when it is no longer needed. Calling
the CloseHandle function with a pseudo handle has no effect. If the pseudo
handle is duplicated by DuplicateHandle, the duplicate handle must be
closed.

HTH

-cd



Sat, 26 Mar 2005 21:48:11 GMT  
 How to get the HANDLE hProcess about my process itself?


Quote:


>> Appreciate for any messages.

> 1. Go to msdn.microsoft.com (this should always be your first step in
> finding answers).
> 2. Type "current process handle" into the search box.

> After a few false hits, you'll find the "GetCurrentProcess()" API
> function. Following that link and reading the remarks on that function
> will tell you everything you need to know:

> The GetCurrentProcess function retrieves a pseudo handle for the
> current process.
> HANDLE GetCurrentProcess(void);

> Parameters

> This function has no parameters.

> Return Values

> The return value is a pseudo handle to the current process.

> Remarks

> A pseudo handle is a special constant, currently (HANDLE)-1, that is
> interpreted as the current process handle. For compatibility with
> future operating systems, it is best to call GetCurrentProcess instead
> of hard-coding this constant value. The calling process can use a
> pseudo handle to specify its own process whenever a process handle is
> required. Pseudo handles are not inherited by child processes.

> This handle has the maximum possible access to the process object. For
> systems that support security descriptors, this is the maximum access
> allowed by the security descriptor for the calling process. For
> systems that do not support security descriptors, this is
> PROCESS_ALL_ACCESS. For more information, see Process Security and
> Access Rights.

> A process can create a "real" handle to itself that is valid in the
> context of other processes, or that can be inherited by other
> processes, by specifying the pseudo handle as the source handle in a
> call to the DuplicateHandle function. A process can also use the
> OpenProcess function to open a real handle to itself.

> The pseudo handle need not be closed when it is no longer needed.
> Calling the CloseHandle function with a pseudo handle has no effect.
> If the pseudo handle is duplicated by DuplicateHandle, the duplicate
> handle must be closed.

> HTH

> -cd

Hi,Carl Daniel
 I know a little about it.I want to know how to get the current real
process handle .If it need use DuplicateHandle function,which value can be
passed about the parameter:HANDLE hSourceProcessHandle,  
  HANDLE hSourceHandle,        
  HANDLE hTargetProcessHandle,  
  LPHANDLE lpTargetHandle
Thanks.


Sun, 27 Mar 2005 15:38:47 GMT  
 How to get the HANDLE hProcess about my process itself?

Quote:
> If it need use DuplicateHandle function,which value can be
> passed about the parameter:HANDLE hSourceProcessHandle,  
>   HANDLE hSourceHandle,        
>   HANDLE hTargetProcessHandle,  
>   LPHANDLE lpTargetHandle

I suppose the first three parameters of DuplicateHandle can all be
GetCurrentProcess().  lpTargetHandle must of course point to the
variable where you want to get the real handle.


Sun, 27 Mar 2005 20:16:51 GMT  
 How to get the HANDLE hProcess about my process itself?

Quote:
> Hi,Carl Daniel
>  I know a little about it.I want to know how to get the current real
> process handle .If it need use DuplicateHandle function,which value can be
> passed about the parameter:HANDLE hSourceProcessHandle,
>   HANDLE hSourceHandle,
>   HANDLE hTargetProcessHandle,
>   LPHANDLE lpTargetHandle
> Thanks.

You need to read replies more carefully, and get in the habit of reading the
documentation for the functions you're using.  In the documentation for
GetCurrentProcess:

Quote:
> > A process can create a "real" handle to itself that is valid in the
> > context of other processes, or that can be inherited by other
> > processes, by specifying the pseudo handle as the source handle in a
> > call to the DuplicateHandle function. A process can also use the
> > OpenProcess function to open a real handle to itself.

..." by specifying the pseudo handle as the source handle in a call to
DuplicateHandle "

In other words, pass GetCurrentProcess() as the first parameter to
DuplicateHandle.  Since you want a handle for your own use, also pass
GetCurrentProcess() as the second parameter to DuplicateHandle.

-cd



Sun, 27 Mar 2005 21:29:49 GMT  
 How to get the HANDLE hProcess about my process itself?

Quote:

>Appreciate for any messages.

From PSDK:

GetCurrentProcess
The GetCurrentProcess function retrieves a pseudo handle for the current
process.

HANDLE GetCurrentProcess(VOID);
Parameters
This function has no parameters.

Return Values
The return value is a pseudo handle to the current process.

Remarks
A pseudo handle is a special constant that is interpreted as the current
process handle. The calling process can use this handle to specify its own
process whenever a process handle is required. Pseudo handles are not
inherited by child processes.

This handle has the maximum possible access to the process object. For
systems that support security descriptors, this is the maximum access
allowed by the security descriptor for the calling process. For systems that
do not support security descriptors, this is PROCESS_ALL_ACCESS. For more
information, see Process Security and Access Rights.

A process can create a "real" handle to itself that is valid in the context
of other processes, or that can be inherited by other processes, by
specifying the pseudo handle as the source handle in a call to the
DuplicateHandle function.

--
 - Vince



Sun, 27 Mar 2005 23:02:38 GMT  
 How to get the HANDLE hProcess about my process itself?

Quote:

>>Appreciate for any messages.

> From PSDK:

> GetCurrentProcess
> The GetCurrentProcess function retrieves a pseudo handle for the
> current process.

> HANDLE GetCurrentProcess(VOID);
> Parameters
> This function has no parameters.

> Return Values
> The return value is a pseudo handle to the current process.

> Remarks
> A pseudo handle is a special constant that is interpreted as the
> current process handle. The calling process can use this handle to
> specify its own process whenever a process handle is required. Pseudo
> handles are not inherited by child processes.

> This handle has the maximum possible access to the process object. For
> systems that support security descriptors, this is the maximum access
> allowed by the security descriptor for the calling process. For
> systems that do not support security descriptors, this is
> PROCESS_ALL_ACCESS. For more information, see Process Security and
> Access Rights.

> A process can create a "real" handle to itself that is valid in the
> context of other processes, or that can be inherited by other
> processes, by specifying the pseudo handle as the source handle in a
> call to the DuplicateHandle function.

Hi,all
 Thank you.I see a little.Then,Where may I get the Ntsecpkg.h head file
from?


Mon, 28 Mar 2005 18:18:05 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. Getting process ID from process handle

2. HANDLE hProcess=GetCurrentProcess();

3. Getting a process' handle/CWnd

4. Getting window handle for a process

5. Getting the handle of a given process's main window

6. how get a process HANDLE from a thread HANDLE

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

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

9. Get a CWnd Handle from Process Handle

10. Process ID from Process Handle

11. Process ID from Process Handle

12. Window handle from process handle?

 

 
Powered by phpBB® Forum Software