--- --
--- -- (1)
for /f "skip=3 " %%i in ('wmic process get name') do (
for %%b in (smss.exe,csrss.exe,winlogon.exe,services.exe,lsass.exe,
svchost.exe,Explorer.exe) do if /i not %%i==%%b taskkill /im %%i /t
)
pause
Where the error is: for example, if the process name obtained by 'wmic process get name' is services.exe, when processing the if statement, it becomes if /i not services.exe ==smss.exe taskkill /im services.exe /t, then in the next loop if /i not services.exe ==csrss.exe taskkill /im services.exe /t ……
As a result, it can't preserve smss.exe,csrss.exe,winlogon.exe,services.exe,lsass.exe,
svchost.exe,Explorer.exe (on the condition that I'm using pskill)
--- -- (2)
for /f "skip=3" %%i in ('wmic process get name') do ( if /i not "%%
i"==smss.exe if /i not "%%i"==csrss.exe if /i not "%%i"==winlogon.exe
if /i not "%%i"==services.exe if /i not "%%i"==lsass.exe if /i not "%%
i"==svchost.exe if /i not "%%i"==Explorer.exe taskkill /f /im "%%i")
pause
Where the error is:
Again taking services.exe as an example, when processing the if statement, I think it should be handled like this:
if /i not services.exe ==smss.exe if /i not services.exe ==csrss.exe if /i not services.exe==winlogon.exe …… if /i not services.exe==Explorer.exe taskkill /f /im services.exe
It should pass through the filtering of the if statements one by one, but in reality it only processes the first if statement:
if /i not services.exe==smss.exe then it executes taskkill /f /im services.exe right away!
I don't understand!
--- -- (3)
Another idea is to use 'wmic process get name' to list the processes, then find
smss.exe,csrss.exe,winlogon.exe,services.exe,lsass.exe,svchost.exe,Explorer.exe and remove them, leaving the processes that should be ended. In one sentence, filtering. Not sure whether that's feasible?
(I don't know how to filter)
Please advise, experts, or if there is any other method that's fine too, many thanks!!