Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to kill a running processor 1

Status
Not open for further replies.

ysrise

Programmer
Sep 22, 2004
4
US
Is there a function I can use in Visual C++ program to kill a running process?

Thank you
yan
 
Do it like this:

DWORD dwProcess;

// Get the process ID and put it in dwProcess

HANDLE hProcess = OpenProcess(PROCESS_TERMINATE, FALSE, dwProcess);
if(hProcess != NULL)
{
TerminateProcess(hProcess, 1);
CloseHandle(hProcess);
}
 
Now I use ShellExecute() to open a executable file. It does not return a process ID.

Which funciton can open a executable file and return a process ID?


Thank you
 
Use
The GetModuleHandle function returns a module handle for the specified module if the file has been mapped into the address space of the calling process.
Code:
HMODULE GetModuleHandle(
  LPCTSTR lpModuleName   // address of module name to return handle 
                         // for
);

or
[tt]ShellExecuteEx[/tt]

or you can use
[tt]CreateProcess[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top