【问题标题】:vbscript wont do "if" properly [duplicate]vbscript 不会正确执行“如果”[重复]
【发布时间】:2023-08-27 15:23:01
【问题描述】:

我正在创建一个 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

有人对此有解决方案吗? (我不是想制造一个合法的病毒,这只是我开玩笑的恶作剧)

【问题讨论】:

  • 又一个恶作剧脚本,我们要看多少?

标签: vbscript msgbox


【解决方案1】:

vbNoa constant value equal to 7

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

需要使用变量来获取用户输入的返回值,如:

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

【讨论】: