Solved

Killing SYSTEM Processes Using VB Sciprt And PID's

Posted on 2007-11-14
9
1,149 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

730 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