Problem med detta script : Kill all running apps

Permalänk
Medlem

Problem med detta script : Kill all running apps

Denna kod skall stänga av alla processer som användaren har startat. Vilket den gör men den stänger även av sig själv vilket den inte gör i Vista.

Koden dör pådirekt och märker inte av pause eller att den inte ska stänga av cmd.
Att lägga till chrome funkar men inte CMD.

Koden funkar på vista men inte på windows 7 eller 8.

Har någon en annan liknande kod eller hur man kan ändra för att göra det kompatibelt?
Jag har gjort allt i min makt för att försöka få den att funka men något snille här kan nog fixa det!

kod:
@echo off
cd c:windowsSystem32
for /f “skip=3 tokens=1″ %%i in (‘TASKLIST /FI “USERNAME ne NT AUTHORITYSYSTEM”‘) do (
if not “%%i”==”svchost.exe” (
if not “%%i”==”explorer.exe” (
if not “%%i”==”cmd.exe” (
if not “%%i”==”tasklist.exe” (
echo %%i
taskkill /f /im “%%i”
)
)
)
)
)
pause

Visa signatur

Stationär: RTX 3090 OC MSI TRIO X 24GB | Ryzen 9 5950X | G.Skill Trident Z NEO 3600mhz 32GB | Noctua NH-D15 Chromax | Corsair HX1000i | Asus Rog Strix X570-F Gaming | Samsung 980 PRO 2TB | Samsung 970 EVO 512 GB | Samsung 850 PRO 512 GB | Seagate SSHD 2TB | Be Quiet! Base Pro 900 Silver Rev.2

Jobbdator: MacBook Pro 16" i7 6C, 16GB ram DDR4, AMD Radeon Pro 5300M 4GB

Permalänk
Skrivet av klotim:

Denna kod skall stänga av alla processer som användaren har startat. Vilket den gör men den stänger även av sig själv vilket den inte gör i Vista.

Koden dör pådirekt och märker inte av pause eller att den inte ska stänga av cmd.
Att lägga till chrome funkar men inte CMD.

Koden funkar på vista men inte på windows 7 eller 8.

Har någon en annan liknande kod eller hur man kan ändra för att göra det kompatibelt?
Jag har gjort allt i min makt för att försöka få den att funka men något snille här kan nog fixa det!

kod:

@echo off cd C:\Windows\System32 for /f "skip=3 tokens=1" %%i in ('TASKLIST /FI "USERNAME ne NT AUTHORITYSYSTEM"') do ( if not "%%i"=="svchost.exe" ( if not "%%i"=="explorer.exe" ( if not "%%i"=="cmd.exe" ( if not "%%i"=="tasklist.exe" ( echo %%i taskkill /f /im "%%i" ) ) ) ) ) pause

Bytte till endast vlc bara för att testa, men det fungerar för mig i Windows 7.

cd c:\windows\System32 for /f "skip=3 tokens=1" %%i in ('TASKLIST /FI "USERNAME ne NT AUTHORITYSYSTEM"') do ( echo %%i if "%%i"=="vlc.exe" ( taskkill /f /im "%%i" ) ) pause

Använd gärna "code" taggen så blir det lättare för andra att kopiera.

Permalänk
Medlem
Skrivet av StabTheDrama:

Bytte till endast vlc bara för att testa, men det fungerar för mig i Windows 7.
Använd gärna "code" taggen så blir det lättare för andra att kopiera.

Ja men det är inte det som är problemet, processen stänger av sig själv, i detta fall, CMD...

Visa signatur

Stationär: RTX 3090 OC MSI TRIO X 24GB | Ryzen 9 5950X | G.Skill Trident Z NEO 3600mhz 32GB | Noctua NH-D15 Chromax | Corsair HX1000i | Asus Rog Strix X570-F Gaming | Samsung 980 PRO 2TB | Samsung 970 EVO 512 GB | Samsung 850 PRO 512 GB | Seagate SSHD 2TB | Be Quiet! Base Pro 900 Silver Rev.2

Jobbdator: MacBook Pro 16" i7 6C, 16GB ram DDR4, AMD Radeon Pro 5300M 4GB

