mnyeu
asked on
Reboot in NT
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?
option. It just logs you out. I believe I need the SE_SHUTDOWN privilege but don't know how. Any idea?
ASKER
I have tried this and did not work, any idea ?
// Get a token for this process.
if (!OpenProcessToken(GetCurr entProcess (),
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].Attribut es = SE_PRIVILEGE_ENABLED;
// Get the shutdown privilege for this process.
AdjustTokenPrivileges(hTok en, 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("AdjustTokenPrivileg es");
// Shut down the system and force all applications to close.
if (!ExitWindowsEx(EWX_SHUTDO WN | EWX_FORCE, 0))
error("ExitWindowsEx");
// Get a token for this process.
if (!OpenProcessToken(GetCurr
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,
&tkp.Privileges[0].Luid);
tkp.PrivilegeCount = 1; // one privilege to set
tkp.Privileges[0].Attribut
// Get the shutdown privilege for this process.
AdjustTokenPrivileges(hTok
(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("AdjustTokenPrivileg
// Shut down the system and force all applications to close.
if (!ExitWindowsEx(EWX_SHUTDO
error("ExitWindowsEx");
ASKER
Adjusted points to 100
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?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
GetTokenInformation(), TOKEN_PRIVILEGES, SetTokenInformation() and so on.
When you have enabled that SE_SHUTDOWN than you should be able to reboot.