process & threads

Posted on 2005-02-28
Medium Priority
Last Modified: 2010-04-15
How can I get the Thread handle of a program X (like i have numbers.exe or notepad.exe) and suspend it and later resume it?
 I have SuspendThread() function frm msdn. How can i tackle it.
To make things simpler i have this code below:

#include <windows.h>
#include <stdio.h>

//Program that creates a process
//This program assumes that numbers.exe is in the PATH!

int main(int argc, char **argv)
 PROCESS_INFORMATION pi;       /* filled in by CreateProcess */
  STARTUPINFO si;               /* startup info for the new process*/

  printf("Process %d reporting for creation\n",GetCurrentProcessId());

  /* Call CreateProcess, telling it to run an exe file
     with lots of defaults... (the NULLs mean "use defaults")
       "\"F:\debug\numbers.exe\" -L",

CreateProcess(NULL,                  /* lpApplicationName */
"numbers.exe",           /* lpCommandLine  assumes to use curent process directory*/
NULL,                              /* lpsaProcess */
NULL,                              /* lpsaThread */
FALSE,                              /* bInheritHandles */
CREATE_NEW_CONSOLE,     /* dwCreationFlags */
NULL,                              /* lpEnvironment */
NULL,                              /* lpCurDir */
&si,                              /* lpStartupInfo */
&pi                                    /* lpProcInfo */

  /* print out the new process iD and quit
     (does not wait for new process to exit!)
  printf("New Process ID: %d ",pi.dwProcessId);
  printf("has started \n");
       DWORD SuspendThread(HANDLE /*hThread*/
//                              );
//       GetLastError(void);


Pliz Assist
Question by:mpapeo

Accepted Solution

novitiate earned 60 total points
ID: 13426886
you can get the thread handle from

last param of CreateProcess function


LVL 10

Expert Comment

ID: 13427758
or you can use GetCurrentThread to get a pseudo handle to the current exeuting thread - this is useful if you do not have the process information structure in scope..


note that you will not need to call CloseHandle on the handle returned in this call


Featured Post

Free tool for managing users' photos in Office 365

Easily upload multiple users’ photos to Office 365. Manage them with an intuitive GUI and use handy built-in cropping and resizing options. Link photos with users based on Azure AD attributes. Free tool!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use for-loops in the C programming language.
The goal of this video is to provide viewers with basic examples to understand opening and reading files in the C programming language.

601 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question