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
Solved

Code to Kill a windows process

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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
groupNoAdj 7 105
WPF issue with Trigger 2 113
Problem to open text file 11 128
how to export this list 4 59
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
When we want to run, execute or repeat a statement multiple times, a loop is necessary. This article covers the two types of loops in Python: the while loop and the for loop.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…

809 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