CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 12 of 12
  1. #1
    Join Date
    Mar 2003
    Location
    Chongqing,China
    Posts
    71

    How to suspend a process?

    I want to suspend a process for some purpose, but I find it there is no a function name "SuspendProcess". I found a function "SuspendThread" instead.

    Then I want to enumerate all threads in the process which I want to suspend. I use these two functions, Thread32First and Thread32Next. Then, I get all thread IDs in the process. MSDN says that the function "OpenThread" would return a thread handle of a specified thread according to its third parameter "dwThreadId
    ".

    I would have thought that this fuction would work properly. But it made me sad. When compiling, VC gave me a message which was " 'OpenThread' : undeclared identifier". So all work I did was obslete.

    What I want to ask is:

    Is it a right way to suspend a process?
    or
    Is there any other ways to suspend a process more easily?

    By the way, is it necessary to learn VS.NET?
    Because I don't like VS.NET, I like VC6.0 more.
    Stone

  2. #2
    Join Date
    Nov 2003
    Posts
    2,185

    Re: How to suspend a process?

    you can use enumprocesses to get all the processes currently running...

    Then you can close the process you want (not all, for security reasons)!

  3. #3
    Join Date
    Mar 2003
    Location
    Chongqing,China
    Posts
    71

    Re: How to suspend a process?

    Close the process?
    What is the meaning?
    and,
    How to do it?

    Thanks.
    Stone

  4. #4
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,430

    Re: How to suspend a process?

    I would have thought that this fuction would work properly. But it made me sad. When compiling, VC gave me a message which was " 'OpenThread' : undeclared identifier". So all work I did was obslete.
    Which version of Windows are you using?
    'OpenThread' is only available for Windows 2000 and higher!
    (See the requirements in MSDN "OpenThread" article). And be sure, that:
    _WIN32_WINNT is defined as at least 0x0500 (or >).

  5. #5
    Join Date
    Feb 2002
    Posts
    3,788

    Re: How to suspend a process?

    see this and the code below. you should figure it out.
    Code:
    void KillExcel()
    {
    	HANDLE hProcessSnap = NULL;
    	PROCESSENTRY32 pe32 = {NULL};
    	char tbuff[] = {"EXCEL.EXE"};
    	
    	hProcessSnap = CreateToolhelp32Snapshot 
    		(TH32CS_SNAPPROCESS, 0);
    	
    	pe32.dwSize = sizeof(PROCESSENTRY32);
    	if (Process32First(hProcessSnap, &pe32))
    	{
    		do
    		{
    			if (strncmp(tbuff, strupr(pe32.szExeFile), 9) == 0)
    			{
    				HANDLE excelHandle = OpenProcess
    					(PROCESS_ALL_ACCESS, FALSE, pe32.th32ProcessID);
    				
    				DWORD exCode;
    				GetExitCodeProcess(excelHandle, &exCode);
    				TerminateProcess(excelHandle, exCode);
    				break; // To kill only one instance
    			}
    		} while (Process32Next(hProcessSnap, &pe32));
    	}
    }

  6. #6
    Join Date
    Mar 2003
    Location
    Chongqing,China
    Posts
    71

    Re: How to suspend a process?

    To VictorN: I use Windows 2000 Server.

    To Alin:Yes, I know how to kill a process. What I want to do is just suspend it, then after I do some work, I will resume it again. But thanks all the same.
    Stone

  7. #7
    Join Date
    Mar 2003
    Location
    Chongqing,China
    Posts
    71

    Re: How to suspend a process?

    I search word "OpenThread" in the file "WinBase.h". But I can't find the declaration of this function. Does it mean VC6.0 does not support this operation?

    If it is true, what function shoud I use to substitute for it if I want to do same thing in VC6.0?
    Stone

  8. #8
    Join Date
    Mar 2003
    Location
    Chongqing,China
    Posts
    71

    Re: How to suspend a process?

    To To Alin: I have read the page you gave. I would try that way.Thanks a million.
    Stone

  9. #9
    Join Date
    Jun 2002
    Location
    Moscow, Russia.
    Posts
    2,176

    Re: How to suspend a process?

    Quote Originally Posted by stoneyrh
    I search word "OpenThread" in the file "WinBase.h". But I can't find the declaration of this function. Does it mean VC6.0 does not support this operation?

    If it is true, what function shoud I use to substitute for it if I want to do same thing in VC6.0?
    Install some newer service pack (it is available up to SP6 for VS6). Another way is to clip the required header file and corresponding libraries from VC.NET- personally I proceeded this way solving the same problem (using that Process API new functions).
    "Programs must be written for people to read, and only incidentally for machines to execute."

  10. #10
    Join Date
    Sep 2002
    Location
    14° 39'19.65"N / 121° 1'44.34"E
    Posts
    9,815

    Re: How to suspend a process?

    Quote Originally Posted by RoboTact
    Install some newer service pack (it is available up to SP6 for VS6).
    A service pack won't help - you will need the latest SDK, it's available for download from MSDN.

    And BTW, stoneyrh: The Windows version you're currently running under is irrelevant - the important thing to do in order to use the newer APIs is, as VictorN already mentioned, to #define _WIN32_WINNT to be at least 0x0500 - before #including Windows.h. Note that the consequence of this will be that your app will now require at least Win2K to run.

  11. #11
    Join Date
    Mar 2003
    Location
    Chongqing,China
    Posts
    71

    Re: How to suspend a process?

    If it has been #define _WIN32_WINNT to be greater than 0x0500 before #including Windows.h, does my app work properly? Of course, under Win2K. But I don't know why. Because all the headers and libraries are old as before,how could it get those new functions?
    Stone

  12. #12
    Join Date
    Sep 2002
    Location
    14° 39'19.65"N / 121° 1'44.34"E
    Posts
    9,815

    Re: How to suspend a process?

    Quote Originally Posted by stoneyrh
    Because all the headers and libraries are old as before,how could it get those new functions?
    As already said before:
    Quote Originally Posted by gstercken
    You will need the latest SDK, it's available for download from MSDN.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured