Help with possible Batch Script Logic Error

Asked

Viewed 10 times

-1

Friends, good morning!

Could you help me with the batch script below? I think I have some logic error, because it goes into an infinite loop and never closes.

In summary the script is programmed by blocks, and it aims to scan all directories of local OS users, log into directories in these profiles and run cash cleaning of users as well as general OS cashs cleaning.

dir /b C:\Users > C:\PPADRAO\Scripts\LogCleanCash.txt
set /p UserToClean=<C:\PPADRAO\Scripts\LogCleanCash.txt
set PathOfUser="C:\Users\%UserToClean%"
echo FIM >> C:\PPADRAO\Scripts\LogCleanCash.txt

:Valida_User

if !UserToClean!==="FIM" (
    GOTO :Finaliza
) else (
    GOTO :CashClean
)

:CashClean

if !UserToClean!==Public (
    GOTO :CleanLine 
)
    
if !UserToClean!==Saturno (
    GOTO :CleanLine
)

erase "%PathOfUser%\AppData\Local\Temp\*.*" /f /s /q
for /D %%i in ("%PathOfUser%\AppData\Local\Temp\*.*") do RD /S /Q "%%i"

erase "%SystemRoot%\TEMP\*.*" /f /s /q
for /D %%i in ("%SystemRoot%\TEMP\*") do RD /S /Q "%%i"

erase "%PathOfUser%\AppData\Local\Google\Chrome\User Data\*.*" /f /s /q
for /D %%i in ("%PathOfUser%\AppData\Local\Google\Chrome\User Data\*") do RD /S /Q "%%i"

erase "%PathOfUser%\AppData\Local\Mozilla\Firefox\Profiles\*.*" /f /s /q
for /D %%i in ("%PathOfUser%\AppData\Local\Mozilla\Firefox\Profiles\*") do RD /S /Q "%%i"

erase "%PathOfUser%\AppData\Local\Microsoft\Edge\User Data\Default\Cache\*.*" /f /s /q
for /D %%i in ("%PathOfUser%\AppData\Local\Microsoft\Edge\User Data\Default\Cache\*") do RD /S /Q "%%i"

erase "%PathOfUser%\AppData\Local\Microsoft\Edge\User Data\Default\Code Cache\*.*" /f /s /q
for /D %%i in ("%PathOfUser%\AppData\Local\Microsoft\Edge\User Data\Default\Code Cache\*") do RD /S /Q "%%i"

erase "%PathOfUser%\AppData\Local\Microsoft\Windows\Caches\*.*" /f /s /q
for /D %%i in ("%PathOfUser%\AppData\Local\Microsoft\Windows\Caches\*") do RD /S /Q "%%i"

erase "%PathOfUser%\AppData\Local\Microsoft\Windows\IECompatCache\*.*" /f /s /q
for /D %%i in ("%PathOfUser%\AppData\Local\Microsoft\Windows\IECompatCache\*") do RD /S /Q "%%i"

erase "%PathOfUser%\AppData\Local\Microsoft\Windows\IECompatUaCache\*.*" /f /s /q
for /D %%i in ("%PathOfUser%\AppData\Local\Microsoft\Windows\IECompatUaCache\*") do RD /S /Q "%%i"

erase "%PathOfUser%\AppData\Local\Microsoft\Windows\IEDownloadHistory\*.*" /f /s /q
for /D %%i in ("%PathOfUser%\AppData\Local\Microsoft\Windows\IEDownloadHistory\*") do RD /S /Q "%%i"

erase "%PathOfUser%\AppData\Local\Microsoft\Windows\INetCache\*.*" /f /s /q
for /D %%i in ("%PathOfUser%\AppData\Local\Microsoft\Windows\INetCache\*") do RD /S /Q "%%i"

erase "%PathOfUser%\AppData\Local\Microsoft\Windows\INetCookies\*.*" /f /s /q
for /D %%i in ("%PathOfUser%\AppData\Local\Microsoft\Windows\INetCookies\*") do RD /S /Q "%%i"

erase "%PathOfUser%\AppData\Local\Microsoft\Windows\WebCache\*.*" /f /s /q
for /D %%i in ("%PathOfUser%\AppData\Local\Microsoft\Windows\WebCache\*") do RD /S /Q "%%i"

GOTO :CleanLine

:CleanLine

@echo off&cls
set $NoLigne=1
if exist ## del ##

setlocal enabledelayedexpansion

for %%a in (LogCleanCash.txt) do (echo # traitement de : %%a
    set $c=1
    for /f "tokens=1* delims=]" %%b in ('type "%%a" ^| find /V /N ""') do (
        if not !$c! equ !$NoLigne! (if "%%c"=="" (echo.>>##) else (echo %%c>>##))
        set /a $c+=1)
        move ## "%%a">nul)
GOTO :Valida_User
endlocal

:Finaliza
del C:\PPADRAO\Scripts\LogCleanCash.txt
exit

  • Please clarify your problem or provide additional details in order to highlight exactly what you need. The way it’s written these days it’s hard to tell exactly what you’re asking.

  • I need the scrip to clean up cash in the user directories, skip some users who are standard system users, and finish executing the code. Users to be cleaned are identified in the Usertoclean variable through the first line of Logcleancash.txt, which in turn cleans the first line with the "Cleanline" function so that the execution is not always in the same user, generating an infinite loop.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.