Permalänk
Hedersmedlem
Skrivet av klotim:

Ja men det är inte det som är problemet, processen stänger av sig själv, i detta fall, CMD...

Har du testat att lägga till ett pause före taskkill för att se när det inträffar?

Permalänk
Medlem
Skrivet av Elgot:

Har du testat att lägga till ett pause före taskkill för att se när det inträffar?

Här är slutresultatet. De ser ju ut som att pause funkar men icke. Jag har ändrat så att det ser ut såhär nu :

@ECHO ON call :Logit>batch.log 2>&1 exit /b 0 :Logit 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"=="csrss.exe" ( if not "%%i"=="Conhost.exe" ( 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

Är det mer processer som har med CMD att göra??

Här är resultatet:

C:\Users\AdamN_000\Desktop>cd c:\windows\System32 c:\Windows\System32>for /F "skip=3 tokens=1" %i in ('TASKLIST /FI "USERNAME eq Adam\Adam" /FI "STATUS eq running"') do (if not "%i" == "csrss.exe" (if not "%i" == "Conhost.exe" (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. ) ) ) ) ) ) ) c:\Windows\System32>(if not "explorer.exe" == "csrss.exe" (if not "explorer.exe" == "Conhost.exe" (if not "explorer.exe" == "svchost.exe" (if not "explorer.exe" == "explorer.exe" (if not "explorer.exe" == "cmd.exe" (if not "explorer.exe" == "tasklist.exe" ( echo. taskkill /f /im "explorer.exe" echo. ) ) ) ) ) ) ) c:\Windows\System32>(if not "TuneUpUtilitiesApp64.exe" == "csrss.exe" (if not "TuneUpUtilitiesApp64.exe" == "Conhost.exe" (if not "TuneUpUtilitiesApp64.exe" == "svchost.exe" (if not "TuneUpUtilitiesApp64.exe" == "explorer.exe" (if not "TuneUpUtilitiesApp64.exe" == "cmd.exe" (if not "TuneUpUtilitiesApp64.exe" == "tasklist.exe" ( echo. taskkill /f /im "TuneUpUtilitiesApp64.exe" echo. ) ) ) ) ) ) ) SUCCESS: The process "TuneUpUtilitiesApp64.exe" with PID 1948 has been terminated. c:\Windows\System32>(if not "dllhost.exe" == "csrss.exe" (if not "dllhost.exe" == "Conhost.exe" (if not "dllhost.exe" == "svchost.exe" (if not "dllhost.exe" == "explorer.exe" (if not "dllhost.exe" == "cmd.exe" (if not "dllhost.exe" == "tasklist.exe" ( echo. taskkill /f /im "dllhost.exe" echo. ) ) ) ) ) ) ) SUCCESS: The process "dllhost.exe" with PID 4904 has been terminated. SUCCESS: The process "dllhost.exe" with PID 4440 has been terminated. c:\Windows\System32>(if not "dllhost.exe" == "csrss.exe" (if not "dllhost.exe" == "Conhost.exe" (if not "dllhost.exe" == "svchost.exe" (if not "dllhost.exe" == "explorer.exe" (if not "dllhost.exe" == "cmd.exe" (if not "dllhost.exe" == "tasklist.exe" ( echo. taskkill /f /im "dllhost.exe" echo. ) ) ) ) ) ) ) ERROR: The process "dllhost.exe" not found. c:\Windows\System32>(if not "cmd.exe" == "csrss.exe" (if not "cmd.exe" == "Conhost.exe" (if not "cmd.exe" == "svchost.exe" (if not "cmd.exe" == "explorer.exe" (if not "cmd.exe" == "cmd.exe" (if not "cmd.exe" == "tasklist.exe" ( echo. taskkill /f /im "cmd.exe" echo. ) ) ) ) ) ) ) c:\Windows\System32>(if not "conhost.exe" == "csrss.exe" (if not "conhost.exe" == "Conhost.exe" (if not "conhost.exe" == "svchost.exe" (if not "conhost.exe" == "explorer.exe" (if not "conhost.exe" == "cmd.exe" (if not "conhost.exe" == "tasklist.exe" ( echo. taskkill /f /im "conhost.exe" echo. ) ) ) ) ) ) ) SUCCESS: The process "conhost.exe" with PID 1996 has been terminated. c:\Windows\System32>pause Press any key to continue . . .

