Automatically closing an excel popup prompt using VBscript

拈花ヽ惹草 提交于 2019-11-29 17:58:05

Unfortunately, AppActivate and SendKeys don't seem to always work so well on popup and dialog windows.

There is a command-line utility called nircmd that can do what you need, however. It's a great tool to have anyway and you'll probably find various other uses for it.

Download it and throw it in the same folder as your VBScript. Or, save it in your System32/SysWow64 folder or any other folder included in your %path% environmental variable. Then include the following statements in your VBScript:

With CreateObject("WScript.Shell")
    .Run "nircmd dlg """" ""Windows Security"" click ok"
End With

The dlg command has the following arguments:

dlg [Process Name] [Window Title] [Action] [Parameters]

We'll leave [Process Name] blank ("""") and just supply the [Window Title]. Note that the quotes here are doubled because they're within a VBS string literal. For the final argument, you need to specify the control ID of the button you want to push/click. For typical dialog buttons (OK, Cancel, Yes, No, etc), you can try using nircmd's predefined control IDs: ok, cancel, yes, no, etc. Otherwise, you'll need to use a tool like Spy++ to determine the button's control ID and pass that instead.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!