使用CMD关闭除此之外的所有程序 [英] Close all program except these with CMD

查看:388
本文介绍了使用CMD关闭除此之外的所有程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨伙计

i有这段代码:

这是一个批处理文件代码

hi guys
i have this code :
This is a batch file code

@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尝试编辑它并添加这样的东西



如果不是%% i==notepad.exe(



但它无论如何都没有工作,当我点击批处理文件时它什么也没有,所以我不知道怎么编辑这个并放一些除了它!感谢提前


but it will close all of the program

What I have tried:

i try to edit it and add something like this

if not "%%i"=="notepad.exe" (

but its not working anyway and when i click on batch file its nothing so i don't know how to edit this and put some except on it! thanks in advance

推荐答案

必须是批处理文件吗? Powershell [ ^ ]这很容易... 如何使用PowerShell关闭所有窗口 - 堆栈溢出 [ ^ ]
Must it be a batch file? Powershell[^] does this very easily... How to close all windows with PowerShell - Stack Overflow[^]


如果我改变了这个:

If I change this:
echo.
taskkill /f /im "%%i" 
echo.

对此:

To this:

echo "%%i" 



然后我明白了:


Then I get this:

D:\Test Data>listtask
"sihost.exe"
"taskhostw.exe"
"Pen_TabletUser.exe"
"Pen_TouchUser.exe"
"avpui.exe"
"ShellExperienceHost.exe"
"SearchUI.exe"
"RuntimeBroker.exe"
"TabTip.exe"
"SettingSyncHost.exe"
"nvtray.exe"
"NvBackend.exe"
"MSASCuiL.exe"
"RAVCpl64.exe"
"CorelCreatorClient.exe"
"SetPoint.exe"
"KHALMNPR.exe"
"OneDrive.exe"
"chrome.exe"
"chrome.exe"
"chrome.exe"
"chrome.exe"
"E_IATIGJE.EXE"
"ProductUpdater.exe"
"WzPreloader.exe"
"LWS.exe"
"GalaxyClient.exe"
"GalaxyClient"
"GOG"
"jucheck.exe"
"CodeprojectReputation.exe"
"wlmail.exe"
"wlcomm.exe"
"PSPad.exe"
"conhost.exe"
Press any key to continue . . .

D:\Test Data>

这表明批处理文件工作得很好,除非是你终止任务的情况 - 出于显而易见的原因,我不打算在我的电脑上试试吧!

通过添加

Which would indicate that the batch file works just fine, except in your case for terminating tasks - for obvious reasons I'm not going to try that on my computer!
Trying the command itself by adding

)
taskkill /f /im "pspad.exe"
pause

最后,我们非常高兴地完成任务。



所以我怀疑这是一个权限问题。

尝试我做的同样的事情,并回应所有正在运行的任务。然后手动杀死第一个。看看它是否有效。但是......我的列表中有很多任务可能会让我的计算机在被杀的时候变得有点不稳定 - 而你的计算机很可能也是如此。

你为什么要这样做?

To the end kills the task perfectly happily.

So I'd suspect that it's a permissions problem.
Try the same thing I did, and echo all the running tasks. Then manually kill the first one. See if it works. But ... there are a lot of tasks in my list that would probably make my computer a little unstable if killed - and yours is likely the same.
Why are you trying to do this?


检查此答案

批处理文件 - 关闭除CMD之外的所有程序 - 堆栈溢出 [ ^ ]


这篇关于使用CMD关闭除此之外的所有程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