?
Solved

process & threads

Posted on 2005-02-28
2
Medium Priority
?
283 Views
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());
  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
0
Comment
Question by:mpapeo
[X]
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
2 Comments
 
LVL 8

Accepted Solution

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

last param of CreateProcess function

pi.hThread

_novi_
0
 
LVL 10

Expert Comment

by:makerp
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..

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
0

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