Hi,
I need to REBOOT the machine(not just SHUTDOWN)
But the reboot works in LOCAL ADMINISTRATOR login only.
I have admin privileges on my system. User Name is not Administrator.
But i have all the admin privileges on the machine.I need to reboot from my
login too.
I have used the EWX_REBOOT in ExitWindowsEx function with EWX_FORCE also to
force reboot.
Windows NT/2000/XP: The calling process must have the SE_SHUTDOWN_NAME
privilege.
hence the code that is given wiht MSDN was tried out.
if (!OpenProcessToken(GetCurrentProcess(),
TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken))
{
dw = GetLastError();
sprintf(szTemp, “OpenProcessToken failed: GetLastError returned %u\n”,dw);
LOGERROR(szTemp);
}
// Get the LUID for the shutdown privilege.
if(0 == LookupPrivilegeValue(NULL, SE_SHUTDOWN_NAME,
&tkp.Privileges[0].Luid))
{
dw = GetLastError();
sprintf(szTemp, “LookupPrivilegeValue failed: GetLastError returned
%u\n”,dw);
LOGERROR(szTemp);
}
tkp.PrivilegeCount = 1; // one privilege to set
tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
// Get the shutdown privilege for this process.
if(ERROR_SUCCESS != AdjustTokenPrivileges(hToken, FALSE, &tkp, 0,
(PTOKEN_PRIVILEGES)NULL, 0))
{
dw = GetLastError();
sprintf(szTemp, “AdjustTokenPrivileges failed: GetLastError returned
%u\n”,dw);
LOGERROR(szTemp);
}
// Cannot test the return value of AdjustTokenPrivileges.
// Shut down the system and force all applications to close.
if (!ExitWindowsEx(EWX_REBOOT|EWX_FORCE, 0))
{
dw = GetLastError();
sprintf(szTemp, “ExitWindowsEx failed: GetLastError returned %u\n”,dw);
LOGERROR(szTemp);
}
Anyone can help me with this?
Thanks in advance
Venkat