alla processer som är igång...

Image Name PID Session Name Session# Mem Usage ========================= ======== ================ =========== ============ System Idle Process 0 Services 0 20 K System 4 Services 0 1,932 K smss.exe 376 Services 0 1,048 K csrss.exe 532 Services 0 4,284 K wininit.exe 656 Services 0 3,980 K csrss.exe 664 Console 1 7,152 K winlogon.exe 716 Console 1 8,452 K services.exe 740 Services 0 8,604 K lsass.exe 756 Services 0 11,084 K svchost.exe 852 Services 0 8,532 K nvvsvc.exe 888 Services 0 7,244 K nvSCPAPISvr.exe 912 Services 0 5,756 K svchost.exe 956 Services 0 7,316 K svchost.exe 1000 Services 0 17,200 K svchost.exe 220 Services 0 36,740 K svchost.exe 560 Services 0 10,072 K svchost.exe 940 Services 0 14,004 K nvxdsync.exe 1072 Console 1 17,804 K nvvsvc.exe 1080 Console 1 13,084 K Start8Srv.exe 1144 Services 0 860 K Start8_64.exe 1172 Console 1 4,028 K svchost.exe 1196 Services 0 25,676 K svchost.exe 1300 Services 0 19,620 K armsvc.exe 1504 Services 0 3,972 K svchost.exe 1524 Services 0 8,116 K AdminService.exe 1548 Services 0 4,904 K inetinfo.exe 1612 Services 0 19,376 K IPROSetMonitor.exe 1656 Services 0 4,020 K mqsvc.exe 1700 Services 0 10,360 K SMSvcHost.exe 1740 Services 0 25,968 K daemonu.exe 1032 Services 0 44,436 K PnkBstrA.exe 1316 Services 0 4,144 K psia.exe 1592 Services 0 19,140 K TuneUpUtilitiesService64. 2104 Services 0 21,496 K svchost.exe 2128 Services 0 9,224 K MsMpEng.exe 2160 Services 0 59,288 K mqtgsvc.exe 2248 Services 0 5,480 K SMSvcHost.exe 2292 Services 0 16,668 K explorer.exe 3108 Console 1 136,344 K svchost.exe 3456 Services 0 3,996 K sua.exe 3964 Services 0 3,520 K SearchIndexer.exe 4064 Services 0 16,664 K svchost.exe 3856 Services 0 4,676 K dwm.exe 2592 Console 1 32,508 K WmiPrvSE.exe 4036 Services 0 5,644 K WmiPrvSE.exe 4472 Services 0 7,700 K cmd.exe 3096 Console 1 2,436 K conhost.exe 4072 Console 1 5,144 K TuneUpUtilitiesApp64.exe 2752 Console 1 10,948 K tasklist.exe 2744 Console 1 5,516 K

Visa signatur

Stationär: RTX 3090 OC MSI TRIO X 24GB | Ryzen 9 5950X | G.Skill Trident Z NEO 3600mhz 32GB | Noctua NH-D15 Chromax | Corsair HX1000i | Asus Rog Strix X570-F Gaming | Samsung 980 PRO 2TB | Samsung 970 EVO 512 GB | Samsung 850 PRO 512 GB | Seagate SSHD 2TB | Be Quiet! Base Pro 900 Silver Rev.2

Jobbdator: MacBook Pro 16" i7 6C, 16GB ram DDR4, AMD Radeon Pro 5300M 4GB

Permalänk
Hedersmedlem
Skrivet av klotim:

(if not "conhost.exe" == "csrss.exe" (if not "conhost.exe" == "Conhost.exe" (if not "conhost.exe" == "svchost.exe" (if not "conhost.exe" == "explorer.exe" (if not "conhost.exe" == "cmd.exe" (if not "conhost.exe" == "tasklist.exe" ( echo. taskkill /f /im "conhost.exe" echo. ) ) ) ) ) ) ) SUCCESS: The process "conhost.exe" with PID 1996 has been terminated.

