Solved

Killing SYSTEM Processes Using VB Sciprt And PID's

Posted on 2007-11-14
9
1,143 Views
Last Modified: 2012-05-05
Hello

im have asked a question like this before on EE and finally made my VB Scipt work, but since then i have installed new programs which at certain times i want to end their related processes

The VB script i have been using goes somewhat like below
----------------------------------------------------------------------------------------------------------------------------
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colProcessList = objWMIService.ExecQuery _
    ("Select * from Win32_Process Where Name = 'atwtusb.exe'")
For Each objProcess in colProcessList
    objProcess.Terminate()
Next
Set colProcessList = objWMIService.ExecQuery _
    ("Select * from Win32_Process Where Name = 'LVPrcSrv.exe'")
For Each objProcess in colProcessList
    objProcess.Terminate()
Next
----------------------------------------------------------------------------------------------------------------------------

I am wondering how can i change this VB scipt to end processes by their PID's, (as i feel i can tidy up my code using PID's over pathnames or names) for example i have one process running called ati2evxx.exe of which i cant end using the tips posted here

"http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_22662388.html"

but i have it's PID in this case being 1160, i have tried looking on the web for any viable information on adapting something like above to end process via PID but to no avail,

any help would be great
0
Comment
Question by:martman2002uk
  • 2
  • 2
  • 2
  • +1
9 Comments
 
LVL 2

Accepted Solution

by:
cshanea0 earned 113 total points
ID: 20285904
strComputer = "."
Set objWMIService = GetObject _
    ("winmgmts:\\" & strComputer & "\root\cimv2")
Set colProcessList = objWMIService.ExecQuery _
    ("Select * from Win32_Process Where ProcessID = 2576")
For Each objProcess in colProcessList
    objProcess.Terminate()
Next
0
 
LVL 26

Assisted Solution

by:EDDYKT
EDDYKT earned 112 total points
ID: 20288524
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colProcessList = objWMIService.ExecQuery _
    ("Select * from Win32_Process")
For Each objProcess In colProcessList
    If objProcess.ProcessID = 1160 Then objProcess.Terminate()
Next
0
 

Author Comment

by:martman2002uk
ID: 20290387
Thanks for the quick replies, both solutions work fine,

I have another question, how can i change either of the above solutions to end services based on their PIDs given to them in windows task manager. for example i have a service running with the PID 544, the above solutions dont end this specific PID.

thanks again
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 2

Expert Comment

by:cshanea0
ID: 20290692
question, what is your goal here?  are you trying to use PID's in a script you want to automate? or is this a manual script you will be running?  is the server local or remote?  the reason i'm asking is because the PID's are gona change each time you start the program.  if you reboot the server/computer, your PID's will probably all change.  if this is a static script that will be automated (task scheduler...) i don't think you will want to use PID's as you will have to update the script each time you run it.  also what are you trying to kill?  some programs have monitoring processes that watch them in case they shutdown for some reason and the monitoring process will restart them.  windows also won't let you shutdown some core windows processes.  tell us a little more about what your goal is.

thanks,
Shane
0
 
LVL 26

Expert Comment

by:EDDYKT
ID: 20291653
can you kill the task from task manager?
if not,  then it is permission
0
 

Author Comment

by:martman2002uk
ID: 20292503
@ cshanea0
First off i should say this is for my own computer, this is only for that use, because at times i want to end all unnecessary processes on my computer to free up ram and whatnot, for example when my computer first boots up i have about 15 processes which i dont need to have running while i surf, game, etc... normaly i run my computer with only the necessary processes, explorer.exe, mcshield.exe, etc...

I writing this code so when my computer boots up and i fancy gaming i just double click the vbs file and hey presto i'm running only the necessary processes.

I'm using PID's as some of the processes wont end using their filename, not sure why. such as in the case of my first comment here, ati2evxx.exe, wouldnt end using filename but would using its PID

@ EDDYKT
yes, i can end it from task manager, although cant seem to get them to end using VBscript
0
 
LVL 19

Expert Comment

by:weellio
ID: 20979865
taskkill /pid <pid>
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Over the years I have built up my own little library of code snippets that I refer to when programming or writing a script.  Many of these have come from the web or adaptations from snippets I find on the Web.  Periodically I add to them when I come…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question