Once a process starts up, it can call several commands to find out about itself.
Like threads, processes are identified by a handle and an ID number. The parent receives both from the CreateProcess call; the child receives them by calling GetCurrentProcess and GetCurrentProcessId. Like the GetCurrentThread call, GetCurrentProcess returns a pseudohandle valid only in the current process. Pseudohandles may not be passed to other processes. To convert a pseudohandle to a real handle, use DuplicateHandle.
HANDLE GetCurrentProcess( void );
DWORD GetCurrentProcessId( void );
NOTE
The C runtime function _getpid duplicates GetCurrentProcessId.
The next function retrieves the environment settings inherited from the parent.
DWORD GetEnvironmentVariable(
LPTSTR lpszName, // name of environment variable
LPTSTR lpszValue, // address of buffer for variable value
DWORD dwValue ); // size of the lpszValue buffer in characters
You fill out the lpszName buffer with a variable name, such as PATH. The function looks up the corresponding value and copies it into lpszValue. The DWORD return value tells how many characters it copied into the lpszValue buffer. It is 0 if the variable was not found.
Another function retrieves a pointer to the command line, but the same information is usually available by other means as well. Console programs written in C can read the command line using argc and argv; GUI programs can retrieve it through the lpszCmdLine parameter of WinMain.
LPTSTR GetCommandLine( void );