整理出来的一个windows关机、锁定、重启、注销 API调用
来源:互联网 发布:java调用浏览器下载 编辑:程序博客网 时间:2024/05/17 22:19
- 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;
- }
- /// <summary>
- /// 锁定计算机
- /// </summary>
- public static void Lock()
- {
- LockWorkStation();
- }
- /**/
- /// <summary>
- /// 重新启动
- /// </summary>
- public static bool Reboot()
- {
- return DoExitWin(EWX_FORCE | EWX_REBOOT);
- }
- /**/
- /// <summary>
- /// 关机
- /// </summary>
- public static bool PowerOff()
- {
- return DoExitWin(EWX_FORCE | EWX_POWEROFF);
- }
- /**/
- /// <summary>
- /// 注销
- /// </summary>
- public static bool LogOff()
- {
- return DoExitWin(EWX_FORCE | EWX_LOGOFF);
- }
- }
- }
0 0
- 整理出来的一个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# 代码如何实现让你的电脑关机,重启,注销,锁定,休眠,睡眠
- 关机 重启 注销
- 注销 关机 重启
- 关机休眠重启注销的类
- Java中为什么要使用抽象类
- 把jar包拷到WEB-INF/lib和放到工程之外的路径作为library引用有什么不同?
- 一些常用算法的代码(2)
- [置顶] oracle 内连接(inner join)、外连接(outer join)、全连接(full join)
- 内存缓存LruCache源码解析
- 整理出来的一个windows关机、锁定、重启、注销 API调用
- 构造、拷贝构造、赋值
- 有异步请求时注意程序执行的顺序
- 常用函数
- NYOJ113题字符串的替换
- ubuntu16下caffe终于编译成功
- 源码-PL/SQL从入门到精通-第三章-变量和类型-Part 2
- Java常见异常总结
- 第一天软件测试总结