One must specifically enable them for the process:
Code:
Usage: SetProcessPrivilege(SE_SHUTDOWN_NAME);
BOOL SetProcessPrivilege(LPCTSTR lpPrivilege) {
/* This function enables a privilege for the current process */
/* lpPrivilege can be either a privilege constant eg. SE_SHUTDOWN_NAME
* which is DEFINEd in the windows headers to the string
* "SeShutdownPrivilege" or the string can be used directly. */
TOKEN_PRIVILEGES tp;
HANDLE hToken;
LUID luid;
OSVERSIONINFO osvi;
/* Check that we are a Win NT system before proceeding */
osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
GetVersionEx (&osvi);
if (osvi.dwPlatformId != VER_PLATFORM_WIN32_NT)
{
PRINTF("Error: System is not NT based");
return FALSE;
}
/* Get the local id of our desired privilege */
if ( !LookupPrivilegeValue(
NULL, // lookup privilege on local system
lpPrivilege, // privilege to lookup
&luid ) ) // receives LUID of privilege
{
PRINTF("LookupPrivilegeValue error: %u\n", GetLastError() );
return FALSE;
}
/* Fill in TOKEN_PRIVILEGES structure */
tp.PrivilegeCount = 1;
tp.Privileges[0].Luid = luid; // the luid of the privilege to enable
tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
/* Get the access token for the current process */
if ( !OpenProcessToken(
GetCurrentProcess(),
TOKEN_ADJUST_PRIVILEGES,
&hToken ) )
{
PRINTF("OpenProcessToken error: %u\n", GetLastError() );
return FALSE;
}
/* Enable the privilege */
if ( !AdjustTokenPrivileges(
hToken, // access token
FALSE, // don't disable all privileges
&tp, // TOKEN_PRIVILEGES struct
sizeof(TOKEN_PRIVILEGES),
(PTOKEN_PRIVILEGES) NULL,
(PDWORD) NULL) )
{
PRINTF("AdjustTokenPrivileges error: %u\n", GetLastError() );
CloseHandle(hToken);
return FALSE;
}
/* Close the process access token */
CloseHandle(hToken);
return TRUE; //success
}