Solved

Code to Kill a windows process

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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
base64 decode encode 12 133
Internet Connection Util 8 92
Licensing Sharepoint 2016 for developers 11 45
Zip Folders Using Chilkat Routines 1 37
Introduction: Recently, I got a requirement to zip all files individually with batch file script in Windows OS. I don't know much about scripting, but I searched Google and found a lot of examples and websites to complete my task. Finally, I was ab…
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…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

785 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