Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Reboot in NT

Posted on 1997-08-07
5
Medium Priority
?
490 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 400 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
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.
Suggested Courses

704 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