使用CMD关闭除这些之外的所有程序

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

我有这个代码: 这是批处理文件代码

@echo off
title Kill all running apps - Bharat Balegere - AgniPulse.com
cd c:\windows\System32
for /f "skip=3 tokens=1" %%i in ('TASKLIST /FI "USERNAME eq %userdomain%\%username%" /FI "STATUS eq running"') do (
if not "%%i"=="svchost.exe" (
if not "%%i"=="explorer.exe" (
if not "%%i"=="cmd.exe" (
if not "%%i"=="tasklist.exe" (
echo.
taskkill /f /im "%%i" 
echo.
)
)
)
)
)
pause

但它会关闭所有程序

我尝试编辑它并添加类似的内容

如果不是“%%i”==“notepad.exe”(
但它无论如何都不起作用,当我单击批处理文件时,它什么也没有 所以我不知道如何编辑这个 并在上面放一些除此之外的东西! 预先感谢

batch-file cmd
2个回答
0
投票

您可以尝试一下这个带有白名单的批处理文件来杀死进程

当然,您可以根据需要修改白名单变量:

@echo off
Title Kill all running apps - Bharat Balegere - AgniPulse.com
set "whitelist=avast mbam dllhost conhost" 
Set "whitelist=%whitelist% taskeng skype"
Set "whitelist=%whitelist% firefox explorer cmd"
Set "whitelist=%whitelist% chrome tasklist taskmgr notepad"

@For /f "skip=3 tokens=1" %%i in (
'TASKLIST /FI "USERNAME eq %userdomain%\%username%" /FI "STATUS eq running" ^| findstr /VI "%whitelist%"'
) Do ( 
    echo Taskkill /IM "%%i" /F
)
pause & exit

如果您希望删除此列表,您当然可以删除

echo
命令!


编辑: 这是使用

WMIC

的另一批白名单
@echo off
Title Process killer with a white list
Mode con cols=50 lines=40 & color 9B
setlocal
Set "White_Process_List=%~dpn0_White_Process_List.txt"
set "Ignoring_Process_List=%~dpn0_Ignoring_Process_List.txt"
set "Terimnated_Process_List=%~dpn0_Terimnated_List.txt"
If exist "%Ignoring_Process_List%" Del "%Ignoring_Process_List%"
If exist "%Terimnated_Process_List%" Del "%Terimnated_Process_List%"

:Whitelist
set "whitelist=Microsoft Mozilla Google Avast Panda ESET Kaspersky Avira AVG Bitdefender Malwarebytes Norton McAfee GAS IBM Skype"
If not exist "%White_Process_List%" echo %whitelist% > "%White_Process_List%" 
Set /p whitelist=<"%White_Process_List%"

:Analyze
for /f "tokens=2 delims=," %%I in (
    'wmic process get executablepath^,status /format:csv ^| find "\"'
) do (
    set "proc=%%~I"
    setlocal enabledelayedexpansion
    wmic datafile where "name='!proc:\=\\!'" get manufacturer 2>nul | findstr /i "%whitelist%" >nul && (
        ( echo Ignoring : %%~nxI & echo "%%~I" 
         echo --------------------------------------- )>>!Ignoring_Process_List! 2>&1
    ) || (
        ( echo Terminating: %%~nxI )>con
        ( echo Terminating : %%~nxI & echo "%%~I" 
        Taskkill /im "%%~nxI" /f /t 
        echo --------------------------------------- )>>!Terimnated_Process_List! 2>&1
    )
    endlocal 
)
Timeout /T 2 /nobreak>nul

0
投票

这是我使用的批处理文件。我想把它变成一个 powershell。 我每天远程访问客户计算机时都会使用它。您可以远程未使用的程序。

:start
echo.&echo.&echo Closing Programs and cleaning files
cd c:\windows\System32
for /f "skip=3 tokens=1" %%i in ('TASKLIST /FI "USERNAME eq 
%userdomain%\%username%" /FI "STATUS eq running"') do (
echo %%i
if not "%%i"=="svchost.exe" (
if not "%%i"=="explorer.exe" (
if not "%%i"=="sfc.exe" (
if not "%%i"=="tasklist.exe" (
if not "%%i"=="notepad.exe" (
if not "%%i"=="dllhost.exe" (
if not "%%i"=="cis.exe" (
if not "%%i"=="cistray.exe" (
if not "%%i"=="cmd.exe" (
if not "%%i"=="taskmgr.exe" (
if not "%%i"=="conhost.exe" (
if not "%%i"=="dwm.exe" (
if not "%%i"=="tv_w32.exe" (
if not "%%i"=="tv_x64.exe" (
if not "%%i"=="TeamViewer.exe" (
if not "%%i"=="Taskmgr.exe" (
if not "%%i"=="chkdsk.exe" (
if not "%%i"=="avast*.exe" (
if not "%%i"=="AvastUI.exe" (
if not "%%i"=="mbam.exe" (
if not "%%i"=="mbamtray.exe" (
if not "%%i"=="secopy.exe" (
if not "%%i"=="mbamtray.exe" (
if not "%%i"=="cmd.exe" (
if not "%%i"=="ninite.exe" (
if not "%%i"=="setupprep" (
if not "%%i"=="RCClient.exe" (
echo.&echo %%i
rem timeout /t 1
taskkill /f /im "%%i"
rem timeout /t 1
echo.
))))))))))))))))))))))))))))
echo All Programs we could close are closed.
echo.Run Task manager and see if there is anything open
Echo Here will open it for you.
start taskmgr.exe
pause
© www.soinside.com 2019 - 2024. All rights reserved.