How to terminate Windows processes?

VA Smalltalk is a "100% VisualAge compatible" IDE that includes the original VisualAge technology and the popular VA Assist and WidgetKit add-ons.

Moderators: Eric Clayberg, wembley, tc, Diane Engles, solveig

How to terminate Windows processes?

Postby Fraray » Mon Jul 21, 2008 7:08 am

Hi all,
I have a question for you: what are the methods to search and terminate a Windows process?

I use VisualAge 6.0.1 with WindowBuilder 6.0.1.

Thank you.

Regards,

Francesco
Fraray
 
Posts: 5
Joined: Tue Jul 01, 2008 10:33 pm

Re: How to terminate Windows processes?

Postby benvandijk » Mon Jul 21, 2008 10:58 pm

Francesco,

To get information about windows processes, look for the psapi.dll on microsoft msdn: http://msdn.microsoft.com/en-us/library/ms684884(VS.85).aspx. This dll has a function for retrieving all processes: EnumProcesses and many more interesting functions.

You can terminate a process once you know its process id, using the windows API:

Code: Select all
killProcess: eenPid
   
   | osHandle exitCode  |
   osHandle := OSHandle openProcess: 16r0001 fInherit: false iDProcess: eenPid.
   exitCode := OSInt32 new.
   osHandle getExitCodeProcess: exitCode.
   osHandle terminateProcess: (exitCode uint32At: 0) 


But be warned: Terminating processes can make your windows system unstable. :(

Greetings, Ben.
benvandijk
 
Posts: 45
Joined: Sun Feb 25, 2007 7:14 am
Location: Arnhem, Netherlands

Re: How to terminate Windows processes?

Postby marten » Mon Jul 21, 2008 11:11 pm

Fraray wrote:Hi all,
I have a question for you: what are the methods to search and terminate a Windows process?

I use VisualAge 6.0.1 with WindowBuilder 6.0.1.

Thank you.

Regards,

Francesco


This is more or less a specific Windows question. To solve problems like this:

* I would search through the Internet to get information about the problem and look for code examples in other languages. At the end of this process one should understand the domain of the solution.
* more or less the answers will concentrate on the usage of one or more API calls within Windows
* knowing the API calls I would look at the PoolDictionary "PlatformFunctions" and search for the entries. There may be no
entries for a specific call (e.g. if it is a a newer API-function introduced in XP or later)
* for each entry I would look for the references to the variable (pop-up menu when inspecting the entry within the PoolDictionary) and finding the references methods I would look for senders.

The answer to your specific question is the API call "TerminateProcess" (if you want to terminate a process from "outside").

Marten
Marten Feldtmann, Principal Smalltalk User, Private
SkypeMe callto://marten.feldtmann
marten
[|]
 
Posts: 641
Joined: Sat Oct 14, 2006 7:10 am
Location: Hamburg - Germany

Re: How to terminate Windows processes?

Postby Fraray » Tue Jul 22, 2008 7:12 am

Ok, thank you very much for your help...

Don't worry Ben, I want to terminate only my processes, not system processes... :wink:

Regards,

Francesco
Fraray
 
Posts: 5
Joined: Tue Jul 01, 2008 10:33 pm

Re: How to terminate Windows processes?

Postby Ralf » Tue Aug 05, 2008 8:13 am

Hi,

another way is finding the window via enum functions and then you can send a wmClose message
to the application. You need 2 methods for this. Here an example how can you do this:

this is the enum function, will send an wmClose message to the window if the process id is found

platformEnumWindowsProcCloseApplication: aHwnd lParam: aLParam

| pid tid wnd |

pid := OSPtr new: 4.
wnd := OSHwnd fromInteger: aHwnd.
tid := wnd getWindowThreadProcessId: pid.
pid := pid int32At: 0.
pid = idProcess "-->>> this is the process id are you must have, in this case it is an instance var in my class"
ifTrue: [wnd postMessage: WmClose wParam: 0 lParam: 0].
^true


this method will call the enum function

platformCloseApplication

| windowProc address |

windowProc :=
EsEntryPoint
receiver: [:hwnd :lParam |
self platformEnumWindowsProcCloseApplication: hwnd lParam: lParam]
selector: #value:value:
callingConvention: 'c'
arrayBased: false
parameterTypes: #(uint32 pointer)
returnType: #boolean.

windowProc failAddress: PlatformFunctions::DefWindowProc address.
address := windowProc address.
PlatformFunctions::EnumWindows callWith: address with: 0.
windowProc unbind.

close the application via wmClose is a little bit softer as TerminateProcess

I hope you can unterstand me:)
Ralf
 
Posts: 41
Joined: Thu Nov 16, 2006 4:18 am


Return to VA Smalltalk 7.0, 7.5 & 8.0

Who is online

Users browsing this forum: Yahoo [Bot] and 1 guest