Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Put an Icon in a WSH Script?
Message
General information
Forum:
Visual FoxPro
Category:
Windows API functions
Miscellaneous
Thread ID:
00478045
Message ID:
00479008
Views:
49
>
>I'll look in the API library now for examples.
>

TerminateProcess() is an absolute kill, even if the event loop stops responding to Windows Messages. The best choice is to send a WM_CLOSE to the thread rather than the Window using PostThreadMessage(), which takes the ThreadID (available as a property of API_APPRUN; wait a few seconds and see if the app terminates using CheckProcessExitCode(), and if it's still running, issue the TerminateProcess(). The modified code for API_APPRUN's KillProc method to use this approach would read:
LPARAMETER nProcessToKill, nThreadToKill
IF TYPE('nProcessToKill') # 'N'
   nProcessToKill = This.inProcessHandle
ENDIF
IF TYPE('nThreadToKill') # 'N'
   nThreadToKill = This.inThreadID
ENDIF
DECLARE INTEGER PostThreadMessage IN USER32 ;
   INTEGER idThread, ;
   INTEGER nMsg, ;
   INTEGER wParam, ;
   INTEGER lParam
DECLARE Sleep IN WIN32API INTEGER
#DEFINE WM_CLOSE 0x10
=PostThread(nThreadToKill,WM_CLOSE,0,0)
=Sleep(3000)  && 3 second delay
IF this.CheckProcessExitCode(nProcessToKill) # 259
   RETURN .T.
ENDIF 
=Sleep(3000)  && 3 second delay
IF this.CheckProcessExitCode(nProcessToKill) # 259
   RETURN .T.
ENDIF 

*  Still running, so blow it away

DECLARE SHORT TerminateProcess IN WIN32API AS KillProc ;
	INTEGER hProcess, ;
	INTEGER uExitCode
LOCAL nResult
IF ! ISNULL(nProcessToKill)
	nResult = KillProc(nProcessToKill,0)
	this.icErrorMessage = IIF(nResult = 0, 'TerminateProcess() could not kill process handle requested','')
ELSE
	this.icErrorMessage = 'NULL handle passed to KillProc()'
	nResult = 0
ENDIF
RETURN (nResult = 1)
>
>>>Thanks again, you always make me think a little more on stuph like this.
>>
>>Glad to be of help.
>
>Thanks again!
EMail: EdR@edrauh.com
"See, the sun is going down..."
"No, the horizon is moving up!"
- Firesign Theater


NT and Win2K FAQ .. cWashington WSH/ADSI/WMI site
MS WSH site ........... WSH FAQ Site
Wrox Press .............. Win32 Scripting Journal
eSolutions Services, LLC

The Surgeon General has determined that prolonged exposure to the Windows Script Host may be addictive to laboratory mice and codemonkeys
Previous
Reply
Map
View

Click here to load this message in the networking platform