forum.vdsworld.com Forum Index forum.vdsworld.com
Visit VDSWORLD.com
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


Kill Tasks

 
Post new topic   Reply to topic    forum.vdsworld.com Forum Index -> Visual DialogScript 5 Units
View previous topic :: View next topic  
Author Message
Hortalonus
Valued Contributor
Valued Contributor


Joined: 15 Mar 2002
Posts: 344
Location: Western USA

PostPosted: Fri Jul 18, 2003 3:09 pm    Post subject: Kill Tasks Reply with quote

I have uploaded the source of a DSU to kill all running instances of a specified file (a function I have been waiting for for a long time Wink ).

Download: http://www.vdsworld.com/index.php?page=download&fileid=293

-OR-

If you prefer, here is the source to the script and a short demo.
Code:
#   Filename:    kill.dsc
#   Version:     1.7.21.1
#   Author:      Jim Bob Pipes
#   Copyright:   © 2003 Jim Bob Pipes
#   Purpose:     To kill all running tasks matching specified file path
#   
#   Functions:   kill
#   Commands:   
#   Includes:   
#   Lists:       6, 7
#   Variables:   %i, %%ProcName, %%ProcID, %%returncode

#DEFINE FUNCTION,KILL

:KILL
# create a list of all running tasks including filenames and process ID's
LIST CREATE,6
LIST CREATE,7
LIST TASKLIST,6,NI
%i = 0
%%returncode = 0
WHILE @GREATER(@COUNT(6),%i)
  LIST SEEK,6,%i
  PARSE "%%ProcName;%%ProcID",@ITEM(6)
  # if the process name matches the file name and extension passed to the function, check
  # the full file path of the process
  IF @EQUAL(%%ProcName,@NAME(%1).@EXT(%1))
    LIST MODULES,7,%%ProcID
    # if the full file path of the process matches the full file path passed to the function, kill it
    IF @EQUAL(@ITEM(7,0),%1)
      KILLTASK %%ProcID
      # increment the valuse of %%returncode each time a running task is killed
      %%returncode = @SUCC(%%returncode)
    END
    LIST CLEAR,7
  END
  %i = @SUCC(%i)
WEND
# close the list and clear variables before leaving the function
LIST CLOSE,6
LIST CLOSE,7
%i =
%%ProcName =
%%ProcID =
EXIT %%returncode


Code:
#   Filename:    demo.dsc
#   Version:     1.7.21.1
#   Author:      Jim Bob Pipes
#   Copyright:   © 2003 Jim Bob Pipes

#INCLUDE kill.dsc

# specify the full file path of the processes you want to kill
%%filename = "your_full_file_path_here"
# number returned will be the number of processes killed
INFO @kill(%%filename)" instances of "%%filename" were killed."
EXIT


EDIT: 07-21-2003 - added routine to check the path of the process. Thanks Dr. Dread and FF for the help! Very Happy

_________________
"ah, come take my hand... we're ridin' out tonight to face the promised land"
Get a free iPod mp3 player...


Last edited by Hortalonus on Mon Jul 21, 2003 6:08 pm; edited 1 time in total
Back to top
View user's profile Send private message Send e-mail
Dr. Dread
Professional Member
Professional Member


Joined: 03 Aug 2001
Posts: 1065
Location: Copenhagen, Denmark

PostPosted: Fri Jul 18, 2003 6:18 pm    Post subject: Reply with quote

Nice. Just a thought: Processes with identical names may originate from different executables, so it
might be a good idea to check whether processes with the to-be-killed name originate from the same
file path. Sometimes you'll only want to kill one of them..

I tell you this coz I had an experience killing off a process that accidentally had the same process
name as the one I really wanted to finish Wink

Greetz
Dread

BTW: I don't think VDS itself can tell ya the process path, you'll probably need an API call for that.

_________________
~~ Alcohol and calculus don't mix... Don't drink and derive! ~~

String.DLL * advanced string processing
Back to top
View user's profile Send private message
Hortalonus
Valued Contributor
Valued Contributor


Joined: 15 Mar 2002
Posts: 344
Location: Western USA

PostPosted: Fri Jul 18, 2003 6:25 pm    Post subject: Reply with quote

Hey Dread!

I hear ya... I've made the same mistake before. This DSU was really just meant to be a simple "kill 'em all because you know you're killing the right process" kind of script. That would be a nice addition though. I don't have much win32 API knowledge but if anybody would like to update this DSU to include Dread's idea, please feel free to.

_________________
"ah, come take my hand... we're ridin' out tonight to face the promised land"
Get a free iPod mp3 player...
Back to top
View user's profile Send private message Send e-mail
FreezingFire
Admin Team


Joined: 23 Jun 2002
Posts: 3508

PostPosted: Sat Jul 19, 2003 12:04 am    Post subject: Reply with quote

You don't need an API to get the process path. Wink

Try this code:

Code:
list create,1
list modules,1,explorer.exe
info @item(1,0)
list close,1
exit

_________________
FreezingFire
VDSWORLD.com
Site Admin Team
Back to top
View user's profile Send private message Visit poster's website
Dr. Dread
Professional Member
Professional Member


Joined: 03 Aug 2001
Posts: 1065
Location: Copenhagen, Denmark

PostPosted: Sat Jul 19, 2003 3:34 am    Post subject: Reply with quote

Aaaaa, great! That one had escaped my attention. I'll keep it in mind for next time.

Greetz
Dread

_________________
~~ Alcohol and calculus don't mix... Don't drink and derive! ~~

String.DLL * advanced string processing
Back to top
View user's profile Send private message
Hortalonus
Valued Contributor
Valued Contributor


Joined: 15 Mar 2002
Posts: 344
Location: Western USA

PostPosted: Mon Jul 21, 2003 1:20 pm    Post subject: Reply with quote

FreezingFire wrote:
You don't need an API to get the process path. Wink

Try this code:

Code:
list create,1
list modules,1,explorer.exe
info @item(1,0)
list close,1
exit

Ah, yes! I forgot about that command FF... thank you! Very Happy

_________________
"ah, come take my hand... we're ridin' out tonight to face the promised land"
Get a free iPod mp3 player...
Back to top
View user's profile Send private message Send e-mail
FreezingFire
Admin Team


Joined: 23 Jun 2002
Posts: 3508

PostPosted: Mon Jul 21, 2003 4:46 pm    Post subject: Reply with quote

No problem. Glad to help. Very Happy
_________________
FreezingFire
VDSWORLD.com
Site Admin Team
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    forum.vdsworld.com Forum Index -> Visual DialogScript 5 Units All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum

Twitter@vdsworld       RSS

Powered by phpBB © 2001, 2005 phpBB Group