Solved

Code to Kill a windows process

Posted on 2010-11-08
3
603 Views
Last Modified: 2013-12-03
I'm looking for code that I can just put into a simple .bat file that will kill a process.  I want to schedule it to run with windows scheduler.  Is there some command string I can put in there to kill ag.exe process?
0
Comment
Question by:N R
3 Comments
 
LVL 24

Accepted Solution

by:
fridom earned 250 total points
ID: 34085483
http://technet.microsoft.com/en-us/sysinternals/bb896683.aspx

If in doubt visit Sysinternal sites. You find many very usefull tools there.

Regards
Friedrich
0
 
LVL 15

Assisted Solution

by:JBond2010
JBond2010 earned 250 total points
ID: 34085486
Using VBScript

strComputer = "."
strOwner = "A111111"
strProcess = "'notepad.exe'"
 
' Connect to WMI service and Win32_Process filtering by name'
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" _
    & strComputer & "\root\cimv2")
Set colProcessbyName = objWMIService.ExecQuery("Select * from Win32_Process Where Name = " _
    & strProcess)
 
' Get the process ID for the process started by the user in question'
For Each objProcess in colProcessbyName
    colProperties = objProcess.GetOwner(strUsername,strUserDomain)
    if strUsername = strOwner then
        strProcessID = objProcess.ProcessId
    end if
next
 
' We have the process ID for the app in question for the user, now we kill it'
Set colProcessList = objWMIService.ExecQuery("Select * from Win32_Process where ProcessId =" & strProcessID)
For Each objProcess in colProcess
    objProcess.Terminate()
Next
0
 
LVL 11

Author Comment

by:N R
ID: 34085541
Thanks, actually ended up doing it like this:

taskkill /F /IM AG.exe
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Being a system administrator some time we require to do things remotely, one of them is installing software. Here I am going to tell you how to install software through wmic (Windows management instrument console). I am not at all saying that this i…
How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

948 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

23 Experts available now in Live!

Get 1:1 Help Now