VB如何自定义关机

来源:百度知道 编辑:UC知道 时间:2024/06/01 13:06:53
本人创建了一个Command和一个TEXTBOX 如何在TEXTBOX输如指定时间然后按 COMMAND按纽就倒计时关机 按下command按钮调用textbox内输入的指定时间 有简单的吗不要太复杂了

有简单的。不要太复杂了。
在Text1中输入的是时间,单位是秒。例如想50秒后关机就输入50。代码如下。
----------------------------------
Private Declare Function ExitWindowsEx Lib "user32" (ByVal uFlags As Long, ByVal dwReserved As Long) As Long
Dim t As Long
Private Sub Command1_Click()
t = Val(Text1.Text)
End Sub

Private Sub Form_Load()
Timer1.Interval = 1000
End Sub

Private Sub Timer1_Timer()
t = t - 1
If t = 0 Then ExitWindowsEx EWX_SHUTDOWN
End Sub

一楼的只能用于XP系统,因为2000没有SHUTDOWN文件
可以用API实现通用关机程序.
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