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
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
The goal of this video is to provide viewers with basic examples to understand how to use strings and some functions related to them in the C programming language.
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.
Suggested Courses

743 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