0

working from home on my private PC via Citrix with web sessions, skype sessions, ... I'd like to make sure that I've gained privacy after end of work. I've figured out the following batch script to close all job related taskbar tasks by one double click. It's kind of brute force, but a single taskkill (therefor) hasn't done the job on certain (nested) processes in the past. Any suggestions for improvements?

Translations:

       ist beendet       = e.g. = is terminated
       ist nicht beendet = e.g. = is not terminated

Best Regards Matt

GetPrivacy_v4.bat

  @ECHO OFF
  ECHO ############# STARTING ###############
  SETLOCAL ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION
  SET   FILE        = ""
  SET/A ACTFILE     = 0
  SET/A MAXFILE     = 0
  SET/A TRIES       = 1
  SET   "SUCCESS=TRUE"
  set "LIST=(msedge.exe AuthManSvr.exe AnyDesk.exe wfcrun32.exe Concentr.exe CtxWebBrowser.exe
             SelfService.exe SelfServicePlugin.exe Skype.exe TeamViewer_service.exe
             g2mlauncher.exe g2mcomm.exe redirector.exe dropbox.exe Teams.exe)"
  for %%x in %LIST% do SET/A MAXFILE += 1
  for %%x in %LIST% do ( 
      SET/A ACTFILE += 1
      SET   FILE=%%x    
      SET   "SUCCESS=TRUE"
      SET/A TRIES=1
  
      FOR /L %%T IN (1,1,5) DO (     
  
        IF !TRIES! LEQ 5 (     
          start /MIN taskkill /F /T /IM !FILE! 2>&0
  
          FOR /f "tokens=1-6,* delims=. " %%a IN ('TASKLIST') DO (     
             IF "%a%" == "!FILE!" SET "SUCCESS=FALSE"  
          )
  
          IF "%SUCCESS%" == "TRUE" (
            SET/A TRIES = 6
          ) ELSE (
            SET/A TRIES = %%T
          )
        )
      )
      IF !TRIES! == 6 (
        IF "%SUCCESS%" == "TRUE"  ( ECHO !ACTFILE!/!MAXFILE!: !FILE! ist beendet )
        IF "%SUCCESS%" == "FALSE" ( ECHO !ACTFILE!/!MAXFILE!: !FILE! ist nicht beendet )
      )
  )
  
  ECHO ############### DONE #################
  PAUSE
Compo
  • 36,585
  • 5
  • 27
  • 39
  • DOS is very different and doesn't support things like `start`, `set /a` or code blocks like that so this definitely can't run in DOS – phuclv Nov 25 '21 at 15:30
  • Updated version with formatted output (DELTA): SET "SPACES= " IF !ACTFILE! LEQ 9 ( SET "INDEX=0!ACTFILE!" ) ELSE ( SET "INDEX=!ACTFILE!" ) SET "MSG=!FILE!!SPACES!" SET "MSG=!MSG:~0,25!" IF "%SUCCESS%" == "TRUE" ( ECHO !INDEX!/!MAXFILE!: !MSG! ist beendet ) IF "%SUCCESS%" == "FALSE" ( ECHO !INDEX!/!MAXFILE!: !MSG! ist nicht beendet .... – B. Matt B. Feb 17 '22 at 18:30

0 Answers0