Solved

Code to Kill a windows process

Posted on 2010-11-08
3
600 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

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

There is an easy way, in .NET, to centralize the treatment of all unexpected errors. First of all, instead of launching the application directly in a Form, you need first to write a Sub called Main, in a module. Then, set the Startup Object to th…
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 …
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.

747 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

11 Experts available now in Live!

Get 1:1 Help Now