Announcement

Collapse
No announcement yet.

script question

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • script question

    I use this script [https://www.petri.com/forums/node/386616] 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

    Originally posted by Rems View Post
    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_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList"
    set "regkey2=HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\shell 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%\system32\RunDll32.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% :
    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" :
    ::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 Settings\Temp" && (
    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").
    Last edited by Rems; 13th September 2011, 14:30. Reason: added a link to the script

  • #2
    (wrong combination in parameters?)

    The result of that last "temp-part" is on my workstation is:
    i.e. C:\Documents and Settings\admin-lksvdd\D:\TEMP

    As you can see it makes a wrong combination of things and I can't exactly locate where the problem is.
    It must have something to do with:
    Call set "$$%~2=%%sf:%usr%\=%%"
    call Set "usr=%~dpns3"
    Call:sf2 "%temp%" "temp" "%userprofile%"

    With kind regards,
    Tim

    PS.
    Default windows temp used and it does work again:
    %UserProfile%\Local Settings\Temp (for currentuser) and
    %SystemRoot%\Temp (system variable).
    Now how to fix the script so it will still work when none windows defaults are used... that's when things go wrong
    Last edited by APOC; 9th September 2011, 11:47. Reason: added windows default path for "temp"

    Comment


    • #3
      solution?

      This seems to be a work-around:

      instead of
      Code:
      ECHO.&echo.%~1\%$$temp%
       pushD "%~1\%$$temp%" &&(
       rmdir /S /Q .
       popD)2>C:\test1_Temp.txt

      use

      Code:
      IF "%$$temp%"=="%$$temp:*:=%" (SET "tmppath=%~1\%$$temp%") ELSE SET "tmppath=%$$temp%"
       ECHO.&echo.%tmppath%
       pushD "%tmppath%" &&(
       rmdir /S /Q .
       popD)2>C:\test1_Temp.txt
      I'm not sure if it's the best way/methode?

      Credits go out to: Andriy M (for pointing out the above solution/work-around)

      Comment


      • #4
        Re: Script to delete Windows temp files via Scheduled Tasks

        not working 100% yet and not sure why

        There still seems something not going 100% in the script with the "temp"-part, I changed my default temp settings in windows to the default paths for testing purposes and I get these 3 error's:
        (http) img199.imageshack.us/img199/9127/errorif.jpg (copy/past for screenshot)

        script run with the windows default temp-path's:
        [user] %UserProfile%\Local Settings\Temp and [system] %SystemRoot%\Temp

        I'm not sure why I get these error's, when I set both temp parameters to D:\TEMP, I get 3 times the same sort of error but than for D:\TEMP instead of available/active users \local settings\Temp. Perhaps the problem is in locals~1??? (The temp-directories do get cleaned though, but why does it say it can't find the path?)

        Code:
        :: Works on Win XP  -and-  on Win 7
        
        @ECHO OFF
        SETLOCAL ENABLEDELAYEDEXPANSION
        
        SET "RegKey=HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList"
        sET "regkey2=HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\shell 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
        )
        REM ***Find UserProfile-path for ALL possible users and clean Cache, History, Cookies.
        
        start "browsergeschiedenis"/w "%windir%\system32\RunDll32.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>C:\test1c_TEMP_Content.ie5.txt
        
        REM echo.&echo.%~1\%$$History%\History.IE5
        REM    pushD "%~1\%$$History%\History.IE5" &&(
        REM    rmdir /S /Q .
        REM    popD)2>C:\test1c_History_ie5.txt
        
        REM echo.&echo.%~1\%$$History%
           pushD "%~1\%$$History%" &&(
           rmdir /S /Q .
           popD)2>C:\test1c_History.txt
        
        REM echo.&echo.%~1\%$$Cookies%
           pushD "%~1\%$$Cookies%" &&(
           rmdir /S /Q .
           popD)2>C:\test1c_Cookies.txt
        
        REM echo.&echo.%~1\%$$Cache%
           pushD "%~1\%$$Cache%" &&(
           rmdir /S /Q .
           popD)2>C:\test1c_TEMP_ie.txt
        
        REM ***Original lines:
        REM ECHO.&echo.%~1\%$$temp%
        REM    pushD "%~1\%$$temp%" &&(
        REM    rmdir /S /Q .
        REM    popD)2>C:\test1c_Temp.txt
        REM ***Removed/stopped while giving problems when using non-default temp.path locations.
        
        IF "%$$temp%"=="%$$temp:*:=%" (SET "tmppath=%~1\%$$temp%") ELSE SET "tmppath=%$$temp%"
        REM ECHO.&echo.%tmppath%
           pushD "%tmppath%" &&(
           ATTRIB -S -H -R -A /D /S & (
           rmdir /S /Q . || Del /F /S /Q .
           )&popD)2>C:\test1c_Temp.txt
        REM evt. rmdir /S /Q . (excl. || Del /F /S /Q .) because it seems pretty useless...
        
        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
        REM ***Check: "shell folders" for Cache, History, Cookies (and Temp?) for CurrentUser ONLY?
        
        :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
        PS. Problem does NOT seem to occur when the directories aren't empty (got files in em), so the above error's/messages only occur when the directories are empty so it seems.
        How come / Why? Can this be prevented or else hide these messages? (that there wasn't anything found)
        Last edited by APOC; 12th September 2011, 11:26. Reason: Added: CODE and PS.

        Comment


        • #5
          Re: script question

          Originally posted by APOC View Post
          I use this script [https://www.petri.com/forums/node/386616] 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%

          <...>
          PS.
          Default windows temp used and it does work again:
          %UserProfile%\Local Settings\Temp (for currentuser) and
          %SystemRoot%\Temp (system variable).
          Now how to fix the script so it will still work when none windows defaults are used... that's when things go wrong.
          The script retrieves the location of each of the special folders of the account that is running the script, it uses the account as a reference. Then it also assumes each of these folders are somewhere in the users profile path.

          The script expects that for every user on the computer the same relative path to each of these special folders are used.
          It is not possible the retreive the actual paths for each user separately. Therefore in your case you have makes changes to the script and hard code the actual (relative)-path in the script.
          In the script a subroutine (label sf2) is getting the relative path of the temp folder of the current user. You can delete the code from that section and just enter the default relative path to the users temp folder there:
          Code:
          
          :sf2
          Set "$$temp=\LOCALS~1\Temp"
          exit /b 0
          

          But when the temp folder would not be in the user's profile path (of all the reguler users) then enter the fullpath in the above subroutine replace the username in the path with a * sign.
          The "REM ***Original lines: <...> " section should now be replaced with:
          Code:
             Set "tmpdir="
             for /f "tokens=*" %%* in (
             'echo.%~1') do call set "tmpdir=%%$$temp:\*=\%%~n*%%"
          
          ECHO.&echo.%tmpdir%
             pushD "%tmpdir%" &&(
             rmdir /S /Q .
             popD)2>C:\test1c_Temp.txt
          /Rems

          This posting is provided "AS IS" with no warranties, and confers no rights.

          __________________

          ** Remember to give credit where credit's due **
          and leave Reputation Points for meaningful posts

          Comment


          • #6
            Re: script question

            changed script:
            Code:
            :: Works on Win XP  -and-  on Win 7
            
            @ECHO OFF
            SETLOCAL ENABLEDELAYEDEXPANSION
            
            SET "RegKey=HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList"
            sET "regkey2=HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\shell folders"
            
            ECHO *** DEL.Temp Started %date% %time% *** >> C:\test1c_TEMP_Content.ie5.txt
            ECHO *** DEL.Temp Started %date% %time% *** >> C:\test1c_History.txt
            ECHO *** DEL.Temp Started %date% %time% *** >> C:\test1c_Cookies.txt
            ECHO *** DEL.Temp Started %date% %time% *** >> C:\test1c_TEMP_ie.txt
            ECHO *** DEL.Temp Started %date% %time% *** >> C:\test1c_Temp.txt
            
            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
            )
            REM ***Find UserProfile-path for ALL possible users and clean Cache, History, Cookies.
            
            start "browsergeschiedenis"/w "%windir%\system32\RunDll32.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>>C:\test1c_TEMP_Content.ie5.txt
            
            REM echo.&echo.%~1\%$$History%\History.IE5
            REM    pushD "%~1\%$$History%\History.IE5" &&(
            REM    rmdir /S /Q .
            REM    popD)2>C:\test1c_History_ie5.txt
            
            REM echo.&echo.%~1\%$$History%
               pushD "%~1\%$$History%" &&(
               rmdir /S /Q .
               popD)2>>C:\test1c_History.txt
            
            REM echo.&echo.%~1\%$$Cookies%
               pushD "%~1\%$$Cookies%" &&(
               rmdir /S /Q .
               popD)2>>C:\test1c_Cookies.txt
            
            REM echo.&echo.%~1\%$$Cache%
               pushD "%~1\%$$Cache%" &&(
               rmdir /S /Q .
               popD)2>>C:\test1c_TEMP_ie.txt
            
            
            REM ***ADDED EXTRA LINES (REMS)*** START ***
               Set "tmpdir="
               for /f "tokens=*" %%* in (
               'echo.%~1') do call set "tmpdir=%%$$temp:\*=\%%~n*%%"
            
            ECHO.&echo.%tmpdir%
               pushD "%tmpdir%" &&(
               rmdir /S /Q .
               popD)2>>C:\test1c_Temp.txt
            REM ***ADDED EXTRA LINES (REMS)*** END ***
            
            
            IF "%$$temp%"=="%$$temp:*:=%" (SET "tmppath=%~1\%$$temp%") ELSE SET "tmppath=%$$temp%"
            REM ECHO.&echo.%tmppath%
               pushD "%tmppath%" &&(
               ATTRIB -S -H -R -A /D /S & (
               rmdir /S /Q .
               )&popD)2>>C:\test1c_Temp.txt
            REM evt. rmdir /S /Q . || Del /F /S /Q .) kinda overkill, but might Force some ReadOnly files...
            
            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
            REM ***Check: "shell folders" for Cache, History, Cookies (and Temp?) for CurrentUser ONLY?
            
            :sf1
               Call set "sf=%~1"
               Call set "$$%~2=%%sf:%userprofile%\=%%"
            exit /b 0
            
            REM Changed to REMS advice *** see below ***
            REM :sf2
            REM    Call set "sf=%~1"
            REM    call Set "usr=%~dpns3"
            REM    Call set "$$%~2=%%sf:%usr%\=%%"
            REM exit /b 0
            REM Changed to REMS advice *** see below, new :sf2 ***
            
            :sf2
            Set "$$temp=\LOCALS~1\Temp"
            exit /b 0
            This does clean the user temp directories (in local settings) BUT not the changed/non-default windows temp-path directory.
            ie. [user] %UserProfile%\Local Settings\Temp and [system] %SystemRoot%\Temp (system - advanced - environment variables).
            => on some workstations D:\TEMP is used instead of the above mentioned windows defaults.

            Without your additional code the script does clean the above mentioned temp-directories as stated in user/system environment temp-path BUT ignores the user temp path's in "local settings".
            With your additional coding it does exactly the opposite

            It should delete both possible options, so for the userprofiles temp (local settings) AND if the temp-path is changed in the environment variables (ie. D:\TEMP) is should delete this one.
            .
            .
            .
            SO when used with ONLY my changes it does clean what's stated in "system - advanced - environment variables"
            ie. D:\TEMP or the windows "default" temp-path's: [user] %UserProfile%\Local Settings\Temp and [system] %SystemRoot%\Temp (system - advanced - environment variables).
            Code:
            REM ***Original lines:
            REM ECHO.&echo.%~1\%$$temp%
            REM    pushD "%~1\%$$temp%" &&(
            REM    rmdir /S /Q .
            REM    popD)2>C:\test1c_Temp.txt
            REM ***Removed/stopped while giving problems when using non-default temp.path locations.
            
            
            IF "%$$temp%"=="%$$temp:*:=%" (SET "tmppath=%~1\%$$temp%") ELSE SET "tmppath=%$$temp%"
            REM ECHO.&echo.%tmppath%
               pushD "%tmppath%" &&(
               ATTRIB -S -H -R -A /D /S & (
               rmdir /S /Q .
               )&popD)2>>C:\test1c_Temp.txt
            REM evt. rmdir /S /Q . || Del /F /S /Q .) kinda overkill, but might Force some ReadOnly files...
            
            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
            REM ***Check: "shell folders" for Cache, History, Cookies (and Temp?) for CurrentUser ONLY?
            
            :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
            AND with your additional/changed lines only the user(profile) temp directories (user\local files\temp) get cleaned at all times.
            Code:
            REM ***ADDED EXTRA LINES (REMS)*** START ***
               Set "tmpdir="
               for /f "tokens=*" %%* in (
               'echo.%~1') do call set "tmpdir=%%$$temp:\*=\%%~n*%%"
            
            ECHO.&echo.%tmpdir%
               pushD "%tmpdir%" &&(
               rmdir /S /Q .
               popD)2>>C:\test1c_Temp.txt
            REM ***ADDED EXTRA LINES (REMS)*** END ***
            
            
            IF "%$$temp%"=="%$$temp:*:=%" (SET "tmppath=%~1\%$$temp%") ELSE SET "tmppath=%$$temp%"
            REM ECHO.&echo.%tmppath%
               pushD "%tmppath%" &&(
               ATTRIB -S -H -R -A /D /S & (
               rmdir /S /Q .
               )&popD)2>>C:\test1c_Temp.txt
            REM evt. rmdir /S /Q . || Del /F /S /Q .) kinda overkill, but might Force some ReadOnly files...
            
            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
            REM ***Check: "shell folders" for Cache, History, Cookies (and Temp?) for CurrentUser ONLY?
            
            :sf1
               Call set "sf=%~1"
               Call set "$$%~2=%%sf:%userprofile%\=%%"
            exit /b 0
            
            REM Changed to REMS advice *** NEW :sf2 ***
            :sf2
            Set "$$temp=\LOCALS~1\Temp"
            exit /b 0
            Now to check for both possibilities and clean (delete) these completely, can't seem to find the right solution
            Last edited by APOC; 16th September 2011, 10:31. Reason: added REMS comments in code

            Comment


            • #7
              Re: script question

              The script does NOT try to clean the system temp folder at all -> that is intentionally because you should never just emptying the system temp folder.
              The script only clears the cache folders that are in the profilepath of the reguler user's. That is what it does.

              In the last addjustment the default temp folder location in the user profile is now hard coded in the script and provided a relative path. The script does not clean any other temp folder unless you hard code the path of any alternative folders as wel.

              I gues it would be better when hardcoding the (relative or absolute) path to use the "long" folder name, therefore change
              Set "$$temp=\LOCALS~1\Temp"
              to
              Set "$$temp=Local Settings\Temp"
              (btw the first slashback should be out).


              In the script ou addded:

              REM ***ADDED EXTRA LINES (REMS)*** START ***
              Set "tmpdir="
              for /f "tokens=*" %%* in (
              'echo.%~1') do call set "tmpdir=%%$$temp:\*=\%%~n*%%"

              ECHO.&echo.%tmpdir%
              pushD "%tmpdir%" &&(
              rmdir /S /Q .
              popD)2>>C:\test1c_Temp.txt
              REM ***ADDED EXTRA LINES (REMS)*** END ***


              But that should be used only when you have entered an asterisk for the username in an absolute path to the temp folder that you would have hard coded. With this code sample the asterisk wil be replaced by the username (any extensions to the user's folder name are stript off to get the account name that the script use for the replacement).
              It is not the case in the last script becasue a relative path is entered, therfore instead use only the original code from the script in the part where the temp folder is being emtyed:

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

              You can add the attrib statements before the rmdir commands.

              Next you could add more lines if you like for emtying additional folders.
              e.d.
              pushD D:\temp" &&(
              rmdir /s /q .
              popD)2>nul

              If d:\temp does not exist on the computer the script does not attempt clearing an other folder that is currently the active folder, because of the double && used in the statement.


              /Rems
              Last edited by Rems; 16th September 2011, 11:55.

              This posting is provided "AS IS" with no warranties, and confers no rights.

              __________________

              ** Remember to give credit where credit's due **
              and leave Reputation Points for meaningful posts

              Comment


              • #8
                Re: script question

                Okay, so if I understand it wel:
                I can use the original code and ONLY change :sf2 into Set "$$temp=Local Settings\Temp" and that should always pull the trick?
                (and if I wan't to clean the system temp, I should do this with additional lines for emptying additional folder)

                By the way: I guess this line has some unnecessary parameters now? Call:sf2 "%temp%" "temp" "%userprofile%"

                Why was the original code better? I hope to learn and understand it more:
                Code:
                :sf2
                   Call set "sf=%~1"
                   call Set "usr=%~dpns3"
                   Call set "$$%~2=%%sf:%usr%\=%%"
                Like discussed the script went wrong here on some workstation which had the system environment changed from the windows defaults for the temp-path's. (not set to userprofile temp)
                Last edited by APOC; 16th September 2011, 15:30. Reason: added PS.

                Comment


                • #9
                  Re: script question

                  Dunno if it helps but personally do I think: why making harder then needed...

                  Clear IE cache from this source:
                  History, RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 1
                  Cookies, RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 2
                  Temp Internet Files, RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 8

                  Clearing temp folder in user profile
                  del /f /q "%userprofile%\local settings\temp\*.*"

                  And other regular temp folder
                  DEL /F /S /Q %TEMP%

                  wrap that around with If exist and such, and I think you're basically done...

                  (oh untested though. I'm currently on my mac...)
                  Last edited by Dumber; 16th September 2011, 16:15.
                  Marcel
                  Technical Consultant
                  Netherlands
                  http://www.phetios.com
                  http://blog.nessus.nl

                  MCITP(EA, SA), MCSA/E 2003:Security, CCNA, SNAF, DCUCI, CCSA/E/E+ (R60), VCP4/5, NCDA, NCIE - SAN, NCIE - BR, EMCPE
                  "No matter how secure, there is always the human factor."

                  "Enjoy life today, tomorrow may never come."
                  "If you're going through hell, keep going. ~Winston Churchill"

                  Comment


                  • #10
                    Re: script question

                    (nl) inderdaad mogelijk, dank, script van Rem's ruimt overigens nog wel ook extra temp files uit ander gebruiksprofielen (nl)

                    True, should also work... (Rem's script does clean a little more)


                    I was curious though, if I use the original code by Rem's and only change
                    :sf2 from
                    Code:
                    :sf2
                       Call set "sf=%~1"
                       Call set "usr=%~dpns3"
                       Call set "$$%~2=%%sf:%usr%\=%%"
                       exit /b 0
                    into
                    Code:
                    :sf2
                       Set "$$temp=Local Settings\Temp"
                       exit /b 0
                    Hasn't got this line a little unnecessary parameters now ???
                    =>
                    Call:sf2 "%temp%" "temp" "%userprofile%" (used in :getspecialfolders)

                    Comment


                    • #11
                      Re: script question

                      due to busyness, not completely done yet, I was curious if someone could tell me if the script doesn't have some unnecessary parameters in it, like stated in the reply above. (20th September 2011 09:23)

                      => Changed :sf2 and Changed Call:sf2 etc.

                      It seems to me that the "%temp%" "temp" "%userprofile%" part isn't used any more, right? (or wrong?)

                      Comment

                      Working...
                      X