Skip to main content
Topic: Viewer GPF's using VBScript .Terminate (Read 2786 times) previous topic - next topic

Viewer GPF's using VBScript .Terminate

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.
Registered user since 1996

Re: Viewer GPF's using VBScript .Terminate

Reply #1
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
Registered user since 1996

 

Re: Viewer GPF's using VBScript .Terminate

Reply #2
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.