Link to home
Create AccountLog in
Avatar of mpapeo
mpapeo

asked on

process & threads

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());
  GetStartupInfo(&si);

  /* 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);


  return(0);
}

Pliz Assist
Thanx
ASKER CERTIFIED SOLUTION
Avatar of novitiate
novitiate

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Avatar of Paul Maker
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..

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/getcurrentthread.asp

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

-P