TerminateProcess() with EVC++

  • Thread starter Thread starter Bks
  • Start date Start date
B

Bks

I want to terminate a running process from the task manager using evc++
code.

i am using this code :
HANDLE hTl,hProcess;
PROCESSENTRY32 pe;
bool bFound=FALSE;
DWORD dwExplorerProcessID;

hTl = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);

if (hTl == INVALID_HANDLE_VALUE)
MessageBox (0,TEXT("INVALID_HANDLE_VALUE"),TEXT(""),0);

pe.dwSize = sizeof(PROCESSENTRY32);

if (!Process32First(hTl, &pe))
MessageBox (0,TEXT("Process32First"),TEXT(""),0);

// if (lstrcmpi(pe.szExeFile, TEXT("explorer.exe")) == 0)
// bFound = TRUE;

while (!bFound && Process32Next(hTl, &pe))
{
if (lstrcmpi(pe.szExeFile, TEXT("explorer.exe")) == 0)
bFound = TRUE;
}

if (bFound)
{
dwExplorerProcessID = pe.th32ProcessID;
hProcess = OpenProcess(0, FALSE, dwExplorerProcessID);
if (hProcess == NULL)
MessageBox (0,TEXT("OpenProcess"),TEXT(""),0);
else
{
if (!TerminateProcess(hProcess, 0))
MessageBox (0,TEXT("TerminateProcess"),TEXT(""),0);
CloseHandle(hProcess);
}

}
CloseToolhelp32Snapshot(hTl);

but it gives me error:


ceSetUp.obj : error LNK2019: unresolved external symbol
CloseToolhelp32Snapshot referenced in function "void __cdecl
StopProcess(void)" (?StopProcess@@YAXXZ)
ceSetUp.obj : error LNK2019: unresolved external symbol Process32Next
referenced in function "void __cdecl StopProcess(void)"
(?StopProcess@@YAXXZ)
ceSetUp.obj : error LNK2019: unresolved external symbol Process32First
referenced in function "void __cdecl StopProcess(void)"
(?StopProcess@@YAXXZ)
ceSetUp.obj : error LNK2019: unresolved external symbol
CreateToolhelp32Snapshot referenced in function "void __cdecl
StopProcess(void)" (?StopProcess@@YAXXZ)


Can any one help me in this ?

Thanks
Bhavin
 
Hi,

It's a linkage error. Your method are not referenced anywhere in the source
code and libraries. Try to link "toolhelp.lib" in your project. (by copying
the file to your project directory and adding it in FileView, Header file
section)

Hope it helps,

Sebastien
 
Back
Top