如何将命令包装在 yes/no 消息中?
How do I wrap a command in a yes/no msg?
我想将以下代码调整为 yes/no,甚至可能是 10 秒的定时 "yes"(默认)。我环顾四周,找到了一些答案,但不幸的是,我无法访问能让我快速获得结果的测试环境。
我的 vbs 是:
Set objShell = CreateObject("WScript.Shell")
cmd = "%comspec% /c diskpart /s X:\cleandisk.txt"
objShell.Run cmd,1,1 ' Run the command in a window and wait for a return
我希望能够提示 运行 或绕过它。上下文是 MDT 环境。目的是在成像之前擦除磁盘。不幸的是,它一直 运行s,当我去捕捉图像时,它擦除驱动器(哎呀)。因此,不要让有限的资源变得过于复杂,简单的 yes/no 到 运行 是我的最佳选择。
作为一个选项,我希望在默认 "yes" 答案上有一个 10 秒的倒数计时器。
正如我之前提到的,我并不反对自己解决这个问题,但我在工作中的资源(vbs editos、测试环境等)有限。
您可以使用Popup
方法。
Dim objShell: Set objShell = CreateObject("WScript.Shell")
Select Case objShell.Popup("Run this? Will autorun in 10 seconds!", 10, "Title", 1)
Case -1
'Timed Out
Case 1
'OK Pressed
Case 2
'Cancel Pressed
End Select
Return 值
-1
值:MsgBox 超时。您可以将其与案例 1 结合使用,因为您希望它们执行相同的操作(见下文)
1
值:用户按下了 'OK' 按钮
2
值:用户按下了 'Cancel' 按钮
由于您希望以与用户按下 'OK' 相同的方式处理超时,您可以将这两个值合并为一种情况:
Dim objShell: Set objShell = CreateObject("WScript.Shell")
' This is the timeout ↓↓
Select Case objShell.Popup("Run this? Will autorun in 10 seconds!", 10, "Title", 1)
Case -1, 1
cmd = "%comspec% /c diskpart /s X:\cleandisk.txt"
objShell.Run cmd,1,1
Case 2
' Do nothing
End Select
我想将以下代码调整为 yes/no,甚至可能是 10 秒的定时 "yes"(默认)。我环顾四周,找到了一些答案,但不幸的是,我无法访问能让我快速获得结果的测试环境。
我的 vbs 是:
Set objShell = CreateObject("WScript.Shell")
cmd = "%comspec% /c diskpart /s X:\cleandisk.txt"
objShell.Run cmd,1,1 ' Run the command in a window and wait for a return
我希望能够提示 运行 或绕过它。上下文是 MDT 环境。目的是在成像之前擦除磁盘。不幸的是,它一直 运行s,当我去捕捉图像时,它擦除驱动器(哎呀)。因此,不要让有限的资源变得过于复杂,简单的 yes/no 到 运行 是我的最佳选择。
作为一个选项,我希望在默认 "yes" 答案上有一个 10 秒的倒数计时器。
正如我之前提到的,我并不反对自己解决这个问题,但我在工作中的资源(vbs editos、测试环境等)有限。
您可以使用Popup
方法。
Dim objShell: Set objShell = CreateObject("WScript.Shell")
Select Case objShell.Popup("Run this? Will autorun in 10 seconds!", 10, "Title", 1)
Case -1
'Timed Out
Case 1
'OK Pressed
Case 2
'Cancel Pressed
End Select
Return 值
-1
值:MsgBox 超时。您可以将其与案例 1 结合使用,因为您希望它们执行相同的操作(见下文)1
值:用户按下了 'OK' 按钮2
值:用户按下了 'Cancel' 按钮
由于您希望以与用户按下 'OK' 相同的方式处理超时,您可以将这两个值合并为一种情况:
Dim objShell: Set objShell = CreateObject("WScript.Shell")
' This is the timeout ↓↓
Select Case objShell.Popup("Run this? Will autorun in 10 seconds!", 10, "Title", 1)
Case -1, 1
cmd = "%comspec% /c diskpart /s X:\cleandisk.txt"
objShell.Run cmd,1,1
Case 2
' Do nothing
End Select