VB关机程序--包括注销、重启、关机。 附:(源码) Option Explicit Private Declare Function GetCurrentProcess Lib "kernel32" () As Long Private Declare Function OpenProcessToken Lib "advapi32" (ByVal ProcessHandle As Long, ByVal DesiredAccess As Long, TokenHandle As Long) As Long Private Declare Function LookupPrivilegeValue Lib "advapi32" Alias "LookupPrivilegeValueA" (ByVal lpSystemName As String, ByVal lpName As String, lpLuid As LUID) As Long Private Declare Function AdjustTokenPrivileges Lib "advapi32" (ByVal TokenHandle As Long, ByVal DisableAllPrivileges As Long, NewState As TOKEN_PRIVILEGES, ByVal BufferLength As Long, PreviousState As TOKEN_PRIVILEGES, ReturnLength As Long) As Long Const TOKEN_ADJUST_PRIVILEGES = &H20 Const TOKEN_QUERY = &H8 Const SE_PRIVILEGE_ENABLED = &H2 Private Type LUID UsedPart As Long IgnoredForNowHigh32BitPart As Long End Type Private Type TOKEN_PRIVILEGES PrivilegeCount As Long TheLuid As LUID Attributes As Long End Type Private Declare Function ExitWindowsEx Lib "user32" (ByVal uFlags As Long, ByVal dwReserved As Long) As Long Const HELP_CONTENTS = &H3& Const EWX_WAIT = 16 Const EWX_REBOOT = 2 '重起 Const EWX_LOGOFF = 0 '注销 Const EWX_FORCE = 4 '终止没有响应的进程 Const EWX_SHUTDOWN = 8 '关闭电源 Private Sub Command1_Click() ExitWindowsEx EWX_REBOOT, 0 End Sub Private Sub Command2_Click() ExitWindowsEx EWX_FORCE Or EWX_SHUTDOWN, 0 End Sub Private Sub Command3_Click() ExitWindowsEx EWX_LOGOFF, 0 End Sub Private Sub Command4_Click() End End Sub Private Sub Form_Load() Dim hProcessHandle As Long Dim hTokenHandle As Long Dim tmpLuid As LUID Dim tkpNew As TOKEN_PRIVILEGES Dim tkpPrevious As TOKEN_PRIVILEGES Dim lBufferNeeded As Long '获取当前进程的一个伪句柄 hProcessHandle = GetCurrentProcess() OpenProcessToken hProcessHandle, TOKEN_ADJUST_PRIVILEGES Or TOKEN_QUERY, hTokenHandle LookupPrivilegeValue "", "SeShutdownPrivilege", tmpLuid tkpNew.PrivilegeCount = 1 tkpNew.TheLuid = tmpLuid tkpNew.Attributes = SE_PRIVILEGE_ENABLED lBufferNeeded = 0 '允许当前应用程序有关闭操作系统的权限 AdjustTokenPrivileges hTokenHandle, False, tkpNew, Len(tkpPrevious), tkpPrevious, lBufferNeeded End Sub
- 「已注销」2013-04-27用API关机就是好用
- VidaWang2013-03-06可以用,只是兼容性不太好
- czcszc2014-09-28可以用,很好很强大
- 粉丝: 0
- 资源: 1
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- Autosar学习视频10-19节
- stm32小车.zip
- AshampooUnInstaller v15.00.22 Portable一款强大的卸载工具,彻底、智能著称阿香婆强制卸载软件.rar
- Ashampoo WinOptimizer v27.00.05 阿香婆一款专业的垃圾清理、碎片整理启动项管理系统优化工具.rar
- misc设备驱动 正点原子阿尔法
- youleng-wms JAVA开发的WMS源码可以借签学习 数据库MYSQL
- 385大神asp.net三层设计停车场管理系统毕业课程源码设计+参考论文
- 数据集,训练数据集,深度学习
- 384大神asp.net基于三层汽车进销存销售管理系统毕业课程源码设计
- AutoSAR基础学习资源