注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

零售创新,创新那些事儿,SPSS,VBA

零售创新

 
 
 

日志

 
 
关于我

新浪微博,零售创新 研究经理,数据分析师 希望和市场研究和零售业的同事共同进步! 本博客发表的都是免费或试用的资料,如果有版权问题请发邮件wangli12a@163.com联系删除。 spss excel vba blog

网易考拉推荐

VB重启开机关机  

2007-07-05 10:28:56|  分类: VB和VBA知识 |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |
VB重启开机关机


Option Explicit
Private Declare Function GetCurrentProcess()Function GetCurrentProcess Lib "kernel32" () As Long
Private Declare Function OpenProcessToken()Function OpenProcessToken Lib "advapi32" (ByVal

ProcessHandle As Long,
 ByVal DesiredAccess As Long, TokenHandle As Long) As Long
Private Declare Function LookupPrivilegeValue()Function LookupPrivilegeValue Lib "advapi32" Alias

"LookupPrivilegeValueA" (
ByVal lpSystemName As String, ByVal lpName As String, lpLuid As LUID) As Long
Private Declare Function AdjustTokenPrivileges()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()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()Sub Command1_Click()
'重新启动计算机
  ExitWindowsEx EWX_REBOOT, 0
End Sub

Private Sub Command2_Click()Sub Command2_Click()
   '关闭计算机
   ExitWindowsEx EWX_FORCE Or EWX_SHUTDOWN, 0
End Sub

Private Sub Command3_Click()Sub Command3_Click()
  End
End Sub

Private Sub Command4_Click()Sub Command4_Click()
  ExitWindowsEx EWX_LOGOFF, 0
End Sub
Private Sub Form_Load()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

  评论这张
 
阅读(690)| 评论(0)
推荐 转载

历史上的今天

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2017