Reboot in NT

How do you reboot NT? I have tried ExitWindowsEx with REBOOT  
option.  It just logs you out.  I believe I need the SE_SHUTDOWN privilege but don't know how. Any idea?
Who is Participating?
TKIIConnect With a Mentor Commented:
Ok, I have tried this code (it looks like if it were from the online help he, he, he) and it works fine on my machine. I just created a project (console app) and wrote a main() with this code. I only removed the EWX_FORCE flag. After compiling and starting the programm my machine shuts down. Maybe there is something wrong with some settings. Try to use the administrator account.
Try to read on in the docs. You need to enable some privileges in your access token. See :
GetTokenInformation(), TOKEN_PRIVILEGES, SetTokenInformation() and so on.
When you have enabled that SE_SHUTDOWN than you should be able to reboot.

mnyeuAuthor Commented:
I have tried this and did not work, any idea ?

// Get a token for this process.
if (!OpenProcessToken(GetCurrentProcess(),
                 wsprintf(szBuf, "OpenProcessToken Error #%d", GetLastError ());
        MessageBox(NULL, szBuf, NULL, MB_OK);
   // error("OpenProcessToken");
// Get the LUID for the shutdown privilege.
LookupPrivilegeValue(NULL, SE_SHUTDOWN_NAME,
tkp.PrivilegeCount = 1;  // one privilege to set    
tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
// Get the shutdown privilege for this process.
AdjustTokenPrivileges(hToken, FALSE, &tkp, 0,
// Cannot test the return value of AdjustTokenPrivileges.
if (GetLastError() != ERROR_SUCCESS){
                 wsprintf(szBuf, "Erro AdjustTokenPrivileges #%d", GetLastError ());
        MessageBox(NULL, szBuf, NULL, MB_OK);
 //   error("AdjustTokenPrivileges");
// Shut down the system and force all applications to close.
if (!ExitWindowsEx(EWX_SHUTDOWN | EWX_FORCE, 0))

mnyeuAuthor Commented:
Adjusted points to 100
The code seems ok to me (but I havn't done this before). Have you tried to use GetTokenInformation() to look at your privileges? What happens if you are stepping through the code in the debugger?
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.