Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to activate, kill the process after knowing their pr
Message
General information
Forum:
Visual FoxPro
Category:
Windows API functions
Miscellaneous
Thread ID:
00321552
Message ID:
00322498
Views:
21
>>I have download some Process handling example from UT File Section!
>>i.e. Ramon F. Jaquez enumproc and Bill Donaldson isrunning
>>
>>
>>In early, I want to make a form instead of Ctrl+Alt+Del Dialog to Kiss Process...
>>but the earliest method will be:
>>
>>- Make a list of Process Window TITLE
>>- with "FindWindow" to find the actually hwnd of that process
>>- with "SendMessage" to kill the process...
>>
>>Last two are copied from UT Knowledge Base to kiss process by knowing the process title
>>
>>Now, using your method to a get a list of PROCID,
>>
>>I have tried: ExitProcess, TerminateProcess with pass that ProcID, but VFP quit.. >_<
>>Even I use: SendMessage to that ProcID, still not work..
>

ExitProcess() kills the -current Process- not a different one. An alternative form of suicide to Quit, it permits the return of an error code. See the FAQ.

SendMessage() can request (not force) a clean kill that needs the WindowProc hWnd of a process, not a ProcessID, and if the Process isn't taking messages, you're spinning wheels. TerminateProcess() takes a ProcessHandle and kills the process dead in it's tracks, but it's messy and can leave things in an inconsistent state. A process handle is not the same thing as a ProcessID, or the hWnd of the application's WindowProc.

The hWnd of the WindowProc of a task takes WM_QUIT message from SendMessage() to get an orderly shutdown. WM_DESTROY sent to the parent Window will, if accepted, shut down the Window and all of its direct children and their children, etc...

You can take a look at API_APPRUN which snags the ProcessHandle of an executable that it launches via CreateProcess() and can do an external kill using TerminateProcess(). You can retrieve a similar ProcessHandle using ShellExecuteEx() rather than simpler, structure-free ShellExecute() and get the ProcessHandle of an indirect process launch directly so that TerminateProcess() is easy to use.

Given a ProcessID, you can use OpenProcess() to get a ProcessHandle for the task named by the ProcessID, and can use TerminateProcess() against the handle if the PROCESS_TERMINATE Access right is granted. OpenProcess() in an environment outside of Win9x requires the use of some of the security structures of NT/Win2K to gain permissions to a task you'd like to mangle that you did not launch.

IOW, the ProcessID doesn't take either the directive of SendMessage() or give you a hook to the ProcessHandle needed by TerminateProcess(). Given the ProcessID, you can obtain the process's WindowProc hWnd and use SendMessage() to request a shutdown coopertively, or given adequate security permissions, can request a ProcessHandle that force a messy shutdown via TerminateProcess(). THESE THINGS ARE NOT INTERCHANGABLE OR EQUIVALENT.
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
Next
Reply
Map
View

Click here to load this message in the networking platform