Click here to Skip to main content
15,889,281 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hi guys
i have this code :
This is a batch file code
PHP
@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

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
Posted
Updated 6-Sep-17 20:52pm
v5
Comments
Richard MacCutchan 7-Sep-17 2:36am    
Add some echo commands to see exactly what is happening when you run it.

 
Share this answer
 
Must it be a batch file? Powershell[^] does this very easily... How to close all windows with PowerShell - Stack Overflow[^]
 
Share this answer
 
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?
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900