kill all processes with taskkill by username but exclude some processes
I want to kill all processes with taskkill by username, with this command:
taskkill /f /fi "USERNAME eq %username%"
The problem is that I want to exclude (skip) some processes (not kill them all), such as explorer.exe, taskmgr.exe, cmd.exe, and of course current CMD instance
How can i exclude this processes with taskkill?
thanks
windows batch cmd.exe
add a comment |
I want to kill all processes with taskkill by username, with this command:
taskkill /f /fi "USERNAME eq %username%"
The problem is that I want to exclude (skip) some processes (not kill them all), such as explorer.exe, taskmgr.exe, cmd.exe, and of course current CMD instance
How can i exclude this processes with taskkill?
thanks
windows batch cmd.exe
Hi there. We're not a scriptwriting service, so since you've specified that you're trying to solve this with a Batch script, please include what you've attempted already, what the results were, and what's tripping you up exactly. If this doesn't NEED to be in batch and/or usingtaskkill, please edit your question to remove the Batch tag, so you'll increase you chances of getting answers (that may or may not be Batch based). :)
– Ƭᴇcʜιᴇ007
Sep 29 '16 at 17:07
the question is very clear and precise
– BrianC
Sep 29 '16 at 17:17
Brian - See below in my answer for a tested and confirmed working process from what I tested and could confirm it works as expected. Let me know how it goes.
– Pimp Juice IT
Sep 29 '16 at 19:27
add a comment |
I want to kill all processes with taskkill by username, with this command:
taskkill /f /fi "USERNAME eq %username%"
The problem is that I want to exclude (skip) some processes (not kill them all), such as explorer.exe, taskmgr.exe, cmd.exe, and of course current CMD instance
How can i exclude this processes with taskkill?
thanks
windows batch cmd.exe
I want to kill all processes with taskkill by username, with this command:
taskkill /f /fi "USERNAME eq %username%"
The problem is that I want to exclude (skip) some processes (not kill them all), such as explorer.exe, taskmgr.exe, cmd.exe, and of course current CMD instance
How can i exclude this processes with taskkill?
thanks
windows batch cmd.exe
windows batch cmd.exe
edited Oct 1 '16 at 15:16
BrianC
asked Sep 29 '16 at 16:55
BrianCBrianC
75210
75210
Hi there. We're not a scriptwriting service, so since you've specified that you're trying to solve this with a Batch script, please include what you've attempted already, what the results were, and what's tripping you up exactly. If this doesn't NEED to be in batch and/or usingtaskkill, please edit your question to remove the Batch tag, so you'll increase you chances of getting answers (that may or may not be Batch based). :)
– Ƭᴇcʜιᴇ007
Sep 29 '16 at 17:07
the question is very clear and precise
– BrianC
Sep 29 '16 at 17:17
Brian - See below in my answer for a tested and confirmed working process from what I tested and could confirm it works as expected. Let me know how it goes.
– Pimp Juice IT
Sep 29 '16 at 19:27
add a comment |
Hi there. We're not a scriptwriting service, so since you've specified that you're trying to solve this with a Batch script, please include what you've attempted already, what the results were, and what's tripping you up exactly. If this doesn't NEED to be in batch and/or usingtaskkill, please edit your question to remove the Batch tag, so you'll increase you chances of getting answers (that may or may not be Batch based). :)
– Ƭᴇcʜιᴇ007
Sep 29 '16 at 17:07
the question is very clear and precise
– BrianC
Sep 29 '16 at 17:17
Brian - See below in my answer for a tested and confirmed working process from what I tested and could confirm it works as expected. Let me know how it goes.
– Pimp Juice IT
Sep 29 '16 at 19:27
Hi there. We're not a scriptwriting service, so since you've specified that you're trying to solve this with a Batch script, please include what you've attempted already, what the results were, and what's tripping you up exactly. If this doesn't NEED to be in batch and/or using
taskkill, please edit your question to remove the Batch tag, so you'll increase you chances of getting answers (that may or may not be Batch based). :)– Ƭᴇcʜιᴇ007
Sep 29 '16 at 17:07
Hi there. We're not a scriptwriting service, so since you've specified that you're trying to solve this with a Batch script, please include what you've attempted already, what the results were, and what's tripping you up exactly. If this doesn't NEED to be in batch and/or using
taskkill, please edit your question to remove the Batch tag, so you'll increase you chances of getting answers (that may or may not be Batch based). :)– Ƭᴇcʜιᴇ007
Sep 29 '16 at 17:07
the question is very clear and precise
– BrianC
Sep 29 '16 at 17:17
the question is very clear and precise
– BrianC
Sep 29 '16 at 17:17
Brian - See below in my answer for a tested and confirmed working process from what I tested and could confirm it works as expected. Let me know how it goes.
– Pimp Juice IT
Sep 29 '16 at 19:27
Brian - See below in my answer for a tested and confirmed working process from what I tested and could confirm it works as expected. Let me know how it goes.
– Pimp Juice IT
Sep 29 '16 at 19:27
add a comment |
3 Answers
3
active
oldest
votes
Windows Native Batch Script CMD Method
Below is a batch script solution that uses Tasklist and FOR /F loops setting and parsing variables accordingly to get just the process names of the processes running of a specific user.
With Findstr these results are then parsed further to exclude any specified exclusions you set in the Exclusions variable up top.
It'll take the final remaining results and kill those process names for that specific username giving you the desired results via a batch script just as explained.
Batch Script
There are only two variables to set for this to work which are the Username and the Exclusions, and the rest will just work and do the rest of the process as you need. Just specific the full process names separated by a space one next to the other just as in the below script.
@ECHO ON
SET Username=user
SET Exclusions=explorer.exe taskmgr.exe cmd.exe
SET tmpfl=%temp%%~n0tmp.dat
IF EXIST "%tmpfl%" DEL /F /Q "%tmpfl%"
SET Exclusions=%Exclusions% taskkill.exe
SETLOCAL ENABLEDELAYEDEXPANSION
FOR /F "DELIMS=: TOKENS=2" %%A IN ('TASKLIST /FI "USERNAME EQ %Username%" /FO LIST ^| FIND /I "Image name:"') DO (
SET var=%%~A
SET var=!var: =!
ECHO !var! | FINDSTR /I /V "%Exclusions%">>"%tmpfl%"
)
FOR /F "USEBACKQ TOKENS=*" %%A IN ("%tmpfl%") DO (
TASKKILL /F /FI "USERNAME eq %Username%" /IM %%~A
)
GOTO EOF
Batch Script 2
@ECHO ON
CD /D "%~DP0"
SET Exclusions=cmd.exe explorer.exe taskmgr.exe
SET tmpfl=%~n0tmp.dat
IF EXIST "%tmpfl%" DEL /F /Q "%tmpfl%"
SET Exclusions=%Exclusions% taskkill.exe
SETLOCAL ENABLEDELAYEDEXPANSION
FOR /F "DELIMS=: TOKENS=2" %%A IN ('TASKLIST /FI "USERNAME EQ %Username%" /FO LIST ^| FIND /I "Image name:"') DO (
SET var=%%~A
SET var=!var: =!
ECHO !var! | FINDSTR /I /V "%Exclusions%">>"%tmpfl%"
)
FOR /F "USEBACKQ TOKENS=*" %%A IN ("%tmpfl%") DO (
TASKKILL /F /FI "USERNAME eq %Username%" /IM %%~A
)
DEL /F /Q "%tmpfl%"
GOTO EOF
Further Resources
- EnableDelayedExpansion
- FOR /F
- Variable Substring
- Tasklist
- Find
- Findstr
- Taskkill
Please check the script for errors. The system can not find the file C:Usersuser1 AppDataLocalTemptesttmp.dat. By the way. this variable is not viable (SET Username = user) because it must serve any account. It must be replaced by %username%
– BrianC
Sep 29 '16 at 19:35
This variable (SET Username = user) not needed. Only "USERNAME EQ %username%"
– BrianC
Sep 29 '16 at 19:50
Yes. And the change is only in user logged
– BrianC
Sep 29 '16 at 19:53
I ran the script with administrative privileges on account and the same error (win7x64)
– BrianC
Sep 29 '16 at 19:55
replace %temp% with %HOMEDRIVE%
– BrianC
Sep 29 '16 at 20:04
|
show 5 more comments
I would personally do this by using powershell.
Something like this:
$processes = Get-Process -IncludeUserName | where {$_.UserName -like "*USERNAME*"}
$tobeignored = @("explorer","Taskmgr","cmd")
foreach($process in $processes)
{
if($tobeignored.Contains($process.ProcessName))
{
continue;
}
else
{
Stop-Process $process.Id -Force
}
}
I have not been able to test run this, I kinda dont wanna kill my own processes :) Let me know if it (doesn't) work(s)
Ok tested it, and made a little change :) this does the trick. Just add the proccess names (without extention) to the array, the ones u wish to leave alone
– Kage
Sep 29 '16 at 17:51
sorry i don't know anything about powershell. I need the solutions with cmd-taskkill. Thanks anyway
– BrianC
Sep 29 '16 at 18:04
Your loss :) Powershell is a powerfull scripting tool, can do a whole lot more with it compared to cmd, all the more recent (windows) OS's come with it by default
– Kage
Sep 29 '16 at 18:07
yes i know. I really appreciate your help
– BrianC
Sep 29 '16 at 19:26
add a comment |
You can do this by specifying multiple filters for taskkill. For example, if you want to exclude explorer.exe, add a filter for the image name not being equal to explorer.exe (with the ne operator):
taskkill /f /fi "USERNAME eq %username%" /fi "IMAGENAME ne explorer.exe"
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "3"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1129712%2fkill-all-processes-with-taskkill-by-username-but-exclude-some-processes%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
Windows Native Batch Script CMD Method
Below is a batch script solution that uses Tasklist and FOR /F loops setting and parsing variables accordingly to get just the process names of the processes running of a specific user.
With Findstr these results are then parsed further to exclude any specified exclusions you set in the Exclusions variable up top.
It'll take the final remaining results and kill those process names for that specific username giving you the desired results via a batch script just as explained.
Batch Script
There are only two variables to set for this to work which are the Username and the Exclusions, and the rest will just work and do the rest of the process as you need. Just specific the full process names separated by a space one next to the other just as in the below script.
@ECHO ON
SET Username=user
SET Exclusions=explorer.exe taskmgr.exe cmd.exe
SET tmpfl=%temp%%~n0tmp.dat
IF EXIST "%tmpfl%" DEL /F /Q "%tmpfl%"
SET Exclusions=%Exclusions% taskkill.exe
SETLOCAL ENABLEDELAYEDEXPANSION
FOR /F "DELIMS=: TOKENS=2" %%A IN ('TASKLIST /FI "USERNAME EQ %Username%" /FO LIST ^| FIND /I "Image name:"') DO (
SET var=%%~A
SET var=!var: =!
ECHO !var! | FINDSTR /I /V "%Exclusions%">>"%tmpfl%"
)
FOR /F "USEBACKQ TOKENS=*" %%A IN ("%tmpfl%") DO (
TASKKILL /F /FI "USERNAME eq %Username%" /IM %%~A
)
GOTO EOF
Batch Script 2
@ECHO ON
CD /D "%~DP0"
SET Exclusions=cmd.exe explorer.exe taskmgr.exe
SET tmpfl=%~n0tmp.dat
IF EXIST "%tmpfl%" DEL /F /Q "%tmpfl%"
SET Exclusions=%Exclusions% taskkill.exe
SETLOCAL ENABLEDELAYEDEXPANSION
FOR /F "DELIMS=: TOKENS=2" %%A IN ('TASKLIST /FI "USERNAME EQ %Username%" /FO LIST ^| FIND /I "Image name:"') DO (
SET var=%%~A
SET var=!var: =!
ECHO !var! | FINDSTR /I /V "%Exclusions%">>"%tmpfl%"
)
FOR /F "USEBACKQ TOKENS=*" %%A IN ("%tmpfl%") DO (
TASKKILL /F /FI "USERNAME eq %Username%" /IM %%~A
)
DEL /F /Q "%tmpfl%"
GOTO EOF
Further Resources
- EnableDelayedExpansion
- FOR /F
- Variable Substring
- Tasklist
- Find
- Findstr
- Taskkill
Please check the script for errors. The system can not find the file C:Usersuser1 AppDataLocalTemptesttmp.dat. By the way. this variable is not viable (SET Username = user) because it must serve any account. It must be replaced by %username%
– BrianC
Sep 29 '16 at 19:35
This variable (SET Username = user) not needed. Only "USERNAME EQ %username%"
– BrianC
Sep 29 '16 at 19:50
Yes. And the change is only in user logged
– BrianC
Sep 29 '16 at 19:53
I ran the script with administrative privileges on account and the same error (win7x64)
– BrianC
Sep 29 '16 at 19:55
replace %temp% with %HOMEDRIVE%
– BrianC
Sep 29 '16 at 20:04
|
show 5 more comments
Windows Native Batch Script CMD Method
Below is a batch script solution that uses Tasklist and FOR /F loops setting and parsing variables accordingly to get just the process names of the processes running of a specific user.
With Findstr these results are then parsed further to exclude any specified exclusions you set in the Exclusions variable up top.
It'll take the final remaining results and kill those process names for that specific username giving you the desired results via a batch script just as explained.
Batch Script
There are only two variables to set for this to work which are the Username and the Exclusions, and the rest will just work and do the rest of the process as you need. Just specific the full process names separated by a space one next to the other just as in the below script.
@ECHO ON
SET Username=user
SET Exclusions=explorer.exe taskmgr.exe cmd.exe
SET tmpfl=%temp%%~n0tmp.dat
IF EXIST "%tmpfl%" DEL /F /Q "%tmpfl%"
SET Exclusions=%Exclusions% taskkill.exe
SETLOCAL ENABLEDELAYEDEXPANSION
FOR /F "DELIMS=: TOKENS=2" %%A IN ('TASKLIST /FI "USERNAME EQ %Username%" /FO LIST ^| FIND /I "Image name:"') DO (
SET var=%%~A
SET var=!var: =!
ECHO !var! | FINDSTR /I /V "%Exclusions%">>"%tmpfl%"
)
FOR /F "USEBACKQ TOKENS=*" %%A IN ("%tmpfl%") DO (
TASKKILL /F /FI "USERNAME eq %Username%" /IM %%~A
)
GOTO EOF
Batch Script 2
@ECHO ON
CD /D "%~DP0"
SET Exclusions=cmd.exe explorer.exe taskmgr.exe
SET tmpfl=%~n0tmp.dat
IF EXIST "%tmpfl%" DEL /F /Q "%tmpfl%"
SET Exclusions=%Exclusions% taskkill.exe
SETLOCAL ENABLEDELAYEDEXPANSION
FOR /F "DELIMS=: TOKENS=2" %%A IN ('TASKLIST /FI "USERNAME EQ %Username%" /FO LIST ^| FIND /I "Image name:"') DO (
SET var=%%~A
SET var=!var: =!
ECHO !var! | FINDSTR /I /V "%Exclusions%">>"%tmpfl%"
)
FOR /F "USEBACKQ TOKENS=*" %%A IN ("%tmpfl%") DO (
TASKKILL /F /FI "USERNAME eq %Username%" /IM %%~A
)
DEL /F /Q "%tmpfl%"
GOTO EOF
Further Resources
- EnableDelayedExpansion
- FOR /F
- Variable Substring
- Tasklist
- Find
- Findstr
- Taskkill
Please check the script for errors. The system can not find the file C:Usersuser1 AppDataLocalTemptesttmp.dat. By the way. this variable is not viable (SET Username = user) because it must serve any account. It must be replaced by %username%
– BrianC
Sep 29 '16 at 19:35
This variable (SET Username = user) not needed. Only "USERNAME EQ %username%"
– BrianC
Sep 29 '16 at 19:50
Yes. And the change is only in user logged
– BrianC
Sep 29 '16 at 19:53
I ran the script with administrative privileges on account and the same error (win7x64)
– BrianC
Sep 29 '16 at 19:55
replace %temp% with %HOMEDRIVE%
– BrianC
Sep 29 '16 at 20:04
|
show 5 more comments
Windows Native Batch Script CMD Method
Below is a batch script solution that uses Tasklist and FOR /F loops setting and parsing variables accordingly to get just the process names of the processes running of a specific user.
With Findstr these results are then parsed further to exclude any specified exclusions you set in the Exclusions variable up top.
It'll take the final remaining results and kill those process names for that specific username giving you the desired results via a batch script just as explained.
Batch Script
There are only two variables to set for this to work which are the Username and the Exclusions, and the rest will just work and do the rest of the process as you need. Just specific the full process names separated by a space one next to the other just as in the below script.
@ECHO ON
SET Username=user
SET Exclusions=explorer.exe taskmgr.exe cmd.exe
SET tmpfl=%temp%%~n0tmp.dat
IF EXIST "%tmpfl%" DEL /F /Q "%tmpfl%"
SET Exclusions=%Exclusions% taskkill.exe
SETLOCAL ENABLEDELAYEDEXPANSION
FOR /F "DELIMS=: TOKENS=2" %%A IN ('TASKLIST /FI "USERNAME EQ %Username%" /FO LIST ^| FIND /I "Image name:"') DO (
SET var=%%~A
SET var=!var: =!
ECHO !var! | FINDSTR /I /V "%Exclusions%">>"%tmpfl%"
)
FOR /F "USEBACKQ TOKENS=*" %%A IN ("%tmpfl%") DO (
TASKKILL /F /FI "USERNAME eq %Username%" /IM %%~A
)
GOTO EOF
Batch Script 2
@ECHO ON
CD /D "%~DP0"
SET Exclusions=cmd.exe explorer.exe taskmgr.exe
SET tmpfl=%~n0tmp.dat
IF EXIST "%tmpfl%" DEL /F /Q "%tmpfl%"
SET Exclusions=%Exclusions% taskkill.exe
SETLOCAL ENABLEDELAYEDEXPANSION
FOR /F "DELIMS=: TOKENS=2" %%A IN ('TASKLIST /FI "USERNAME EQ %Username%" /FO LIST ^| FIND /I "Image name:"') DO (
SET var=%%~A
SET var=!var: =!
ECHO !var! | FINDSTR /I /V "%Exclusions%">>"%tmpfl%"
)
FOR /F "USEBACKQ TOKENS=*" %%A IN ("%tmpfl%") DO (
TASKKILL /F /FI "USERNAME eq %Username%" /IM %%~A
)
DEL /F /Q "%tmpfl%"
GOTO EOF
Further Resources
- EnableDelayedExpansion
- FOR /F
- Variable Substring
- Tasklist
- Find
- Findstr
- Taskkill
Windows Native Batch Script CMD Method
Below is a batch script solution that uses Tasklist and FOR /F loops setting and parsing variables accordingly to get just the process names of the processes running of a specific user.
With Findstr these results are then parsed further to exclude any specified exclusions you set in the Exclusions variable up top.
It'll take the final remaining results and kill those process names for that specific username giving you the desired results via a batch script just as explained.
Batch Script
There are only two variables to set for this to work which are the Username and the Exclusions, and the rest will just work and do the rest of the process as you need. Just specific the full process names separated by a space one next to the other just as in the below script.
@ECHO ON
SET Username=user
SET Exclusions=explorer.exe taskmgr.exe cmd.exe
SET tmpfl=%temp%%~n0tmp.dat
IF EXIST "%tmpfl%" DEL /F /Q "%tmpfl%"
SET Exclusions=%Exclusions% taskkill.exe
SETLOCAL ENABLEDELAYEDEXPANSION
FOR /F "DELIMS=: TOKENS=2" %%A IN ('TASKLIST /FI "USERNAME EQ %Username%" /FO LIST ^| FIND /I "Image name:"') DO (
SET var=%%~A
SET var=!var: =!
ECHO !var! | FINDSTR /I /V "%Exclusions%">>"%tmpfl%"
)
FOR /F "USEBACKQ TOKENS=*" %%A IN ("%tmpfl%") DO (
TASKKILL /F /FI "USERNAME eq %Username%" /IM %%~A
)
GOTO EOF
Batch Script 2
@ECHO ON
CD /D "%~DP0"
SET Exclusions=cmd.exe explorer.exe taskmgr.exe
SET tmpfl=%~n0tmp.dat
IF EXIST "%tmpfl%" DEL /F /Q "%tmpfl%"
SET Exclusions=%Exclusions% taskkill.exe
SETLOCAL ENABLEDELAYEDEXPANSION
FOR /F "DELIMS=: TOKENS=2" %%A IN ('TASKLIST /FI "USERNAME EQ %Username%" /FO LIST ^| FIND /I "Image name:"') DO (
SET var=%%~A
SET var=!var: =!
ECHO !var! | FINDSTR /I /V "%Exclusions%">>"%tmpfl%"
)
FOR /F "USEBACKQ TOKENS=*" %%A IN ("%tmpfl%") DO (
TASKKILL /F /FI "USERNAME eq %Username%" /IM %%~A
)
DEL /F /Q "%tmpfl%"
GOTO EOF
Further Resources
- EnableDelayedExpansion
- FOR /F
- Variable Substring
- Tasklist
- Find
- Findstr
- Taskkill
edited Sep 29 '16 at 21:25
answered Sep 29 '16 at 19:26
Pimp Juice ITPimp Juice IT
23.1k113969
23.1k113969
Please check the script for errors. The system can not find the file C:Usersuser1 AppDataLocalTemptesttmp.dat. By the way. this variable is not viable (SET Username = user) because it must serve any account. It must be replaced by %username%
– BrianC
Sep 29 '16 at 19:35
This variable (SET Username = user) not needed. Only "USERNAME EQ %username%"
– BrianC
Sep 29 '16 at 19:50
Yes. And the change is only in user logged
– BrianC
Sep 29 '16 at 19:53
I ran the script with administrative privileges on account and the same error (win7x64)
– BrianC
Sep 29 '16 at 19:55
replace %temp% with %HOMEDRIVE%
– BrianC
Sep 29 '16 at 20:04
|
show 5 more comments
Please check the script for errors. The system can not find the file C:Usersuser1 AppDataLocalTemptesttmp.dat. By the way. this variable is not viable (SET Username = user) because it must serve any account. It must be replaced by %username%
– BrianC
Sep 29 '16 at 19:35
This variable (SET Username = user) not needed. Only "USERNAME EQ %username%"
– BrianC
Sep 29 '16 at 19:50
Yes. And the change is only in user logged
– BrianC
Sep 29 '16 at 19:53
I ran the script with administrative privileges on account and the same error (win7x64)
– BrianC
Sep 29 '16 at 19:55
replace %temp% with %HOMEDRIVE%
– BrianC
Sep 29 '16 at 20:04
Please check the script for errors. The system can not find the file C:Usersuser1 AppDataLocalTemptesttmp.dat. By the way. this variable is not viable (SET Username = user) because it must serve any account. It must be replaced by %username%
– BrianC
Sep 29 '16 at 19:35
Please check the script for errors. The system can not find the file C:Usersuser1 AppDataLocalTemptesttmp.dat. By the way. this variable is not viable (SET Username = user) because it must serve any account. It must be replaced by %username%
– BrianC
Sep 29 '16 at 19:35
This variable (SET Username = user) not needed. Only "USERNAME EQ %username%"
– BrianC
Sep 29 '16 at 19:50
This variable (SET Username = user) not needed. Only "USERNAME EQ %username%"
– BrianC
Sep 29 '16 at 19:50
Yes. And the change is only in user logged
– BrianC
Sep 29 '16 at 19:53
Yes. And the change is only in user logged
– BrianC
Sep 29 '16 at 19:53
I ran the script with administrative privileges on account and the same error (win7x64)
– BrianC
Sep 29 '16 at 19:55
I ran the script with administrative privileges on account and the same error (win7x64)
– BrianC
Sep 29 '16 at 19:55
replace %temp% with %HOMEDRIVE%
– BrianC
Sep 29 '16 at 20:04
replace %temp% with %HOMEDRIVE%
– BrianC
Sep 29 '16 at 20:04
|
show 5 more comments
I would personally do this by using powershell.
Something like this:
$processes = Get-Process -IncludeUserName | where {$_.UserName -like "*USERNAME*"}
$tobeignored = @("explorer","Taskmgr","cmd")
foreach($process in $processes)
{
if($tobeignored.Contains($process.ProcessName))
{
continue;
}
else
{
Stop-Process $process.Id -Force
}
}
I have not been able to test run this, I kinda dont wanna kill my own processes :) Let me know if it (doesn't) work(s)
Ok tested it, and made a little change :) this does the trick. Just add the proccess names (without extention) to the array, the ones u wish to leave alone
– Kage
Sep 29 '16 at 17:51
sorry i don't know anything about powershell. I need the solutions with cmd-taskkill. Thanks anyway
– BrianC
Sep 29 '16 at 18:04
Your loss :) Powershell is a powerfull scripting tool, can do a whole lot more with it compared to cmd, all the more recent (windows) OS's come with it by default
– Kage
Sep 29 '16 at 18:07
yes i know. I really appreciate your help
– BrianC
Sep 29 '16 at 19:26
add a comment |
I would personally do this by using powershell.
Something like this:
$processes = Get-Process -IncludeUserName | where {$_.UserName -like "*USERNAME*"}
$tobeignored = @("explorer","Taskmgr","cmd")
foreach($process in $processes)
{
if($tobeignored.Contains($process.ProcessName))
{
continue;
}
else
{
Stop-Process $process.Id -Force
}
}
I have not been able to test run this, I kinda dont wanna kill my own processes :) Let me know if it (doesn't) work(s)
Ok tested it, and made a little change :) this does the trick. Just add the proccess names (without extention) to the array, the ones u wish to leave alone
– Kage
Sep 29 '16 at 17:51
sorry i don't know anything about powershell. I need the solutions with cmd-taskkill. Thanks anyway
– BrianC
Sep 29 '16 at 18:04
Your loss :) Powershell is a powerfull scripting tool, can do a whole lot more with it compared to cmd, all the more recent (windows) OS's come with it by default
– Kage
Sep 29 '16 at 18:07
yes i know. I really appreciate your help
– BrianC
Sep 29 '16 at 19:26
add a comment |
I would personally do this by using powershell.
Something like this:
$processes = Get-Process -IncludeUserName | where {$_.UserName -like "*USERNAME*"}
$tobeignored = @("explorer","Taskmgr","cmd")
foreach($process in $processes)
{
if($tobeignored.Contains($process.ProcessName))
{
continue;
}
else
{
Stop-Process $process.Id -Force
}
}
I have not been able to test run this, I kinda dont wanna kill my own processes :) Let me know if it (doesn't) work(s)
I would personally do this by using powershell.
Something like this:
$processes = Get-Process -IncludeUserName | where {$_.UserName -like "*USERNAME*"}
$tobeignored = @("explorer","Taskmgr","cmd")
foreach($process in $processes)
{
if($tobeignored.Contains($process.ProcessName))
{
continue;
}
else
{
Stop-Process $process.Id -Force
}
}
I have not been able to test run this, I kinda dont wanna kill my own processes :) Let me know if it (doesn't) work(s)
edited Sep 29 '16 at 17:51
answered Sep 29 '16 at 17:42
KageKage
33619
33619
Ok tested it, and made a little change :) this does the trick. Just add the proccess names (without extention) to the array, the ones u wish to leave alone
– Kage
Sep 29 '16 at 17:51
sorry i don't know anything about powershell. I need the solutions with cmd-taskkill. Thanks anyway
– BrianC
Sep 29 '16 at 18:04
Your loss :) Powershell is a powerfull scripting tool, can do a whole lot more with it compared to cmd, all the more recent (windows) OS's come with it by default
– Kage
Sep 29 '16 at 18:07
yes i know. I really appreciate your help
– BrianC
Sep 29 '16 at 19:26
add a comment |
Ok tested it, and made a little change :) this does the trick. Just add the proccess names (without extention) to the array, the ones u wish to leave alone
– Kage
Sep 29 '16 at 17:51
sorry i don't know anything about powershell. I need the solutions with cmd-taskkill. Thanks anyway
– BrianC
Sep 29 '16 at 18:04
Your loss :) Powershell is a powerfull scripting tool, can do a whole lot more with it compared to cmd, all the more recent (windows) OS's come with it by default
– Kage
Sep 29 '16 at 18:07
yes i know. I really appreciate your help
– BrianC
Sep 29 '16 at 19:26
Ok tested it, and made a little change :) this does the trick. Just add the proccess names (without extention) to the array, the ones u wish to leave alone
– Kage
Sep 29 '16 at 17:51
Ok tested it, and made a little change :) this does the trick. Just add the proccess names (without extention) to the array, the ones u wish to leave alone
– Kage
Sep 29 '16 at 17:51
sorry i don't know anything about powershell. I need the solutions with cmd-taskkill. Thanks anyway
– BrianC
Sep 29 '16 at 18:04
sorry i don't know anything about powershell. I need the solutions with cmd-taskkill. Thanks anyway
– BrianC
Sep 29 '16 at 18:04
Your loss :) Powershell is a powerfull scripting tool, can do a whole lot more with it compared to cmd, all the more recent (windows) OS's come with it by default
– Kage
Sep 29 '16 at 18:07
Your loss :) Powershell is a powerfull scripting tool, can do a whole lot more with it compared to cmd, all the more recent (windows) OS's come with it by default
– Kage
Sep 29 '16 at 18:07
yes i know. I really appreciate your help
– BrianC
Sep 29 '16 at 19:26
yes i know. I really appreciate your help
– BrianC
Sep 29 '16 at 19:26
add a comment |
You can do this by specifying multiple filters for taskkill. For example, if you want to exclude explorer.exe, add a filter for the image name not being equal to explorer.exe (with the ne operator):
taskkill /f /fi "USERNAME eq %username%" /fi "IMAGENAME ne explorer.exe"
add a comment |
You can do this by specifying multiple filters for taskkill. For example, if you want to exclude explorer.exe, add a filter for the image name not being equal to explorer.exe (with the ne operator):
taskkill /f /fi "USERNAME eq %username%" /fi "IMAGENAME ne explorer.exe"
add a comment |
You can do this by specifying multiple filters for taskkill. For example, if you want to exclude explorer.exe, add a filter for the image name not being equal to explorer.exe (with the ne operator):
taskkill /f /fi "USERNAME eq %username%" /fi "IMAGENAME ne explorer.exe"
You can do this by specifying multiple filters for taskkill. For example, if you want to exclude explorer.exe, add a filter for the image name not being equal to explorer.exe (with the ne operator):
taskkill /f /fi "USERNAME eq %username%" /fi "IMAGENAME ne explorer.exe"
answered Dec 14 '18 at 17:23
Owen PaulingOwen Pauling
17114
17114
add a comment |
add a comment |
Thanks for contributing an answer to Super User!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1129712%2fkill-all-processes-with-taskkill-by-username-but-exclude-some-processes%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Hi there. We're not a scriptwriting service, so since you've specified that you're trying to solve this with a Batch script, please include what you've attempted already, what the results were, and what's tripping you up exactly. If this doesn't NEED to be in batch and/or using
taskkill, please edit your question to remove the Batch tag, so you'll increase you chances of getting answers (that may or may not be Batch based). :)– Ƭᴇcʜιᴇ007
Sep 29 '16 at 17:07
the question is very clear and precise
– BrianC
Sep 29 '16 at 17:17
Brian - See below in my answer for a tested and confirmed working process from what I tested and could confirm it works as expected. Let me know how it goes.
– Pimp Juice IT
Sep 29 '16 at 19:27