Solved

restart

Posted on 1997-02-20
1
184 Views
Last Modified: 2010-04-10
How do I execute a reboot from within Windows NT V4, The standard ExitWindows(EW_REBOOT,0) Just logs you out, and takes you to the logon screen.
0
Comment
Question by:r-carver
1 Comment
 

Accepted Solution

by:
rob_garner earned 200 total points
ID: 1162246
ExitWindowsEx can be used to shutdown the system. but he calling process must have the SE_SHUTDOWN_NAME privilege. See the following example from the SDK documentation:

The following example enables the SE_SHUTDOWN_NAME privilege and then shuts down the system.
 
HANDLE hToken;
TOKEN_PRIVILEGES tkp;
 
/* Get a token for this process. */
 
if (!OpenProcessToken(GetCurrentProcess(),
        TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken))
    error("OpenProcessToken");
 
/* Get the LUID for the shutdown privilege. */
 
LookupPrivilegeValue(NULL, TEXT("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)
    error("AdjustTokenPrivileges");
 
/* Shut down the system and force all applications to close. */
 
if (!ExitWindowsEx(EWX_SHUTDOWN | EWX_FORCE, 0))
    error("ExitWindowsEx");

0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

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…
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
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 technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

776 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