Solved

Reboot in NT

Posted on 1997-08-07
5
487 Views
Last Modified: 2008-03-17
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?
0
Comment
Question by:mnyeu
  • 3
  • 2
5 Comments
 
LVL 1

Expert Comment

by:TKII
ID: 1167004
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.

0
 

Author Comment

by:mnyeu
ID: 1167005
I have tried this and did not work, any idea ?

// Get a token for this process.
 
if (!OpenProcessToken(GetCurrentProcess(),
        TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken)) {
                 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.Privileges[0].Luid);
 
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,
        (PTOKEN_PRIVILEGES)NULL, 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))
    error("ExitWindowsEx");

0
 

Author Comment

by:mnyeu
ID: 1167006
Adjusted points to 100
0
 
LVL 1

Expert Comment

by:TKII
ID: 1167007
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?
0
 
LVL 1

Accepted Solution

by:
TKII earned 100 total points
ID: 1167008
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.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

679 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question