Save the code as:
ViewerGPF.vbsSet wso = CreateObject("WScript.Shell")
wso.CurrentDirectory = "C:\Program Files\NoteWorthy Composer 2 Viewer"
Set exo = wso.Exec("NWC2View.exe Mozart.nwc /play")
WScript.Sleep 5000
exo.Terminate
Assuming your files are in the standard places, running
ViewerGPF.vbs causes a nasty GPF.
Win98SE locks up, requiring a hard reset. XP recovers, wanting to send a report to M$.
Not a big deal, but it would be useful if would shut down gracefully.
This does it gracefully:
Set wso = CreateObject("WScript.Shell")
wso.CurrentDirectory = "C:\Program Files\NoteWorthy Composer 2 Viewer"
Set exo = wso.Exec("NWC2View.exe Mozart.nwc /play")
WScript.Sleep 5000
If wso.AppActivate(exo.ProcessID) Then wso.SendKeys("%{f4}")
Still, most programs terminate without GPF's
You really shouldn't use the WshScriptExec object's Terminate method on a Windows GUI program.
Using the Terminate method to close our GUI programs will cause them to crash. This is unavoidable due to the way the Terminate method behaves. The Terminate method actually causes the program to crash because it doesn't give the program a chance to actually complete the task (it intentionally creates an abnormal program termination). You should either send the Viewer program a WM_CLOSE message directly, or use keystrokes as you have shown.