参照下面代码
using namespace std;
typedef vector<PROCESSENTRY32> EXEINFOLIST;
typedef EXEINFOLIST::iterator EXEINFOITER;
BOOL GetExeList()
{
PROCESSENTRY32 ExeInfo;
ExeInfo.dwSize=sizeof(ExeInfo);
DWORD dwLastError = 0;
HANDLE hProcessSnap = ::CreateToolhelp32Snapshot(TH32CS_SNAPALL, 0);
if(hProcessSnap == INVALID_HANDLE_VALUE)
{
dwLastError = ::GetLastError();
return FALSE;
}
BOOL bMore=::Process32First(hProcessSnap,&ExeInfo);
if (bMore) {
m_ProcessList.push_back(ExeInfo);
}
while(bMore)
{
bMore=::Process32Next(hProcessSnap,&ExeInfo);
if (!bMore) {
dwLastError = ::GetLastError();
}
else {
m_ProcessList.push_back(ExeInfo);
}
}
::CloseHandle(hProcessSnap);
return TRUE;
}
typedef struct tagPROCESSENTRY32 {
DWORD dwSize;
DWORD cntUsage;
DWORD th32ProcessID;
ULONG_PTR th32DefaultHeapID;
DWORD th32ModuleID;
DWORD cntThreads;
DWORD th32ParentProcessID;
LONG pcPriClassBase;
DWORD dwFlags;
TCHAR szExeFile[MAX_PATH]; } PROCESSENTRY32,
*PPROCESSENTRY32;
提高进程权限
BOOL EnablePriv()
{
HANDLE hToken;
if ( OpenProcessToken(GetCurrentProcess(),TOKEN_ADJUST_PRIVILEGES,&hToken) )
{
TOKEN_PRIVILEGES tkp;
LookupPrivilegeValue( NULL,SE_DEBUG_NAME,&tkp.Privileges[0].Luid );
tkp.PrivilegeCount=1;
tkp.Privileges[0].Attributes=SE_PRIVILEGE_ENABLED;
AdjustTokenPrivileges( hToken,FALSE,&tkp,sizeof tkp,NULL,NULL );
return( (GetLastError()==ERROR_SUCCESS) );
}
return TRUE;
}
using namespace std;
typedef vector<PROCESSENTRY32> EXEINFOLIST;
typedef EXEINFOLIST::iterator EXEINFOITER;
BOOL GetExeList()
{
PROCESSENTRY32 ExeInfo;
ExeInfo.dwSize=sizeof(ExeInfo);
DWORD dwLastError = 0;
HANDLE hProcessSnap = ::CreateToolhelp32Snapshot(TH32CS_SNAPALL, 0);
if(hProcessSnap == INVALID_HANDLE_VALUE)
{
dwLastError = ::GetLastError();
return FALSE;
}
BOOL bMore=::Process32First(hProcessSnap,&ExeInfo);
if (bMore) {
m_ProcessList.push_back(ExeInfo);
}
while(bMore)
{
bMore=::Process32Next(hProcessSnap,&ExeInfo);
if (!bMore) {
dwLastError = ::GetLastError();
}
else {
m_ProcessList.push_back(ExeInfo);
}
}
::CloseHandle(hProcessSnap);
return TRUE;
}
typedef struct tagPROCESSENTRY32 {
DWORD dwSize;
DWORD cntUsage;
DWORD th32ProcessID;
ULONG_PTR th32DefaultHeapID;
DWORD th32ModuleID;
DWORD cntThreads;
DWORD th32ParentProcessID;
LONG pcPriClassBase;
DWORD dwFlags;
TCHAR szExeFile[MAX_PATH]; } PROCESSENTRY32,
*PPROCESSENTRY32;
提高进程权限
BOOL EnablePriv()
{
HANDLE hToken;
if ( OpenProcessToken(GetCurrentProcess(),TOKEN_ADJUST_PRIVILEGES,&hToken) )
{
TOKEN_PRIVILEGES tkp;
LookupPrivilegeValue( NULL,SE_DEBUG_NAME,&tkp.Privileges[0].Luid );
tkp.PrivilegeCount=1;
tkp.Privileges[0].Attributes=SE_PRIVILEGE_ENABLED;
AdjustTokenPrivileges( hToken,FALSE,&tkp,sizeof tkp,NULL,NULL );
return( (GetLastError()==ERROR_SUCCESS) );
}
return TRUE;
}