class processutils
;
#include "stdafx.h"
#include "process_utils.h"
#include "psapi.h"
#include dword processutils::findprocess(const tchar *strprocessname)
return 0;}//
// function: errorforce
// 此函式中用上面的 findprocess 函式獲得你的目標程序的id
// 用win api openporcess 獲得此程序的控制代碼,再以terminateprocess
// 強制結束這個程序
//bool processutils::killprocess(const tchar* strprocessname)
//// getdebugpriv
// 在 windows nt/2000/xp 中可能因許可權不夠導致以上函式失敗
// 如以 system 許可權執行的系統程序,服務程序
// 用本函式取得 debug 許可權即可,winlogon.exe 都可以終止哦 :)
//bool processutils::getdebugpriv()
if (!lookupprivilegevalue(null, se_debug_name, &sedebugnamevalue))
tkp.privilegecount = 1;
tkp.privileges[0].luid = sedebugnamevalue;
tkp.privileges[0].attributes = se_privilege_enabled;
if (!adjusttokenprivileges(htoken, false, &tkp, sizeof tkp, null, null))
return true;
}dword processutils::getmainthreadid(dword processid)
; handle threadsnap = createtoolhelp32snapshot(th32cs_snapthread, 0);
if (thread32first(threadsnap, &te32))
}while (thread32next(threadsnap, &te32));
} return threadid;
}bool processutils::ismainthread()
bool processutils::isadministrator()
/*token_elevation*/te;
dword dwreturnlength = 0;
if (gettokeninformation(htoken, /*tokenelevation*/(_token_information_class)20,
&te, sizeof(te), &dwreturnlength))
closehandle( htoken );
} return biselevated;
}bool processutils::isenableuac(void)
; ovi.dwosversioninfosize = sizeof(ovi);
if (::getversionexw(&ovi))
}} }
return benableuac;
}bool processutils::issysprocess(handle hprocess)
ptoken_user ptoken_user = null;
dword dwtokenuser = 0l;
if(htoken != null)
if(dwtokenuser>0)
if(ptoken_user != null)
tchar szaccname[max_path] = ;
tchar szdomainname[max_path] = ;
if(bretval != false && ptoken_user != null) }
if(bretval != false) }
ptoken_user
if (ptoken_user != null)
if(htoken != null)
return bretval ;
}bool processutils::getprocesslist(__out std::vector* proclist)
, cbneeded = 0, cbmneeded = 0;
hmodule hmods[1024];
handle hprocess = null;
tchar szprocessname[max_path] = _t("");
tchar szprocesspath[max_path] = _t("");
if (!enumprocesses( aprocesses, sizeof(aprocesses), &cbneeded )) return false;
for (int i = 0; i < (int)(cbneeded / sizeof(dword)); i++)
return bret;
}
VC常用函式
獲取工作路徑的函式 getcurrentdirectory the getcurrentdirectory function retrieves the current directory for the current process.dword getcurrentdirectory dword...
VC 常用函式
獲得視窗控制代碼 全集 this m hwnd hwnd getforegroundwindow void getsafehwnd 取你程式所在視窗類的控制代碼 getactivewindow 取當前活動視窗控制代碼 afxgetmainwnd 取主視窗控制代碼 getforegroundwindo...
VC常用函式
include stdafx.h include include pragma warning disable 4996 輸出某一資料夾下的所有檔案 包括子資料夾裡的 unsigned intlistdir const char pchdata long handlefind 1 char temp...