using System
class shoutdown{
[StructLayout(LayoutKind
internal struct TokPriv
{
public int Count;
public long Luid;
public int Attr;
}
[DllImport(
internal static extern IntPtr GetCurrentProcess();
[DllImport(
internal static extern bool OpenProcessToken( IntPtr h
[DllImport(
internal static extern bool LookupPrivilegeValue( string host
[DllImport(
internal static extern bool AdjustTokenPrivileges( IntPtr htok
ref TokPriv
[DllImport(
internal static extern bool ExitWindowsEx( int flg
internal const int SE_PRIVILEGE_ENABLED =
internal const int TOKEN_QUERY =
internal const int TOKEN_ADJUST_PRIVILEGES =
internal const string SE_SHUTDOWN_NAME =
internal const int EWX_LOGOFF =
internal const int EWX_SHUTDOWN =
internal const int EWX_REBOOT =
internal const int EWX_FORCE =
internal const int EWX_POWEROFF =
internal const int EWX_FORCEIFHUNG =
private static void DoExitWin(int flg)
{
bool ok;
TokPriv
IntPtr hproc = GetCurrentProcess();
IntPtr htok = IntPtr
ok = OpenProcessToken( hproc
tp
tp
tp
ok = LookupPrivilegeValue( null
ok = AdjustTokenPrivileges( htok
ok = ExitWindowsEx( flg
}
public static void Main()
{
Console
// 修改 EWX_SHUTDOWN 或者 EWX_LOGOFF
// 在XP下可以看到幫助信息
// SHUTDOWN /?
DoExitWin(EWX_SHUTDOWN);
}
}
From:http://tw.wingwit.com/Article/program/net/201311/12498.html