Solved

restart

Posted on 1997-02-20
1
182 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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
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 how to clear a vector as well as how to detect empty vectors in C++.
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.

746 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now