I'm trying to write a batch file (or powershell script) that closes all programs with active windows, except certain programs. I also don't want just any program Windows is running to be closed, just programs I've opened. I also can't program a list of what programs tokill, so I can't simply do this:
@echo off
set programs[0] = program1;
set programs[1] = program2; etc;
for %%a in (%programs%) do (
taskkill /F /im %%a
echo/
)
I would like something that looks like this (<...> indicating parts I don't know):
@echo off
set safeList[0] = program1;
set safeList[1] = program2; etc;
set activePrograms = <get all active programs that aren't basic windows processes, startup programs, etc.>
for %%a in (%activePrograms%) do (
if(<%%a not found in safeList>) (
taskkill /F /im %%a
echo/
)
)
Obviously, the activePrograms part should not include basic windows tasks (ie. explorer.exe), as that would be chaotic. I would like to not have to define every single running task in safeList.