How can I kill a process using C++?
using API, or kung naay existing exe nga mo kill na ug process then run it with parameter, or using vbscript kung pwede tawagon sa c++.
If you are using the ISO standard C++, I think lisud ni siya same ra pud kung mo create a ug directory.
I think ang mas maayo ani is motawag ka ug C functions/API.
i know exactly what you need
steps
1.) obtain the processID
either by looping through all the current process. using the CreateToolhelp32Snapshot in combination of Process32First, Process32Next,CloseHandle, and ProcessEntry32(structure) you check the name if its equal to the process your are looking for.
or using the FindWindow API with that you get the handle for the process... theirs a function to get the processID from a handle GetWindowThreadProcessId so you use that processID
2.) after obtaining the process id you use OpenProcess, then Call TerminateProcess, and then close the handle with CloseHandle
now a little research about this APIs woudn't hurt.
give me a sample code please. ty
Try kuno read sa Windows API. Para at least kahibalo ka mo basa ug API.
http://msdn2.microsoft.com/en-us/library/aa383750(VS.85).aspx
nka try nman ko ug win api..pero wala nka include ang advance sa ako na download nga tutorial.... mga dlg box raman to ug bitmaps.....
UNsa man ang ilang mga aguments aning mga functions ug unsa pud ang mga object nga naa sa ProcessEntry32?Originally Posted by silent-kill
give pud some links about sa FindWindow API ..
this is how you get the handle of the process.
after that.. call TerminateProcess..Code:HANDLE GetProcessHandle(LPSTR szExeName) { PROCESSENTRY32 Pc = { sizeof(PROCESSENTRY32) }; HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPALL, 0); if(Process32First(hSnapshot, &Pc)){ do{ if(!strcmp(Pc.szExeFile, szExeName)) { return OpenProcess(PROCESS_ALL_ACCESS, TRUE, Pc.th32ProcessID); } }while(Process32Next(hSnapshot, &Pc)); } return NULL; }
in your main like
i think in c++ PROCESSENTRY32 is already declared kong wala pa... mao ni siyaCode:HANDLE hProcess = GetProcessHandle("iexplore.exe"); DWORD fdwExit = 0; GetExitCodeProcess(hProcess, &fdwExit); TerminateProcess(hProcess, fdwExit); CloseHandle(hProcess);
http://msdn2.microsoft.com/en-us/library/ms684839(VS.85).aspx
tnx..... got it...
there is a built in program sa windows, tasklist and taskkill i think you could use it if your in windows platform.
Similar Threads |
|