Det skall nog inte vara ett stort 'C' i "Conhost" där.

Permalänk
Medlem
Skrivet av Elgot:

Det skall nog inte vara ett stort 'C' i "Conhost" där.

:/ stänger av sig själv fortfarande, jag vill att de ska vara kvar o faktiskt lyssna på paus kommandot på slutet inte stänga av sig själv :/
Det funkade på Vista så de måste vara andra kommandon som gäller nu? Trodde Vista / 7 / 8 har samma kommandon.

Visa signatur

Stationär: RTX 3090 OC MSI TRIO X 24GB | Ryzen 9 5950X | G.Skill Trident Z NEO 3600mhz 32GB | Noctua NH-D15 Chromax | Corsair HX1000i | Asus Rog Strix X570-F Gaming | Samsung 980 PRO 2TB | Samsung 970 EVO 512 GB | Samsung 850 PRO 512 GB | Seagate SSHD 2TB | Be Quiet! Base Pro 900 Silver Rev.2

Jobbdator: MacBook Pro 16" i7 6C, 16GB ram DDR4, AMD Radeon Pro 5300M 4GB

Permalänk
Hedersmedlem
Skrivet av klotim:

:/ stänger av sig själv fortfarande, jag vill att de ska vara kvar o faktiskt lyssna på paus kommandot på slutet inte stänga av sig själv :/
Det funkade på Vista så de måste vara andra kommandon som gäller nu? Trodde Vista / 7 / 8 har samma kommandon.

Conhost verkar dock vara ny in windows7 (så det hade varit en trevlig förklaring). Men testa då att köra pause före varje taskkill och stega igenom (eventuell långsamt).

Permalänk
Medlem

EDIT:
Script funkar nu för windows 7 och 8 samt vista:

@ECHO ON 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"=="wininit.exe" ( if not "%%i"=="smss.exe" ( if not "%%i"=="lsass.exe" ( if not "%%i"=="csrss.exe" ( if not "%%i"=="conhost.exe" ( if not "%%i"=="cmd.exe" ( if not "%%i"=="svchost.exe" ( if not "%%i"=="explorer.exe" ( if not "%%i"=="tasklist.exe" ( if not "%%i"=="%0" ( echo. taskkill /f /im "%%i" echo. ) ) ) ) ) ) ) ) ) ) ) ) pause

Visa signatur

Stationär: RTX 3090 OC MSI TRIO X 24GB | Ryzen 9 5950X | G.Skill Trident Z NEO 3600mhz 32GB | Noctua NH-D15 Chromax | Corsair HX1000i | Asus Rog Strix X570-F Gaming | Samsung 980 PRO 2TB | Samsung 970 EVO 512 GB | Samsung 850 PRO 512 GB | Seagate SSHD 2TB | Be Quiet! Base Pro 900 Silver Rev.2

Jobbdator: MacBook Pro 16" i7 6C, 16GB ram DDR4, AMD Radeon Pro 5300M 4GB

Permalänk
Hedersmedlem
Skrivet av klotim:

Har jag skrivit fel eller måste man skriva specifika PID med?

Du har fortfarande ett stort 'C'.

Permalänk
Medlem
Skrivet av Elgot:

Du har fortfarande ett stort 'C'.

Aa la upp den gamla loggen igår för att visa bara. Scriptet funkar nu av någon anledning!

Visa signatur

Stationär: RTX 3090 OC MSI TRIO X 24GB | Ryzen 9 5950X | G.Skill Trident Z NEO 3600mhz 32GB | Noctua NH-D15 Chromax | Corsair HX1000i | Asus Rog Strix X570-F Gaming | Samsung 980 PRO 2TB | Samsung 970 EVO 512 GB | Samsung 850 PRO 512 GB | Seagate SSHD 2TB | Be Quiet! Base Pro 900 Silver Rev.2

Jobbdator: MacBook Pro 16" i7 6C, 16GB ram DDR4, AMD Radeon Pro 5300M 4GB