NoteWorthy Composer Forum

Forums => General Discussion => Topic started by: Rick G. on 2007-02-15 11:19 pm

Title: Viewer GPF's using VBScript .Terminate
Post by: Rick G. on 2007-02-15 11:19 pm
Save the code as: ViewerGPF.vbs
Code: [Select · Download]
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
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.
Title: Re: Viewer GPF's using VBScript .Terminate
Post by: Rick G. on 2007-02-16 06:10 am
This does it gracefully:
Code: [Select · Download]
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
Title: Re: Viewer GPF's using VBScript .Terminate
Post by: NoteWorthy Online on 2007-02-17 11:34 am
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.