"bat" file keeps closing after executing
Posted: 25 Aug 2019 13:56
Good afternoon everyone,
Hi my name is Brian and I have rewritten a bat file I have and trying to combined my other ones so that I have one Master bat file to run. I will use it for deep cleaning computers I work with at work (win7/win10). The first part of the bat is for killing task/processes and I believe that is where my problem starts. I have remove that part and was able to get the bat to work. So I just need to get the first part "killing task/processes" to work and then I believe the rest of the bat file will run. For some reason after I "right click" and "run as Administrator" the first few line will run and then the bat file just closes. Can someone please help me out as I would like to use it at work?
Thank you,
Brian
Hi my name is Brian and I have rewritten a bat file I have and trying to combined my other ones so that I have one Master bat file to run. I will use it for deep cleaning computers I work with at work (win7/win10). The first part of the bat is for killing task/processes and I believe that is where my problem starts. I have remove that part and was able to get the bat to work. So I just need to get the first part "killing task/processes" to work and then I believe the rest of the bat file will run. For some reason after I "right click" and "run as Administrator" the first few line will run and then the bat file just closes. Can someone please help me out as I would like to use it at work?
Thank you,
Brian
Code: Select all
@echo off
Color 0C
echo Kill Task.....EXECUTING!!!
TIMEOUT /T 10
SETLOCAL EnableDelayedExpansion
cd c:\Windows\System32
FOR /F “DELIMS=: TOKENS=2” %%i IN (‘TASKLIST /FI “USERNAME EQ %userdomain%\%username%” /FO LIST ^| FIND /I “Image name: “‘) DO (
:: Remove space
SET var=%%~i
SET MyVar=!var!
SET MyVar=!MyVar: =!
:: Process with space in the name
if “!MyVar!”==”AutomationAnywhere.exe” (
SET “MyVar=Automation Anywhere.exe”
)
:: Applications
if not “!MyVar!”==”Automation Anywhere.exe” (
if not “!MyVar!”==”always-on-top.exe” (
:: Windows Services
if not “!MyVar!”==”svchost.exe” (
if not “!MyVar!”==”explorer.exe” (
if not “!MyVar!”==”cmd.exe” (
if not “!MyVar!”==”conhost.exe” (
if not “!MyVar!”==”dllhost.exe” (
if not “!MyVar!”==”tasklist.exe” (
if not “!MyVar!”==”vmtoolsd.exe” (
if not “!MyVar!”==”dwm.exe” (
if not “!MyVar!”==”taskhostex.exe” (
if not “!MyVar!”==”rdpclip.exe” (
if not “!MyVar!”==”find.exe” (
taskkill /f /im “!MyVar!” /FI “USERNAME EQ %userdomain%\%username%”
) ) ) ) ) ) ) ) ) ) ) ) )
)
echo.
echo Waiting 5 seconds…
echo.
TIMEOUT / 5
echo CleanUp.....INVOKING!!!
TIMEOUT /T 5
Color 0A
ECHO -----
ECHO STATUS: CHKDSK scheduling in progress.
ECHO Y | CHKDSK C: /F
ECHO STATUS: CHKDSK scheduling completed, defragmentation in progress.
defrag.exe c: -f /h /x
REM Checking System File Integrity
ECHO Checking System File Integritu
SFC /SCANNOW
echo Cleaning system junk files, please wait…
REM displays a line of text
del /f /s /q %systemdrive%\*.tmp
del /f /s /q %systemdrive%\*._mp
del /f /s /q %systemdrive%\*.log
del /f /s /q %systemdrive%\*.gid
del /f /s /q %systemdrive%\*.chk
del /f /s /q %systemdrive%\*.old
del /f /s /q %systemdrive%\recycled\*.*
del /f /s /q %windir%\*.bak
del /f /s /q %windir%\prefetch\*.*
rd /s /q %windir%\temp & md %windir%\temp
del /f /q %userprofile%\cookies\*.*
del /f /q %userprofile%\recent\*.*
del /f /s /q “%userprofile%\Local Settings\Temporary Internet Files\*.*”
del /f /s /q “%userprofile%\Local Settings\Temp\*.*”
del /f /s /q “%userprofile%\recent\*.*”
REM /f: force deleting of read-only files
REM /s: Delete specified files from all subdirectories.
REM /q: Quiet mode, do not ask if ok to delete on global wildcard
REM %systemdrive%: drive upon which the system folder was placed
REM %windir%: a regular variable and is defined in the variable store as %SystemRoot%.
REM %userprofile%: variable to find the directory structure owned by the user running the process
del /s /f /q c:\windows\temp\*.*
rd /s /q c:\windows\temp
md c:\windows\temp
del /s /f /q C:\WINDOWS\Prefetch
del /s /f /q %temp%\*.*
rd /s /q %temp%
md %temp%
deltree /y c:\windows\tempor~1
deltree /y c:\windows\temp
deltree /y c:\windows\tmp
deltree /y c:\windows\ff*.tmp
deltree /y c:\windows\history
deltree /y c:\windows\cookies
deltree /y c:\windows\recent
deltree /y c:\windows\spool\printers
deltree c:\windows\temp\*.* /y
del c:\WIN386.SWP
Del /F /Q %APPDATA%\Microsoft\Windows\Recent\*
Del /F /Q %APPDATA%\Microsoft\Windows\Recent\AutomaticDestinations\*
Del /F /Q %APPDATA%\Microsoft\Windows\Recent\CustomDestinations\*
reg delete HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\RunMRU /VA /F
reg delete HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\TypedPaths /VA /F
reg delete "HKEY_CURRENT_USER\Software\Microsoft\Terminal Server Client\Default" /va /f
reg delete "HKEY_CURRENT_USER\Software\Microsoft\Terminal Server Client\Servers" /f
reg add "HKEY_CURRENT_USER\Software\Microsoft\Terminal Server Client\Servers"
cd %userprofile%\documents\
attrib Default.rdp -s -h
del Default.rdp
echo off
set DataDir=C:\Users\%USERNAME%\AppData\Local\Microsoft\Intern~1\
del /q /s /f "%DataDir%"
rd /s /q "%DataDir%"
set History=C:\Users\%USERNAME%\AppData\Local\Microsoft\Windows\History
del /q /s /f "%History%"
rd /s /q "%History%"
set IETemp=C:\Users\%USERNAME%\AppData\Local\Microsoft\Windows\Tempor~1
del /q /s /f "%IETemp%"
rd /s /q "%IETemp%"
set Cookies=C:\Users\%USERNAME%\AppData\Roaming\Microsoft\Windows\Cookies
del /q /s /f "%Cookies%"
rd /s /q "%Cookies%"
C:\bin\regdelete.exe HKEY_CURRENT_USER "Software\Microsoft\Internet Explorer\TypedURLs"
echo off | clip
echo y | del %1\*.*
echo Network Connetion.....PURGING!!!
TIMEOUT /T 10
ipconfig /release
ipconfig /renew
ipconfig /flushdns
ipconfig /registerdns
echo Network Connection.....TESTING!!!
TIMEOUT /T 15
@echo off
Color 0E
cd\
ping google.com -n 10
echo Cleaning of junk files is.....FINISHED!!!
TIMEOUT /T 10
shutdown -r -f -t 30 /C "Applying Changes"
ECHO.
ECHO Removing CleanUp utility...
REM Delete self on Exit
cmd /k DEL "%~f0"