整理出来的一个windows关机、锁定、重启、注销 API调用 .
来源:互联网 发布:淘宝不上传身份证清关, 编辑:程序博客网 时间:2024/05/18 02:03
- using System.Runtime.InteropServices;
-
- namespace HookDemo
- {
- class WindowsExit
- {
- [StructLayout(LayoutKind.Sequential, Pack = 1)]
- private struct TokPriv1Luid
- {
- public int Count;
- public long Luid;
- public int Attr;
- }
- [DllImport("kernel32.dll", ExactSpelling = true)]
- private static extern IntPtr GetCurrentProcess();
-
- [DllImport("advapi32.dll", ExactSpelling = true, SetLastError = true)]
- private static extern bool OpenProcessToken(IntPtr h, int acc, ref IntPtr phtok);
-
- [DllImport("advapi32.dll", SetLastError = true)]
- private static extern bool LookupPrivilegeValue(string host, string name, ref long pluid);
-
- [DllImport("advapi32.dll", ExactSpelling = true, SetLastError = true)]
- private static extern bool AdjustTokenPrivileges(IntPtr htok, bool disall,
- ref TokPriv1Luid newst, int len, IntPtr prev, IntPtr relen);
-
- [DllImport("user32.dll", ExactSpelling = true, SetLastError = true)]
- private static extern bool ExitWindowsEx(int DoFlag, int rea);
- [DllImport("user32.dll")]
- public static extern void LockWorkStation();
-
- private const int SE_PRIVILEGE_ENABLED = 0x00000002;
- private const int TOKEN_QUERY = 0x00000008;
- private const int TOKEN_ADJUST_PRIVILEGES = 0x00000020;
- private const string SE_SHUTDOWN_NAME = "SeShutdownPrivilege";
- private const int EWX_LOGOFF = 0x00000000;
- private const int EWX_SHUTDOWN = 0x00000001;
- private const int EWX_REBOOT = 0x00000002;
- private const int EWX_FORCE = 0x00000004;
- private const int EWX_POWEROFF = 0x00000008;
- private const int EWX_FORCEIFHUNG = 0x00000010;
-
- private static bool DoExitWin(int DoFlag)
- {
- 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(DoFlag, 0);
- return ok;
- }
-
-
-
-
- public static void Lock()
- {
- LockWorkStation();
- }
-
-
-
-
-
- public static bool Reboot()
- {
- return DoExitWin(EWX_FORCE | EWX_REBOOT);
- }
-
-
-
-
-
- public static bool PowerOff()
- {
- return DoExitWin(EWX_FORCE | EWX_POWEROFF);
- }
-
-
-
-
-
- public static bool LogOff()
- {
- return DoExitWin(EWX_FORCE | EWX_LOGOFF);
- }
- }
- }
- 整理出来的一个windows关机、锁定、重启、注销 API调用
- 整理出来的一个windows关机、锁定、重启、注销 API调用
- 整理出来的一个windows关机、锁定、重启、注销 API调用 .
- 整理出来的一个windows关机、锁定、重启、注销 API调用
- golang 调用win32 api 实现windows注销、重启、关机
- 调用API关机、重启、注销
- VB2005调用API实现注销、关机和重启
- DELPHI中调用API函数ExitWindowsEX可以实现系统的关机,注销,和重启
- 注册表实现windows系统的关机、注销和重启
- C#下计算机锁定, 注销, 重启, 关机, 休眠, 待机
- C#下计算机锁定, 注销, 重启, 关机, 休眠, 待机
- 编程实现Windows关机、重启、注销
- C# 实现 Windows 关机 重启 注销
- C# 设置电脑关机、重启、注销、锁定、关闭显示器的类(支持win7,win8)
- C# 代码如何实现让你的电脑关机,重启,注销,锁定,休眠,睡眠
- 关机 重启 注销
- 注销 关机 重启
- 关机休眠重启注销的类
- C/C++读取标准输入行
- 黄金价格受哪些因素影响?
- 完成端口之个人理解
- 如今还有人在憎恨比尔盖茨吗?
- 设置Sql Server禁止执行时间长的Sql语句执行
- 整理出来的一个windows关机、锁定、重启、注销 API调用 .
- 如何选择有实力的国际现货黄金(伦敦金)交易平台?
- 实战培训初级班第三次课——我的课前答案
- 急!急!急!烦请Java大神帮助小弟解除动态代理的某些问题!
- Oracle中NULL的定义及其相关处理办法
- 工具链准备好,调试jlink
- 一些关于布林线的知识
- Nginx 1.0.9 在 Ubuntu 11.10 Server 上的安装
- AutoCad 2010安装完成后无法运行