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.
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)!
Re: How to suspend a process?
Close the process?
What is the meaning?
and,
How to do it?
Thanks.
Re: How to suspend a process?
Quote:
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 >).
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));
}
}
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.
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?
Re: How to suspend a process?
To To Alin: I have read the page you gave. I would try that way.Thanks a million.
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).
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.
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?
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.