Skip to content

Instantly share code, notes, and snippets.

@rafalkasa
Last active January 24, 2017 15:08
Show Gist options
  • Save rafalkasa/d29b372212e5cbdc0a1b979ffdf9b5ce to your computer and use it in GitHub Desktop.
Save rafalkasa/d29b372212e5cbdc0a1b979ffdf9b5ce to your computer and use it in GitHub Desktop.
Kill Running Processes from a specific folder via Batch File
@echo off
if "%1"=="" goto help
:: Put the work dir here
set "workdir=%1
set "workdir=%workdir:\=\\%"
setlocal enableDelayedExpansion
for /f "usebackq tokens=* delims=" %%a in (`
wmic process where 'CommandLine like "%%!workdir!%%" and not CommandLine like "%%RuntimeBroker%%"' get CommandLine^,ProcessId /format:value
`) do (
for /f "tokens=* delims=" %%# in ("%%a") do (
if "%%#" neq "" (
set "%%#"
SET var="%%#"
SET searchVal=ProcessId
SET var|FINDSTR /b "var="|FINDSTR /i %searchVal% >nul
IF ERRORLEVEL 1 (echo.) ELSE (taskkill /pid !ProcessId! /f)
)
)
)
goto end
:help
echo ********************
echo * Example of Usage *
echo ********************
echo.
echo =============================================
echo closeapp \\server\path\test
echo.
:end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment