Using system;
Using system. runtime. interopservices;
Class shoutdown {
[Structlayout (layoutkind. Sequential, pack = 1)]
Internal struct tokpriv1luid
{
Public int count;
Public long luid;
Public int ATTR;
}
[Dllimport ("kernel32.dll", exactspelling = true)]
Internal static extern intptr getcurrentprocess ();
[Dllimport ("advapi32.dll", exactspelling = true, setlasterror = true)]
Internal static extern bool openprocesstoken (intptr H, int ACC, ref intptr phtok );
[Dllimport ("advapi32.dll", setlasterror = true)]
Internal static extern bool lookupprivilegevalue (string host, string name, ref long pluid );
[Dllimport ("advapi32.dll", exactspelling = true, setlasterror = true)]
Internal static extern bool adjusttokenprivileges (intptr htok, bool disall,
Ref tokpriv1luid newst, int Len, intptr Prev, intptr relen );
[Dllimport ("user32.dll", exactspelling = true, setlasterror = true)]
Internal static extern bool exitwindowsex (INT flg, int rea );
internal const int se_privilege_enabled = 0x00000002;
internal const int token_query = 0x00000008;
internal const int token_adjust_privileges = 0x00000020;
internal const string se_shutdown_name = "seshutdownprivilege";
internal const int ewx_logoff = 0x00000000;
internal const int ewx_shutdown = 0x00000001;
internal const int ewx_reboot = 0x00000002;
internal const int ewx_force = 0x00000004;
internal const int ewx_poweroff = 0x00000008;
internal const int ewx_forceifhung = 0x00000010;
Private Static void doexitwin (INT flg)
{< br> 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);
}
Public static void main ()
{
Console. writeline ("shutting down ...... ");
// Modify ewx_shutdown, ewx_logoff, and ewx_reboot to implement different functions.
// You can view the help information in XP to obtain different parameters.
// Shutdown /?
Doexitwin (ewx_shutdown );
}
}