Killing Processes

Discuss RoboTask here
Post Reply
markan
Posts: 6
Joined: Wed Apr 06, 2005 11:29 am

Killing Processes

Post by markan »

Hi
Is there an easy way to kill a process that is running i.e. The equivalent of killing from the task manager?
I often get left with a rogue Outlook.exe running that I want to kill off when there is no visible Oultlook window.
Oleg
Site Admin
Posts: 3014
Joined: Thu Jan 01, 1970 1:00 am
Contact:

Killing Processes

Post by Oleg »

I think that killing of processes is not a good idea, because it is an emergency way of shutdown of application. If you kill OUTLOOK.EXE, you can break your information.

Most application can be closed via closing the main window of the application. Try to close the window with caption "MIcrosoft Outlook". There is "Window Command" action for this purpose. This action can process hidden and child windows.
markan
Posts: 6
Joined: Wed Apr 06, 2005 11:29 am

Killing Processes

Post by markan »

Oleg
I theory I agree with you, but I am having to do it by hand anyway.
Outlook has developed a nasty habit of leaving an icon running in the notification area and a process running despite having had the last visible window closed. I have tried using Robotask to close the hidden windows (and there are several) but Outlook goes on!
I can understand you not wanting to add it to the application in a direct way because of the risk aspect, but could a bit of script do it?
Last edited by markan on Wed Feb 01, 2006 7:27 am, edited 1 time in total.
Oleg
Site Admin
Posts: 3014
Joined: Thu Jan 01, 1970 1:00 am
Contact:

Killing Processes

Post by Oleg »

I wrote a BASIC script for killing process. See example below. This task kills all processes of Notepad.
I reiterate again that it is a potentially dangerous operation.

Probably we'll add this action in future.

;**********************
;* RoboTask Task file *
;* Do not edit!       *
;**********************

[Root]
ActionAfterRun=INTEGER|0
Actions=FOLDER
Automat=INTEGER|-1
CatID=INTEGER|0
ContinueOnError=INTEGER|0
ExternalName=STRING|"Task376"
Hide=INTEGER|0
ID=INTEGER|18484598
Name=STRING|"Kill process (notepad)"
Priority=INTEGER|3
RunOnClose=INTEGER|0
RunOnStartup=INTEGER|0
ToLog=INTEGER|3

[Actions]
Action1=FOLDER
Action2=FOLDER
Action3=FOLDER

[Actions\Action1]
ActionID=STRING|"A_LOOP_WINDOW"
Enabled=INTEGER|-1
Name=STRING|"Window Loop"
Params=FOLDER

[Actions\Action1\Params]
caption=STRING|"0"
captionexact=STRING|"0"
captionfilter=STRING|"1"
captionvalue=STRING|"notepad"
class=STRING|"0"
classexact=STRING|"0"
classfilter=STRING|"0"
handlevariable=STRING|"W_HANDLE"
showchild=STRING|"0"
showhidden=STRING|"0"

[Actions\Action2]
ActionID=STRING|"BASIC_SCRIPT"
Enabled=INTEGER|-1
Name=STRING|"Basic Script"
Params=FOLDER

[Actions\Action2\Params]
line00000=STRING|"Private Declare Function OpenProcess Lib ""kernel32"" (ByVal _"
line00001=STRING|" dwDesiredAccess As Long, ByVal bInheritHandle As Long, _"
line00002=STRING|" ByVal dwProcessId As Long) As Long"
line00004=STRING|"Private Declare Function TerminateProcess Lib ""kernel32"" _"
line00005=STRING|" (ByVal hProcess As Long, ByVal uExitCode As Long) As Long"
line00007=STRING|"Private Declare Function CloseHandle Lib ""kernel32"" _"
line00008=STRING|" (ByVal hObject As Long) As Long"
line00010=STRING|"Private Declare Function GetWindowThreadProcessId Lib ""user32"" _"
line00011=STRING|" Alias ""GetWindowThreadProcessId"" (ByVal hwnd As Long, lpdwProcessId As Long) As Long"
line00013=STRING|"Private Const PROCESS_TERMINATE As Long = &H1"
line00015=STRING|"Sub Main"
line00016=STRING|" Dim ProcHandle As Long"
line00017=STRING|" Dim thr As Long"
line00018=STRING|" Dim pid As Long"
line00019=STRING|" Dim win As Long"
line00021=STRING|" win = Val(RoboTaskApp.ExpandText(""{w_handle}""))"
line00022=STRING|" thr = GetWindowThreadProcessId(win,pid)"
line00023=STRING|" ProcHandle = OpenProcess(PROCESS_TERMINATE, False, pid)"
line00024=STRING|" TerminateProcess(ProcHandle, 0)"
line00025=STRING|" CloseHandle ProcHandle"
line00026=STRING|"End Sub"
linecount=STRING|"27"
source=STRING|"0"

[Actions\Action3]
ActionID=STRING|"A_LOOP_END"
Enabled=INTEGER|-1
Name=STRING|"End Loop"
waghlis
Posts: 1
Joined: Thu Jun 08, 2006 7:20 am
Location: Canada

Killing Processes

Post by waghlis »

Hi, im an engineer doing an evaluation of your application. I would like to know how could I test this script with robotask. I also would like to know if its possible to kill a process by the windows pid of a process.
Imagine this situation:
-I want to run an excel program with vba code on it in an automated task each morning.( I know I can create the task and add the sheduling trigger event ).
-The program can crash or just finish.
- I want to be able to kill the process after a certain time or if the program crashes or have a popup. For example, if I known that the vba program takes 2 minutes for running, I want to be able to kill this specific application after this time. I can't find how to do this. Is there a way by using directly robotask pre-defined action or with any script ?
 
Thanks for your time.
Oleg
Site Admin
Posts: 3014
Joined: Thu Jan 01, 1970 1:00 am
Contact:

Killing Processes

Post by Oleg »

We haven't included "Kill process" action into RoboTask, because it is a potentially dangerous action. We shall add this feature in next release.
Now you can close desired application when you close main window of the application.
Also you can use the Basic script from the task in my previous post in this topic.
clue
Posts: 1
Joined: Thu Jul 06, 2006 10:19 am
Location: American Samoa
Contact:

Killing Processes

Post by clue »

Im and user of a software of MCI Desarrollos, and always I have the same problem!!!Bye!clue
allst1
Posts: 2
Joined: Sat Nov 04, 2006 7:11 pm

Killing Processes

Post by allst1 »

you can kill a process using the following method:Robotask option run:Program:cmd parameters:taskkill /IM example.exeProblem with this method is the command prompt window stays open even if it is run in hidden mode.Another method is to download pskill from sysinternals:Paste it into windows directory.Create a new taskRobotask option run:
Program: C:\WINDOWS\pskill.exe
parameters: example.exepskill will automatically close at the end of the task as well. :)It's useful when you want to exit an application that is in the system tray!
Oleg
Site Admin
Posts: 3014
Joined: Thu Jan 01, 1970 1:00 am
Contact:

Killing Processes

Post by Oleg »

Great!
Also, we have added the "Terminate process" in new release. (coming soon)
Post Reply