永发信息网

c# Windows Mobile 6.0关机代码?

答案:1  悬赏:10  手机版
解决时间 2021-11-09 14:35
  • 提问者网友:蓝莓格格巫
  • 2021-11-08 14:18
c# Windows Mobile 6.0关机代码?
最佳答案
  • 五星知识达人网友:詩光轨車
  • 2021-11-08 15:30
public struct TokPriv1Luid
{
public int Count;
public long Luid;
public int Attr;
}

[DllImport("kernel32.dll",ExactSpelling=true)]
public static extern IntPtr GetCurrentProcess();

[DllImport("advapi32.dll",ExactSpelling=true,SetLastError=true)]

public static extern bool OpenProcessToken(IntPtr h,int acc,ref IntPtr phtok );
[DllImport("advapi32.dll",SetLastError=true)]

public static extern bool LookupPrivilegeValue(string host,string name,ref long pluid );
[DllImport("advapi32.dll",ExactSpelling=true, SetLastError=true) ]

public static extern bool AdjustTokenPrivileges(IntPtr htok,bool disall,
ref TokPriv1Luid newst,int len,IntPtr prev, IntPtr relen);

[DllImport("user32.dll",ExactSpelling=true,SetLastError=true) ]

public static extern bool ExitWindowsEx(int flg,int rea);
public const int SE_PRIVILEGE_ENABLED = 0x00000002; //
public const int TOKEN_QUERY = 0x00000008; //
public const int TOKEN_ADJUST_PRIVILEGES = 0x00000020; //
public const string SE_SHUTDOWN_NAME = "SeShutdownPrivilege";//
public const int EWX_LOGOFF = 0x00000000; // 注消
public const int EWX_SHUTDOWN = 0x00000001; // 先保存再关机
public const int EWX_REBOOT = 0x00000002; // 重启
public const int EWX_FORCE = 0x00000004;//终止没响应程序
public const int EWX_POWEROFF = 0x00000008;//强制关机
public const int EWX_FORCEIFHUNG = 0x00000010;//不保存就关机

///
/// 关机,重启。。。。。
///

///
private void DoExitWin( int flg)
{

bool send;
TokPriv1Luid tp;
IntPtr hproc = GetCurrentProcess();
IntPtr htok = IntPtr.Zero;
send = OpenProcessToken(hproc,TOKEN_ADJUST_PRIVILEGES |TOKEN_QUERY,ref htok );
tp.Count = 1;
tp.Luid = 0;
tp.Attr = SE_PRIVILEGE_ENABLED;
send = LookupPrivilegeValue(null,SE_SHUTDOWN_NAME,ref tp.Luid);
send= AdjustTokenPrivileges(htok,false,ref tp,0,IntPtr.Zero,IntPtr.Zero);
send = ExitWindowsEx(flg,0);
}
///
/// 不保存关闭
///

///
///
private void menuItem9_Click(object sender, System.EventArgs e)
{
DoExitWin(EWX_FORCEIFHUNG);
}
///
/// 强制关闭
///

///
///
private void menuItem8_Click(object sender, System.EventArgs e)
{
DoExitWin(EWX_POWEROFF);
}
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