script question

Home Forums Scripting General Scripting script question

Viewing 1 post (of 1 total)
  • Author
    Posts
  • Avatar
    APOC
    Member
    #156163

    I use this script post]236998[/post to clean history, coockies and cache(Temporary Internet Files) for all users AND it should also clean de temp dir BUT there seems to be something wrong.

    2 things get mixed up I think, the %temp% variable (= D:TEMP in my environment) AND de users temp dir in the %userprofile%

    I ran the script on a WinXP PRO SP3 workstation

    Rems;236998 wrote:
    The batch sample I posted earlier can be used for the user logon script (or user logoff script). It works also for non-local admins.

    If you would prefere using a scheduled task, and run the job as an Administrator that cleans temp files of all the users profiles (incl. index.dat files!), try this:

    Code:
    :: Works on Win XP -and- on Win 7


    @echo
    off

    Set “RegKey=HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindows NTCurrentVersionProfileList”
    set “regkey2=HKCUSoftwareMicrosoftWindowsCurrentVersionExplorershell folders”

    call:getspecialfolders “Cache, History, Cookies”

    For /f “tokens=*” %%? in (
    ‘Reg.exe QUERY “%RegKey%” ^|findstr /ric:”S-1-5-21-[0-9]*-[0-9]*-[0-9]*-[0-9]*$”‘
    ) do (
    For /f “tokens=2,*” %%A in (
    ‘Reg.exe QUERY “%%?” /v ProfileImagePath ^|find /i “ProfileImagePath”‘
    ) do call:Go %%B
    )

    start “”/w “%windir%system32RunDll32.exe” InetCpl.cpl,ClearMyTracksByProcess 255

    :end ***

    goto:EOF
    :Go
    call Set “Target=%*”
    If EXIST “%Target%” call:Clear “%Target%”
    exit /b 0

    :Clear
    rem echo.&echo.%~1%$$Cache%Content.IE5
    pushD “%~1%$$Cache%Content.IE5” &&(
    rmdir /s /q .
    popD)2>nul

    rem echo.&echo.%~1%$$History%History.IE5
    pushD “%~1%$$History%History.IE5” &&(
    rmdir /s /q .
    popD)2>nul

    rem echo.&echo.%~1%$$History%
    pushD “%~1%$$History%” &&(
    rmdir /s /q .
    popD)2>nul

    rem echo.&echo.%~1%$$Cookies%
    pushD “%~1%$$Cookies%” &&(
    rmdir /s /q .
    popD)2>nul

    rem echo.&echo.%~1%$$Cache%
    pushD “%~1%$$Cache%” &&(
    rmdir /s /q .
    popD)2>nul

    rem echo.&echo.%~1%$$temp%
    pushD “%~1%$$temp%” &&(
    rmdir /s /q .
    popD)2>nul
    exit /b 0

    :getspecialfolders
    Set “FoldersToClear=%~1”

    For %%* in (%FoldersToClear%) Do (
    For /f “tokens=2,*” %%A in (
    ‘reg.exe query “%regkey2%” /v %%* ^|find /i “%%~*”‘
    ) do Call:sf1 “%%~B” “%%~*”
    )
    Call:sf2 “%temp%” “temp” “%userprofile%”
    exit /b 0

    :sf1
    Call set “sf=%~1”
    Call set “$$%~2=%%sf:%userprofile%=%%”
    exit /b 0

    :sf2
    Call set “sf=%~1”
    call Set “usr=%~dpns3”
    Call set “$$%~2=%%sf:%usr%=%%”
    exit /b 0

    /Rems

    BUT somehow I can’t get the last “temp part” to function so it cleans the %temp% (D:Temp in my environment) and to also find al “temp dir’s” in the %userprofile%.

    ie. this for instance does work for %temp% :

    Quote:
    PushD “%Temp%” && (
    ATTRIB -S -H -R -A /D /S & (
    For /f “Tokens=*” %%* in (‘dir “%Temp%” /B’) Do (
    RD “%Temp%%%*” /S /Q || Del /F /S /Q “%Temp%%%*”))&PopD)2>c:test0b_TEMP.txt

    and this ie. work for the “user(s) temp” :

    Quote:
    ::Set Search directory to “Documents and Settings” folder
    (Set Target=%AllUsersProfile:~0,-10%)

    title,Finding the Temp subfolders in %Target%&COLOR 9E

    If EXIST “%Target%”,(
    For /f “Tokens=*” %%* in (‘dir “%Target%” /B’) Do (
    cd/D “%target%%%*Local SettingsTemp” && (
    ATTRIB -S -H -R -A /D /S >nul & (
    For /f “Tokens=*” %%* in (‘dir /B’) Do (
    RD “%%*” /S /Q ||Del /F “%%*” )))>nul)
    )

    I hope some one can help me out fixing the script, I think it’s in the :sf2 and/or in combination with the %temp% part.
    Somehow 2 things get mixed-up now (“users temp” en “environment temp”).

Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.