void CShowAllProcessDlg::OnStopProcess()
{
POSITION pos = m_showlist.GetFirstSelectedItemPosition();// 一个List control
int currentSelect = m_showlist.GetNextSelectedItem(pos);
if(currentSelect > 0)
{
CString FileBuffer; FileBuffer = CString(TEXT("确实要终止进程")+m_showlist.GetItemText(currentSelect,0)+TEXT("吗?")); if(AfxMessageBox(FileBuffer,MB_OKCANCEL,0)==IDOK)
{
HANDLE ProcessHandle;
ProcessHandle = OpenProcess(PROCESS_ALL_ACCESS,FALSE,m_ProcessIndex[currentSelect]);
if(ProcessHandle)
{
::TerminateProcess(ProcessHandle,0);//进程结束不了
AfxMessageBox("指定进程已终止!");
OnGetProcess();
}
else
AfxMessageBox("对不起,终止该进程将造成系统不稳!");
}
}
}
{
POSITION pos = m_showlist.GetFirstSelectedItemPosition();// 一个List control
int currentSelect = m_showlist.GetNextSelectedItem(pos);
if(currentSelect > 0)
{
CString FileBuffer; FileBuffer = CString(TEXT("确实要终止进程")+m_showlist.GetItemText(currentSelect,0)+TEXT("吗?")); if(AfxMessageBox(FileBuffer,MB_OKCANCEL,0)==IDOK)
{
HANDLE ProcessHandle;
ProcessHandle = OpenProcess(PROCESS_ALL_ACCESS,FALSE,m_ProcessIndex[currentSelect]);
if(ProcessHandle)
{
::TerminateProcess(ProcessHandle,0);//进程结束不了
AfxMessageBox("指定进程已终止!");
OnGetProcess();
}
else
AfxMessageBox("对不起,终止该进程将造成系统不稳!");
}
}
}
{
BOOL fOK = FALSE;
HANDLE hToken = NULL;
if(OpenProcessToken(GetCurrentProcess(),TOKEN_ADJUST_PRIVILEGES,&hToken)){
TOKEN_PRIVILEGES tp;
tp.PrivilegeCount =1;
LookupPrivilegeValue(NULL,SE_DEBUG_NAME,&tp.Privileges[0].Luid);
tp.Privileges[0].Attributes = fEnable ? SE_PRIVILEGE_ENABLED : 0;
AdjustTokenPrivileges(hToken,FALSE,&tp,sizeof(tp),NULL,NULL);
fOK = (GetLastError()==ERROR_SUCCESS);
CloseHandle(hToken);
}
return fOK;
}