vbs打开,循环显示消息,关闭应用程序

时间:2018-11-07 14:20:11

标签: vbscript

我已使用以下代码解决了其中一些问题。我被卡住的部分是通过消息弹出框循环回来的。如果答案是肯定的,我希望它循环回到顶部。如果答案是否定的,我希望它退出循环并关闭程序;如果消息框超时,我希望它退出循环并关闭程序。请在下面查看我的代码。预先感谢您的帮助。

Dim PromptTime, DelayTime, StrAppPath, AppExec, MsgTxt, intAnswer, intRet

Set objShell = CreateObject("WScript.Shell")

PromptTime = 5
DelayTime = 4
StrAppPath = "C:Windows\"
AppExec = "Notepad.exe"
MsgTxt = "Are you still using Notepad?"
intMsgTimeout = 5
Set WshShell= CreateObject("WScript.Shell")

objShell.Run chr(34) & StrAppPath & AppExec & chr(34), 1, "False"
Do
WScript.Sleep (1000 * 1 * PromptTime)
'intAnswer = MsgTxt(MsgTxt, vbYesNo, "Please select Yes or No")
intResult = WshShell.Popup(MsgTxt, intMsgTimeout, "Warning!", vbYesNo)

Select Case WshShell
Case vbYes
If intResult = vbYes Then Do

Case vbNo
If intResult = vbNo Then Exit Do

'Case Else
If intResult = Else Then Exit Do

End Select
Loop

taskKill = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & taskKill & "\root\cimv2")

Set processlistFull= objWMIService.ExecQuery _
("Select * from Win32_Process Where name = 'Notepad.exe'")

For Each killPro In processlistFull
killPro.Terminate()
Next

Set objShell = Nothing
Set objWmi = Nothing
Set objQResult = Nothing

1 个答案:

答案 0 :(得分:0)

我发现了一种通过“循环播放”并删除“选择大小写”的方法:

Do
WScript.Sleep (1000 * 1 * PromptTime)
Loop While WshShell.Popup("Are you still using Syteline?", 5, "Please select yes or no", vbYesNo) = vbYes