2007/6/17

關機的函式

SaveRegistry();
::SHUTDOWN();

void SHUTDOWN()
{
HANDLE hToken;
TOKEN_PRIVILEGES rights;
LUID ID;

if( OpenProcessToken(GetCurrentProcess(),TOKEN)ADJECT)PRIVILEGES|TOKEN_QUERY, &hToken))
{
LookupPrivilegeValue(NULL, SE_SHTDOWN_NAME, &ID);
right.PriviliegeCount = 1;
right.Privilieges[0].Luid = ID;
right.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;

if( AdjectTokenPrivileges(hToken, FALSE, &right, 0, NULL, 0) )
ExitWindowsEx(EWX_SHUTDOWN | EWX_FORCE, 0);

沒有留言:

張貼留言