TerminateProcess结束进程

#include
#include 
#include
BOOL KillProcess(DWORD dwProcessId)
{


    HANDLE hProcess= OpenProcess(PROCESS_ALL_ACCESS,FALSE,dwProcessId);

BOOL bKill= TerminateProcess(hProcess,0);
if(bKill==0)
{
return FALSE;
}




}
bool EnumProcess()
{


//CreateToolhelp32Snapshot
//Process32Next
//Process32First
PROCESSENTRY32 pe32;
pe32.dwSize=sizeof(PROCESSENTRY32);
HANDLE hSnapshot= CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
if(INVALID_HANDLE_VALUE==hSnapshot)
   return false;
if(Process32First(hSnapshot,&pe32))
{


do 
{
printf("ID:%d,Name:%s\n",pe32.th32ProcessID,pe32.szExeFile);




} while (Process32Next(hSnapshot,&pe32));






}
return false;


}


bool EnablePri()
{
//OpenProcessToken
//LookupPrivilegeValue
//AdjustTokenPrivileges()
 HANDLE TokenHandle;
 PLUID lpLuid;
 TOKEN_PRIVILEGES tkp;
 tkp.PrivilegeCount=1;


 BOOL bOpen= OpenProcessToken(GetCurrentProcess(),TOKEN_ADJUST_PRIVILEGES|TOKEN_QUERY,&TokenHandle);
  if(!bOpen)
     return false;
  BOOL bLook= LookupPrivilegeValue(NULL,SE_SECURITY_NAME,&tkp.Privileges[0].Luid);
  if(!bLook)
 return false;
  BOOL bAdjust= AdjustTokenPrivileges(TokenHandle,false,&tkp,sizeof(tkp),NULL,NULL);


  return(GetLastError()==ERROR_SUCCESS);
}






void main()
{  


if(!EnablePri())
{printf("EnablePri fail\n");
return;
}
if(EnumProcess())
{  printf("EnumProcess fail\n");
   getchar();
   return;
}


printf("InPut Process PID:");
DWORD dwProcessId;
scanf("%d",&dwProcessId);


KillProcess(dwProcessId);


}


你可能感兴趣的:(为什么我叫木马?)