G
Gary Lamb
Hi,
I have written a .NET service that, if certain conditions are met, reboots
the server by calling
ExitWindowsEx(EWX_REBOOT + EWX_FORCE, 0)
This works fine on my XP Professional box, but does not work on the server
which is running windows 2000 (it has the framework installed)
The entire function is:
public static void reboot()
{
DoExitWin(EWX_REBOOT + EWX_FORCE);
}
private static void DoExitWin( int flg )
{
bool ok;
TokPriv1Luid tp;
IntPtr hproc = GetCurrentProcess();
IntPtr htok = IntPtr.Zero;
ok = OpenProcessToken( hproc, TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, ref
htok );
tp.Count = 1;
tp.Luid = 0;
tp.Attr = SE_PRIVILEGE_ENABLED;
ok = LookupPrivilegeValue( null, SE_SHUTDOWN_NAME, ref tp.Luid );
ok = AdjustTokenPrivileges( htok, false, ref tp, 0, IntPtr.Zero,
IntPtr.Zero );
ok = ExitWindowsEx( flg, 0 );
}
Does anybody have any ideas?
Thanks
Gary
I have written a .NET service that, if certain conditions are met, reboots
the server by calling
ExitWindowsEx(EWX_REBOOT + EWX_FORCE, 0)
This works fine on my XP Professional box, but does not work on the server
which is running windows 2000 (it has the framework installed)
The entire function is:
public static void reboot()
{
DoExitWin(EWX_REBOOT + EWX_FORCE);
}
private static void DoExitWin( int flg )
{
bool ok;
TokPriv1Luid tp;
IntPtr hproc = GetCurrentProcess();
IntPtr htok = IntPtr.Zero;
ok = OpenProcessToken( hproc, TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, ref
htok );
tp.Count = 1;
tp.Luid = 0;
tp.Attr = SE_PRIVILEGE_ENABLED;
ok = LookupPrivilegeValue( null, SE_SHUTDOWN_NAME, ref tp.Luid );
ok = AdjustTokenPrivileges( htok, false, ref tp, 0, IntPtr.Zero,
IntPtr.Zero );
ok = ExitWindowsEx( flg, 0 );
}
Does anybody have any ideas?
Thanks
Gary