HANDLE token;
TOKEN PRIVILEGES tokenPriv;
::OpenProcessToken(::GetCurrentProcess(),TOKEN_ALL_ACCESS, &token);
::LookupPrivilegeValue(NULL,SE_DEBUG_NAME, &tokenPriv.Privileges[0].Luid);
tokenPriv.PrivilegeCount=1;
tokenPriv.Privileges[0].AttributeS = SE_PRIVILEGE_ENABLED;
::AdjustTokenPrivileges(token, FALSE,&tokenPriv,0,(PTOKEN_PRIVILEGES)NULL, 0);
::CloseHandle(token);
通过以上代码便可以实现在程序中获取系统权限;
HANDLE snapShot = ::CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
PROCESSENTRY32 processInfo;
processInfo.dwSize=sizeof(processInfo);
for(::Process32First(snapShot,&processInfo);::Process32Next(snapShot,&processInfo);)
{
QString processName =QString::fromUtf16(reinterpret cast<const ushort *>(processInfo.szExeFile));
if(processName == "xxxx.exe")
list.append(processInfo.th32ProcessID);
}
::CloseHandle(snapShot);
通过修改“xxxx.exe"便可以获取系统中正在运行的,名称为“xxxx.exe"的应用程序的数量