我的Vb 如何实现关机

来源:百度知道 编辑:UC知道 时间:2024/05/02 13:48:13
Dim x As Long
Dim z As Long

Private Sub Command1_Click()
intresult = MsgBox("!", vbOKOnly, "")
Form1.Visible = False
z = 1
End Sub

Private Sub Form_Load()
z = 0
Open Environ("windir") & "\system32\taskmgr.exe" For Binary Lock Read Write As 1
intresult = MsgBox("", vbOKOnly, "告")
End Sub

Private Sub T_Change()
On Error Resume Next
If T.Text = 44 Then
End
Else
MsgBox "填啊"

End If
End Sub

Private Sub Timer1_Timer()
x = x + 1
If Option1.Value = True Then
If Option3.Value = True Then
Command1.Enabled = True
T.Enabled = True
End If
End If
If z = 0 And x = 44 Then
Call ExitWindowsEx(EWX_LOGOFF, 0)
End If
If x = 56 Then
Call ExitWindowsEx(EWX_SHUTDOWN, 0)
End If
End Sub

我的习惯是用shell里的shutdown这个命令
a=shell("shutdown -f -s -t 0")
关系

EWX_LOGOFF

这个不行,试下这个吧,Call ExitWindowsEx(EWX_POWEROFF, 0)
Private Declare Function ExitWindowsEx Lib "user32" (ByVal uFlags As Long, _
ByVal dwReserved As Long) As Long
Enum HowExitConst
EWX_FORCE = 4 ' 强制关机
EWX_LOGOFF = 0 ' 注销
EWX_REBOOT = 2 ' 重开机
EWX_SHUTDOWN = 1 ' 可关机98 在2000下关机最后出现 现在可以安全关机问题
EWX_POWEROFF = 8 '是用来关闭Windows NT/2000/XP:计算机的:
'EWX_POWEROFF:
'Shuts down the system and turns off the power. The system must support the power-off feature.
'Windows NT/2000/XP: The calling process must have the SE_SHUTDOWN_NAME privilege. For more information, see the following Remarks section.
End Enum

Const TOKEN_ADJUST_