Solved

Killing SYSTEM Processes Using VB Sciprt And PID's

Posted on 2007-11-14
9
1,128 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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

757 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now