|
-
December 4th, 2008, 04:32 AM
#1
Getting thread id of a process
I have created a process using ShellExecute and i have the process handle.
I need to get the PROCESS_INFORMATION of that process.
Some body please help me
Last edited by zuhrs; December 4th, 2008 at 04:35 AM.
-
December 4th, 2008, 04:38 AM
#2
Re: Getting thread id of a process
You should use CreateProcess instead. This will fill the PROCESS_INFORMATION struct for you.
Take a look here: Processes: How can I start a process?
Laitinen
-
December 4th, 2008, 04:47 AM
#3
Re: Getting thread id of a process
If i use CreateProcess API I can get PROCESS_INFORMATION structure, but my question is
is there any way so that i get the PROCESS_INFORMATION from the process handle or process id
we can get process ID if we have process handle as
processID = GetProcessId(processhandle);
I need to get the thread ID
-
December 4th, 2008, 04:55 AM
#4
Re: Getting thread id of a process
which thread id? A process may have many threads.
-
December 4th, 2008, 05:37 AM
#5
Re: Getting thread id of a process
I have created a process using ShellExecuteEx and to get the handle of the window I have created , ihave done the following code
SHELLEXECUTEINFO ExecuteInfo = {0};
memset(&ExecuteInfo, 0, sizeof(ExecuteInfo));
ExecuteInfo.cbSize = sizeof(ExecuteInfo);
ExecuteInfo.fMask = SEE_MASK_DOENVSUBST | SEE_MASK_NOCLOSEPROCESS ;
ExecuteInfo.hwnd = 0;
ExecuteInfo.lpVerb = L"open";
ExecuteInfo.nShow = SW_SHOW;
ExecuteInfo.lpFile = szExe.GetString();
ExecuteInfo.lpParameters = szPath.GetString();
ExecuteInfo.lpDirectory = 0;
ExecuteInfo.hInstApp = AfxGetInstanceHandle();
if (::ShellExecuteEx(&ExecuteInfo))
{
if( ExecuteInfo.hProcess != NULL )
{
WaitForInputIdle(ExecuteInfo.hProcess, WAIT_FOR_INPUT_TIMEOUT);
}
DWORD processID = GetProcessId(ExecuteInfo.hProcess);
int count = 0;
HWND hwnd = ::GetTopWindow(0 );
while ( hwnd )
{
DWORD pid;
DWORD dwTheardId = ::GetWindowThreadProcessId( hwnd,&pid);
if (processID == pid)
{
count++;
MessageBox("window title");
}
hwnd = ::GetNextWindow( hwnd , GW_HWNDNEXT);
}
}
After this execution, count is 3. There are three handles.
Actually i am opening another application using the create process.
When i open the mspaint, i get three conditions meeting the above handles
How can i ensure which is the main handle of the created application . eg : mspaint
Initially it is giving GDI as handle and then it gives the oroginal handle of the mspaint
-
December 4th, 2008, 06:35 AM
#6
Re: Getting thread id of a process
Use Spy++ to know what threads/windows (and how many) are created when you start MsPaint.
Victor Nijegorodov
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|