If you can close the window using ALT+F4, this should work, just substitute program.exe for notepad.exe. The Sleep commands might need to be adjusted, or might not be needed at all. This will not prevent another program from stealing the focus, it simply sends keystrokes to the active window:
Code:
Set objShell = CreateObject("WScript.Shell")
objShell.Run "notepad.exe"
Wscript.Sleep 1500
objShell.SendKeys "filename"
Wscript.Sleep 100
objShell.SendKeys "{ENTER}"
Wscript.Sleep 100
objShell.SendKeys "y"
Wscript.Sleep 100
objShell.SendKeys "{ENTER}"
Wscript.Sleep 100
objShell.SendKeys "%{F4}"
WScript.Quit
The % is used to send ALT.
Notepad will prompt to save when closed, this example lets the user make a choice.
You could send ALT+Y (objShell.SendKeys "%y") to save, send a file name (including drive&path), then ALT+S to save, or ALT+N to not save.
More info on the
SendKeys Method.
AutoIt or AutoHotKeys would also be good choices. I haven't used either enough to be able to recommend one over the other.
HTH
Jerry