如何杀死在文件夹下运行的所有进程?

问题描述 投票:0回答:2

我想替换文件夹中的某些文件,并且我发现该文件夹下有多个过程阻止我这样做。

如何杀死在文件夹下运行的所有进程?

powershell cmd process kill
2个回答
1
投票

如果您更喜欢使用(因为是您的标签之一),请使用wmic process

@echo off
set "dir=YOUR PATH HERE"

for /f "skip=1 tokens=*" %%a in ('wmic process get executablepath') do (
    for /f "eol= tokens=*" %%A in ("%%a") do (
        echo(%%~dpA | findstr /I %dir% >nul 2>&1
        if %ERRORLEVEL% equ 0 taskkill /F /IM "%%~nxA"
    )
)

注意:这是NOT万无一失,所有同名进程将被杀死


0
投票

使用powershell:

  1. 通过以下方法将当前Powershell目录导航到目标路径:

cd "%*DestinationPath*%"

  1. Get-Process | ?{$_.path -and (test-path (split-path $_.path -leaf ))} | Stop-Process -Force
© www.soinside.com 2019 - 2024. All rights reserved.