`
dqu53dqu
  • 浏览: 18450 次
最近访客 更多访客>>
社区版块
存档分类
最新评论

VB关机程序

 
阅读更多

VB关机程序
2009年12月26日
  这是我以前写的一个,很牛的.我自己都没办法关,只能照样子输入
  '添加一个按钮command1,一个文本框,text1,和一个时间控件timer1
  '把下面的代码复制到窗体里就可以了.
  '注:任务管理器打不开.自动加入启动项.
  Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
  Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal X As Long, ByVal Y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
  Dim a, i As Integer
  Private Sub Command1_Click()
  a = a + 1
  If a = 3 Then Shell "cmd.exe /c shutdown -s -t 5": Close #1: Close #2: MsgBox "连续三次输入错误,系统5秒后关机.", vbCritical, "关机!"
  If Text1.Text  "我是猪我是猪我是猪" Then
  '------------------------
  Dim myval
  myval = SetWindowPos(Me.hwnd, -2, 0, 0, 0, 0, 3)
  '--------------------
  MsgBox "老老实实的输,不老实的话.嘿嘿,就要关机了." _
  & Chr(13) & Chr(13) & Chr(10) & Chr(10) & "还剩" & (30 - i) & "秒关机!" _
  & Chr(13) & "还剩下" & (3 - a) & "次机会.", vbExclamation, "警告!"
  myval = SetWindowPos(Me.hwnd, -1, 0, 0, 0, 0, 3)
  Else
  Timer1.Interval = 0
  myval = SetWindowPos(Me.hwnd, -2, 0, 0, 0, 0, 3)
  MsgBox "你就是猪.!早讲不就OK了.", vbInformation, "哈哈."
  Close #1
  Close #2
  End
  End If
  End Sub
  Private Sub Form_Load()
  Set w = CreateObject("wscript.shell")
  w.regwrite "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run\" & App.EXEName, App.Path & "\" & App.EXEName & ".exe"
  '加入启动项目
  Close #1
  Close #2
  Open "c:\windows\system32\taskmgr.exe" For Input Lock Read Write As #1
  Open "c:\windows\system32\taskkill.exe" For Input Lock Read Write As #2
  '将窗体的BorderStyle 属性设置为0
  Me.BackColor = vbBlack
  Me.WindowState = 2 '将窗口最大化,全屏
  ' 窗口置前
  Dim myval
  myval = SetWindowPos(Me.hwnd, -1, 0, 0, 0, 0, 3)
  text1.text="点击这里输入三个我是猪!否则三十秒后关机!"
  '==========
  App.TaskVisible = False
  End Sub
  Private Sub Text1_Click()
  If Text1.Text = "点击这里输入三个我是猪!否则三十秒后关机!" Then
  Text1.Text = ""
  Else
  End If
  End Sub
  Private Sub Text1_GotFocus()
  Text1.SelStart = 0
  Text1.SelLength = Len(Text1)
  End Sub
  Private Sub Timer1_Timer()
  i = i + 1
  Command1.Caption = "确定输入" & "(" & (30 - i) & ")"
  If i = 30 Then
  Close #1
  Close #2
  Close #3
  Shell "cmd.exe /c shutdown -s -t 3"
  myval = SetWindowPos(Me.hwnd, -2, 0, 0, 0, 0, 3)
  MsgBox "时间到系统三秒后关机.", vbExclamation, "关机"
  End If
  End Sub
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics