Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
519 views
in Technique[技术] by (71.8m points)

vbscript - Get title opening windows and close with specific title?

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

Or is there another way to solve this problem?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You can use the SendKeys method to send the Alt+F4 shortcut to the window you wish to close. This window must be active at the moment, so you also need to call AppActivate right before 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.)

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

Learning

References

Other resources


As for VBScript resources in Russian, check out script-coding.info and Серый форум — 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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

56.8k users

...