您好,登錄后才能下訂單哦!
BOOL EnableShutdownPrivilege()
{
HANDLE hProcess = NULL;
HANDLE hToken = NULL;
LUID uID = {0};
TOKEN_PRIVILEGES stToken_Privileges = {0};
hProcess = ::GetCurrentProcess(); //獲取當(dāng)前應(yīng)用程序進(jìn)程句柄
if(!::OpenProcessToken(hProcess,TOKEN_ADJUST_PRIVILEGES,&hToken)) //打開(kāi)當(dāng)前進(jìn)程的訪問(wèn)令牌句柄(OpenProcessToken函數(shù)調(diào)用失敗返回值為零)
{
return FALSE;
}
if(!::LookupPrivilegeValue(NULL,SE_SHUTDOWN_NAME,&uID)) //獲取權(quán)限名稱為"SeShutdownPrivilege"的LUID(LookupPrivilegeValue函數(shù)調(diào)用失敗返回值為零)
{
return FALSE;
}
stToken_Privileges.PrivilegeCount = 1; //欲調(diào)整的權(quán)限個(gè)數(shù)
stToken_Privileges.Privileges[0].Luid = uID; //權(quán)限的LUID
stToken_Privileges.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED; //權(quán)限的屬性,SE_PRIVILEGE_ENABLED為使能該權(quán)限
if(!::AdjustTokenPrivileges(hToken,FALSE,&stToken_Privileges,sizeof stToken_Privileges,NULL,NULL)) //調(diào)整訪問(wèn)令牌里的指定權(quán)限(AdjustTokenPrivileges函數(shù)調(diào)用失敗返回值為零)
{
return FALSE;
}
if(::GetLastError() != ERROR_SUCCESS) //查看權(quán)限是否調(diào)整成功
{
return FALSE;
}
::CloseHandle(hToken);
return TRUE;
}
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。