2

How do I kill all program.exe instances that are currently open through a Windows network share?

I know how to list the open files net files | Findstr "program.exe" but how then how do I kill it?

In Linux I would type:

kill -9 `pidof program.exe`

What is the equivalent of this in Windows?

Richard Keller
  • 2,270
  • 2
  • 18
  • 31
Widmo
  • 21
  • 1
  • 2

3 Answers3

2

If your windows version has powershell (if not, you can download and install from microsoft site), it is very easy as well

get-process "program.exe" | stop-process -force -confirm:$false
Mark Henderson
  • 68,316
  • 31
  • 175
  • 255
johnshen64
  • 5,747
  • 23
  • 17
  • You writing about system processes, but i'm looking for open network files ( look at: net files ) :) – Widmo May 21 '12 at 21:22
  • oh sorry i thought you were asking for processes. net file filenum /close is what you are looking for then? where filenum is what you find in the net files listing. – johnshen64 May 21 '12 at 21:31
  • True, net file /close is what i am looking for, i wrote it in 1st post ;) But i don't know how to connect it with findstring and kill PID's only from program: sample.exe ;) So: I need to do one command and kill all PID's from files example.exe :) – Widmo May 21 '12 at 21:44
  • i don't think there is a such a command, but there might be batch files or powershells scripts available, or you can write one. if you have powershell, i can likely whip up one for you quickly if you cannot write one quickly and cannot find one written by someone else, but not batch file, as i am really rusty in batch files by now :-) – johnshen64 May 21 '12 at 21:50
1

Look here: http://support.microsoft.com/kb/290585/en-us

I believe this still applies to current Windows versions, or should at least put you in the right direction.

Command line:

for /f "skip=4 tokens=1" %a in ('net files') do net files %a /close

Batch file:

for /f "skip=4 tokens=1" %%a in ('net files') do net files %%a /close
MichelZ
  • 11,008
  • 4
  • 30
  • 58
0

tskill.exe (either built-in or possibly in a resource kit) or pskill.exe, from sysinternals - which as a Windows admin, you should have on a USB key and on a network share.

Also, don't forget to include which version of Windows you're working on - that may make a difference with someone's answer - although likely not for this question.

mfinni
  • 35,711
  • 3
  • 50
  • 86