Solved

Killing SYSTEM Processes Using VB Sciprt And PID's

Posted on 2007-11-14
9
1,137 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
Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

 
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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

803 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