Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Killing SYSTEM Processes Using VB Sciprt And PID's

Posted on 2007-11-14
9
Medium Priority
?
1,169 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 452 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 448 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
With User Account Control (UAC) enabled in Windows 7, one needs to open an elevated Command Prompt in order to run scripts under administrative privileges. Although the elevated Command Prompt accomplishes the task, the question How to run as script…
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…
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…
Suggested Courses

610 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