Solved

Reboot in NT

Posted on 1997-08-07
5
488 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall‚Ķ
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

751 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