您的批评和鼓励都是我把编程无限办好的动力! 您编程时遇到困难,或遇到不顺心的事想发发牢骚尽管到这里来吧! 虽然本网力求全面,但也不能包罗万象,这些我筛选出的优秀网站连接就是对本站最好的补充! 学习编程当然也离不开书本了,这里收集大量编程书籍! 编程无限之源码超市,这里收集的代码令你意想不到的全面! 欢迎光临编程网校,这里专门收集VB/CB入门文章及技术文章! 欢迎光临编程无限!
     
       
 
当前位置:中文资料 >> 系统控制
重启Windows 2000(NT系统)
  资料类型: 系统控制 上传时间: 2001-02-21 阅读次数: 3425



重启Windows 2000/NT系统
作者:MadAd

  重新启动Windows 2000/NT系统

 Reboots a Windows 2000 PC. Many examples shell to the kernel and just kill the PC. This does it properly and takes into account a user privilages.

'API Calls used for RebootPC

Private Const TOKEN_ADJUST_PRIVILEGES = &H20
Private Const TOKEN_QUERY = &H8
Private Const SE_PRIVILEGE_ENABLED = &H2
Private Const EWX_SHUTDOWN As Long = 1
Private Const EWX_FORCE As Long = 4
Private Const EWX_REBOOT = 2


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 dwOptions As Long, ByVal dwReserved As Long) As Long
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


Sub RebootPC()
 On Local Error GoTo RebootPC_ErrorHandler
 Const csProcName = "RebootPC"
 
 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()
 Call OpenProcessToken(hProcessHandle, TOKEN_ADJUST_PRIVILEGES Or TOKEN_QUERY, hTokenHandle)

' Get the LUID for the shutdown privilege
 Call LookupPrivilegeValue("", "SeShutdownPrivilege", tmpLuid)

 tkpNew.PrivilegeCount = 1 ' One privilege to set
 tkpNew.TheLuid = tmpLuid
 tkpNew.Attributes = SE_PRIVILEGE_ENABLED

' Enable the shutdown privilege in the access token of this process.
 lBufferNeeded = 0
 Call AdjustTokenPrivileges(hTokenHandle, False, tkpNew, Len(tkpPrevious), tkpPrevious, lBufferNeeded)

' Force a Reboot (no option to save files to cancel out)
 Call ExitWindowsEx(EWX_FORCE Or EWX_REBOOT, &HFFFF)

 Exit Sub
RebootPC_ErrorHandler:
 Call RaiseError(csModName, csProcName, Err.Number, Err.Description)
End Sub

推荐给朋友 点 评( 0 ) 返回前页 关闭此页
   
  本类最热文章排名:
  1.自动开始上次关机时关闭的应用
2.怎样存取注册表信息
3.怎样关闭一个正在运行的程序
4.怎样延迟一个VB程序?
5.如何使用 VB 编写自动反安装的程序?
6.用键盘操纵控件
7.怎样限制鼠标移动
8.用VB编写键盘拦截程序
9.自动记录应用软件工作时间
10.怎样捕捉窗体的鼠标?
   
   
  评论:
 
 
 

 

关于本站 版权声明 联系方法
编程无限 V4.1 Copyright © 1999-2009 21code.com

京ICP备05006938号