求关机代码
解决方案 »
- 用input语句为什么读不出所有的文件内容?(文件可能是随机文件,用记事本看有乱码,但也能全部显示)
- 找到工作啦!散分,大家快来抢啊!!
- 创建activex 控件中的错误处理
- 听说有种REAL插件安装后可以不安装REAL就可以播放RM电影了?
- 有關於CryStal Report 有VB打包的問題?
- 不遍历,能知某folder下的文件总数不?不需要subfolder
- 在VB中如何动态地添加,删除数组?
- Qbcolor()函数的用法
- 从那能下sql7桌面版?
- 在VB6中,如何把动态生成的recordset送给activeReport,以便生成报表??
- 急需毕业论文一篇!!
- 使用数据窗体向导,说无法识别的数据库,怎么回事?
Shell "c:\windows\rundll32.exe user.exe,exitwindows"
Public Declare Function ExitWindowsEx Lib "user32" Alias "ExitWindowsEx" (ByVal uFlags As Long, ByVal dwReserved As Long) As LongPublic Const EWX_LOGOFF = 0
Public Const EWX_SHUTDOWN = 1
Public Const EWX_REBOOT = 2
Public Const EWX_FORCE = 4
Private Declare Function ShellAbout Lib "shell32.dll" Alias "ShellAboutA" (ByVal hwnd As Long, ByVal szApp As String, ByVal szOtherStuff As String, ByVal hIcon As Long) As Long
Private Declare Function ExitWindowsEx Lib "user32" (ByVal uFlags As Long, ByVal dwReserved As Long) As Long
Const SHUTDOWN = 1
Const REBOOT = 2
Const LOGOFF = 0
Dim sh As Long
Dim counter As Integer
Dim n As IntegerPrivate Sub Check1_Click()
If Check1.Value = 1 Then
Label3(0).Caption = "小时"
End If
End SubPrivate Sub Check2_Click()
If Check2.Value = 1 Then
Label3(0).Caption = "点"
End If
End SubPrivate Sub Combo1_click()
Combo1.BackColor = &H800000
Combo1.ForeColor = &HFFFFFF
Select Case Combo1.ListIndex
Case 0
Label2.Caption = "结束会话,关闭Windows,以便安全关闭电源。"
Case 1
Label2.Caption = "结束会话,关闭Windows,然后重新启动。"
Case 2
Label2.Caption = "结束会话,用户重新登陆。"
End Select
End SubPrivate Sub Combo1_DropDown()
Combo1.BackColor = &HFFFFFF
Combo1.ForeColor = &H0
End SubPrivate Sub Command1_Click()
Dim str As String
If Command2.Enabled = True Then
Select Case Combo1.ListIndex
Case 0
shutdown1
Case 1
reboot1
Case 2
logoff1
End Select
Else
If Check1.Value = 0 And Check2.Value = 0 And Check3.Value = 0 Then
Select Case Combo1.ListIndex
Case 0
shutdown1
Case 1
reboot1
Case 2
logoff1
End Select
Else
If Check1.Value = 0 And Check2.Value = 0 Then
str = MsgBox("你还有设置漏选!", 48, "错误")
End If
End If
n = Val(Text1.Text) * 3600 + Val(Text2.Text) * 60 + Val(Text3.Text)
If Check2.Value = 1 Then
If Text1.Text = "" Then
Text1.Text = "0"
End If
If Text2.Text = "" Then
Text2.Text = "0"
End If
If Text3.Text = "" Then
Text3.Text = "0"
End If
End If
If Check1.Value = 1 Then
If Val(Text3.Text) > 60 Or Val(Text2.Text) > 60 Then
MsgBox "填入的数据错误,要重填!", 48, "错误"
n = 0
Exit Sub
End If
If Text1.Text <> "0" And Text2.Text = "0" Then
Text2.Text = "60"
End If
If Text2.Text <> "0" And Text3.Text = "0" Then
Text3.Text = "60"
End If
End If
Timer1.Enabled = True
End If
End SubPrivate Sub Command2_Click()
Dim str As String
If Combo1.Text = "" Then
str = MsgBox("请选择操作类型!", 0, "错误")
Exit Sub
End If
Frame1.Visible = True
Command2.Enabled = False
End SubPrivate Sub Command3_Click()
End
End SubPrivate Sub Command4_Click()
Call ShellAbout(hwnd, "关闭Windows", "本软件由 HydeKong 制作!" & vbCrLf & "谢谢使用!", Me.Icon)
End SubPrivate Sub Command5_Click()
If Timer1.Enabled = True Then
Timer1.Enabled = False
End If
Text1.Text = 0
Text2.Text = 0
Text3.Text = 0
End SubPrivate Sub Form_Load()
Frame1.Visible = False
Label2.Caption = ""
Combo1.AddItem "关机"
Combo1.AddItem "重新启动"
Combo1.AddItem "注销"
counter = 0
Timer1.Enabled = False
End SubPrivate Sub shutdown1()
sh = ExitWindowsEx(SHUTDOWN, dwReserved)
End SubPrivate Sub reboot1()
sh = ExitWindowsEx(REBOOT, dwReserved)
End SubPrivate Sub logoff1()
sh = ExitWindowsEx(LOGOFF, dwReserved)
End SubPrivate Sub Text1_KeyPress(KeyAscii As Integer)
Key = Chr(KeyAscii)
If KeyAscii <> 8 And Key < "0" Or Key > "9" Then
MsgBox "请填入数字!"
End If
End SubPrivate Sub Text2_KeyPress(KeyAscii As Integer)
Key = Chr(KeyAscii)
If KeyAscii <> 8 And Key < "0" Or Key > "9" Then
MsgBox "请填入数字!"
End If
End SubPrivate Sub Text3_KeyPress(KeyAscii As Integer)
Key = Chr(KeyAscii)
If KeyAscii <> 8 And Key < "0" Or Key > "9" Then
MsgBox "请填入数字!"
End If
End SubPrivate Sub Timer1_Timer()
counter = counter + 1
If Check1.Value = 1 Then
If Text1.Text <> 0 And Text2.Text = "60" Then
Text1.Text = Text1.Text - "1"
End If
If Text2.Text <> 0 And Text3.Text = "60" Then
Text2.Text = Text2.Text - "1"
End If
If Text3.Text <> 0 Then
Text3.Text = Text3.Text - "1"
End If
If Text2.Text = "0" And Text1.Text <> "0" Then
Text2.Text = "60"
End If
If Text3.Text = "0" And Text2.Text <> "0" Then
Text3.Text = "60"
End If
End If
Dim ch As String
If Check3.Value = 1 Then
If n > 300 Then
If n - counter = 300 Then
Dim rtn
rtn = SetWindowPos(Me.hwnd, -1, 0, 0, 0, 0, 3)
ch = MsgBox("还有5分钟就要关机,是否继续执行?", 48 + vbYesNo, "提醒")
If ch = vbNo Then
Timer1.Enabled = False
rtn = SetWindowPos(Me.hwnd, -2, 0, 0, 0, 0, 3)
counter = 0
Exit Sub
Else
MsgBox "请做好数据保存,就要关机了!", 48, "提醒"
End If
End If
End If
End If
If (n - counter) = 0 Then
Select Case Combo1.ListIndex
Case 0
shutdown1
Case 1
reboot1
Case 2
logoff1
End Select
End If
End Sub