How to bring Hotkeyz.exe into focus and send it an Alt+F4 with a VBScript

Rebel_no_1 used Ask the Experts™
I have a straightforward issue:
I launch Hotkeyz.exe with a dos .bat script (Start /MIN Hotkeyz.exe) and have configured the program to go "Hidden" when I click on the close button or Press Alt+F4 on it. Therefore it doesn't close, but goes hidden, which is what I want. The problem is that it launches but it is still just minimized and not closed. The issue is that a user can then ALT+TAB to it and perform unwanted actions. Therefore I need only the following:
I need a simple vbscript which would bring into focus the Hotkeyz.exe application (Which will be minimized) and send it an Alt+F4. After this the vbscript must just close. This would then effectively tell the program to go "Hidden" and avoid the users from Alt+Tab'ing to it and potentially editing and breaking the Hotkeyz.exe app settings. (Intentionally or unintentionally) I would prefer if this script can be compatible with Windows XP and above. Please let me know if any further information is required.
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Most Valuable Expert 2012
Top Expert 2014
Hi, if you change strWindowTitle to the exact window title of the application, this should work.


strWindowTitle = "HotKeyz"
Set objShell = CreateObject("WScript.Shell")
While objShell.AppActivate(strWindowTitle) = 0
	WScript.Sleep 100
objShell.AppActivate strWindowTitle
WScript.Sleep 100
objShell.SendKeys "%{F4}"

Open in new window

Hi Rebel

Rob Sampson's VBScript should work fine for what you need, but just for your additional information it is possible to create a step-by-step script and wrap it up into one program Exe using great little free applications like:

If you use little scripts quite a lot to perform repetitive tasks it might be worthwhile having a look.  basically you run through the actions in a similar way to manually recording a Macro in MS Word, except that you use the program to discover things like the Window Title and the names of the buttons, check boxes, text fields, etc, and compile your script which can then be saved as a single executable.  In other words, you could have a program launcher that opens Hotkeyz.exe and then hides it all in one go.

There are also a couple of simpler programs by the same author that wrap up BAT/CMD or VBS files into a single executable:
(Online version to test:
(Online version to test:
Various useful command line tools:

Remember, this is just for your additional info in future.  Rob has answered your question with a script that should work fine for you.



This script will successfully send an (ALT+F4) command to a specified application. This script will however not send the command to a program which have been minimized. This was tested on win7. Thank you Rob, this works a bit different from what I expected but It will be just fine for me. Thanks again! Much appreciated!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial