Current location: Hot Scripts Forums » Programming Languages » Visual Basic » Terminate/Kill More Then 1 Process...?


Terminate/Kill More Then 1 Process...?

Reply
  #1 (permalink)  
Old 01-27-07, 01:14 PM
luckyricky_1 luckyricky_1 is offline
New Member
 
Join Date: Jan 2007
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Terminate/Kill More Then 1 Process...?

Hi all, first post, just registered.

Sort of need some help, i have found the script below, all well, its a good script, got it working no problem, what if i want to make the script kill 2 processes?

The script is:
Code:
Option Explicit
Dim objWMIService, objProcess, colProcess
Dim strComputer, strProcessKill
strComputer = "."
strProcessKill = "'calc.exe'"

Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" _
& strComputer & "\root\cimv2")

Set colProcess = objWMIService.ExecQuery _
("Select * from Win32_Process Where Name = " & strProcessKill )
For Each objProcess in colProcess
objProcess.Terminate()
Next
WScript.Quit
Many Many Many thanks in advance!

Last edited by Nico; 01-29-07 at 09:36 AM. Reason: Please use [code] wrappers when posting code.
Reply With Quote
  #2 (permalink)  
Old 01-28-07, 07:06 AM
King Coder King Coder is offline
Community VIP
 
Join Date: Jan 2006
Posts: 703
Thanks: 0
Thanked 0 Times in 0 Posts
Throw that code into a function and call it twice with two different process names:

strProcessKill = "'calc.exe'"
__________________
my site
Reply With Quote
  #3 (permalink)  
Old 01-28-07, 12:08 PM
luckyricky_1 luckyricky_1 is offline
New Member
 
Join Date: Jan 2007
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Hi King Code, thank you for your reply.

I am not a coder, i picked this code up when i was looking through google and found it really interesting.

Is it possible for you to insert the function? I have looked through google but seems to be more then 1 function, i tried to put one it but it didn't work :|

Many thanks again for your reply,

Richard
Reply With Quote
  #4 (permalink)  
Old 01-29-07, 09:23 AM
m.timoney's Avatar
m.timoney m.timoney is offline
Newbie Coder
 
Join Date: Jan 2007
Location: Leicester - UK
Posts: 76
Thanks: 1
Thanked 0 Times in 0 Posts
coder probably means this
Code:
private sub KillProcess(strProcessKill  as string)
Dim objWMIService, objProcess, colProcess
Dim strComputer, strProcessKill
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" _
& strComputer & "\root\cimv2")

Set colProcess = objWMIService.ExecQuery _
("Select * from Win32_Process Where Name = " & strProcessKill )
For Each objProcess in colProcess
objProcess.Terminate()
Next
end sub
then you call
KillProcess("calc.exe")
KillProcess("winword.exe")
WScript.Quit
and you've killed 2 processes

warning the above code in untested and written on the fly and is used to convey the idea of how to do it not the code that will do it
__________________
Definition of a Beginner, Someone who doesn't know the rules.

Definition of an Expert, Someone who knows when to ignore the rules.

Last edited by Nico; 01-29-07 at 09:36 AM. Reason: Please use [code] wrappers when posting code.
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Perl/CGI Script to background process weilies Perl 3 07-18-06 08:19 PM
Hide Process aljovan Visual Basic 4 08-11-05 12:33 AM
hide process mike_wilson Visual Basic 3 03-20-05 01:03 PM
Process Control Data on the Web stardog589 ASP.NET 0 01-20-05 02:45 PM


All times are GMT -5. The time now is 01:17 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.