sizeof stToken_Privileges

时间:2022-05-27 05:50:18

标签:

BOOL EnableShutdownPrivilege() { HANDLE hProcess = NULL; HANDLE hToken = NULL; LUID uID = {0}; TOKEN_PRIVILEGES stToken_Privileges = {0}; hProcess = ::GetCurrentProcess(); //获取当前应用措施进程句柄 if(!::OpenProcessToken(hProcess,TOKEN_ADJUST_PRIVILEGES,&hToken)) //打开当前进程的访谒令牌句柄(OpenProcessToken函数挪用掉败返回值为零) { return FALSE; } if(!::LookupPrivilegeValue(NULL,SE_SHUTDOWN_NAME,&uID)) //获取权限名称为"SeShutdownPrivilege"的LUID(LookupPrivilegeValue函数挪用掉败返回值为零) { return FALSE; } stToken_Privileges.PrivilegeCount = 1; //欲调解的权限个数 stToken_Privileges.Privileges[0].Luid = uID; //权限的LUID stToken_Privileges.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED; //权限的属性,SE_PRIVILEGE_ENABLED为使能该权限 if(!::AdjustTokenPrivileges(hToken,FALSE,&stToken_Privileges,sizeof stToken_Privileges,NULL,NULL)) //调解访谒令牌里的指定权限(AdjustTokenPrivileges函数挪用掉败返回值为零) { return FALSE; } if(::GetLastError() != ERROR_SUCCESS) //检察权限是否调解告成 { return FALSE; } ::CloseHandle(hToken); return TRUE; }

【API】Windows 措施提升权限函数