Get windows with title open and close specific title?

How to close a window with a specific title in a Windows XP database using VBscript?

Or is there any other way to solve this problem?

+2
source share
2 answers

You can use the method SendKeysto send the Alt+ shortcut F4to the window you want to close. This window must be active at the moment, so you also need to call AppActivateright before SendKeys.

Basically, you will need something like this:

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

You can add checks and slight delays to make your script more reliable:

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

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

- VBScript, , , :


VBScript , script-coding.info — . , , VBScript, .

+12

, WScript.Shell . , MSWord 2016,    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"
0

All Articles