windows 获取标题打开窗口并以特定标题关闭?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2935591/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 07:21:53  来源:igfitidea点击:

Get title opening windows and close with specific title?

windowsvbscript

提问by Alexandr

How can I close a window with a specific title in Windows XP base using VBscript?

如何使用 VBscript 在 Windows XP base 中关闭具有特定标题的窗口?

Or is there another way to solve this problem?

或者有其他方法可以解决这个问题吗?

回答by Helen

You can use the SendKeysmethod to send the Alt+F4shortcut to the window you wish to close. This window must be active at the moment, so you also need to call AppActivateright before SendKeys.

您可以使用该SendKeys方法将Alt+F4快捷方式发送到您要关闭的窗口。此窗口目前必须处于活动状态,因此您还需要在AppActivate之前调用SendKeys

Basically, you'll need something like this:

基本上,你需要这样的东西:

Set oShell = CreateObject("WScript.Shell") 
oShell.AppActivate "Untitled - Notepad"
oShell.SendKeys "%{F4}"

You may want to add checks and small delays to make your script more foolproof:

您可能希望添加检查和小延迟以使您的脚本更加万无一失:

Set oShell = CreateObject("WScript.Shell") 
If oShell.AppActivate("Untitled - Notepad") Then
   WScript.Sleep 500
   oShell.SendKeys "%{F4}"
End If


Edit:(An answer to your comment/question about VBScript resources.)

编辑:(对您关于 VBScript 资源的评论/问题的回答。)

I've compiled some links to VBScript websites and resource pages that I hope they will be helpful:

我已经编译了一些指向 VBScript 网站和资源页面的链接,希望它们会有所帮助:

Learning

学习

References

参考

Other resources

其他资源


As for VBScript resources in Russian, check out script-coding.infoand Серый форум— there're lots of useful and interesting examples. Also, take a look at the this thread, which contains links to many VBScript resources, including those in Russian.


至于俄语的 VBScript 资源,请查看script-coding.infoСерый форум— 有很多有用和有趣的例子。另外,请查看此线程,其中包含指向许多 VBScript 资源(包括俄语资源)的链接。

回答by Ritesh Karwa

Posting this answer for anyone who is still stuck on trying to close the WScript.Shell Object after creating it and not able to find a solution. I tried the above solution and it cause MSWord 2016 to crash, don't know the reason My Vb Script :

为任何在创建 WScript.Shell 对象后仍然试图关闭它而无法找到解决方案的人发布此答案。我尝试了上述解决方案,它导致 MSWord 2016 崩溃,不知道原因 My Vb Script :

        Dim wsh As Object
        Set wsh = CreateObject("WScript.Shell", vbNothing)
        wsh.Run "cmd.exe /C pause"
        wsh.Run "taskkill /F /IM cmd.exe"