Hey man kann die Datenträgerbereinigung auch mit Powershell nutzen.

Dann das Script einfach noch per Task hinterlegen und in regelmäßigen Abständen ausführen.

So gehts...:

View source
  1.  
  2.  
  3.  
  4. # variable for firewall profiles
  5.  
  6.  
  7. $tag = "StateFlags"
  8.  
  9.  
  10. $counter = "0001"
  11.  
  12.  
  13. $stateflags = $($tag) + $($counter)
  14.  
  15.  
  16. $options"Active Setup Temp Folders","BranchCache","Downloaded Program Files","Internet Cache Files","Old ChkDsk Files","Previous Installations","Recycle Bin","RetailDemo Offline Content","Service Pack Cleanup","Setup Log Files","System error memory dump files","System error minidump files","Temporary Files","Temporary Setup Files","Thumbnail Cache","Update Cleanup","Upgrade Discarded Files","User file versions","Windows Defender","Windows Error Reporting Archive Files","Windows Error Reporting Queue Files","Windows Error Reporting System Archive Files","Windows Error Reporting System Queue Files","Windows Error Reporting Temp Files","Windows ESD installation files","Windows Upgrade Log Files"
  17.  
  18.  
  19. #----------------------------------------------------------------------------------
  20.  
  21.  
  22. # global error handling
  23.  
  24.  
  25. $ErrorActionPreference = "SilentlyContinue";
  26.  
  27.  
  28. $error.Clear();
  29.  
  30.  
  31. # only show defined error messages
  32.  
  33.  
  34. function errorhandling($message = $error[0].Exception.Message, $Code)
  35.  
  36.  
  37. {
  38.  
  39.  
  40.        # write execution Log to %tempp%
  41.  
  42.  
  43.        $error | out-file -PSPath $env:temp\PowerShell_Execution_Error.log -Append;
  44.  
  45.  
  46.        # on error just show content of Exeption.Message
  47.  
  48.  
  49.        $message = "Error executing section $($code): " + $($message)
  50.  
  51.  
  52.        write-warning $($message)
  53.  
  54.  
  55.        # stop script on error
  56.  
  57.  
  58.        read-host
  59.  
  60.  
  61.        exit $code;
  62.  
  63.  
  64. }
  65.  
  66.  
  67. #----------------------------------------------------------------------------------
  68.  
  69.  
  70. # check if script runs in admin context
  71.  
  72.  
  73. if (-NOT ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole(`
  74.  
  75.  
  76.        [Security.Principal.WindowsBuiltInRole] "Administrator"))
  77.  
  78.  
  79. {
  80.  
  81.  
  82.     Write-Warning "You have to run this Script with elevated privileges to delete all files"
  83.  
  84.  
  85.     Write-Host "Press any key to exit the script"
  86.  
  87.  
  88.     read-host
  89.  
  90.  
  91.        exit 0;
  92.  
  93.  
  94. }
  95.  
  96.  
  97. #----------------------------------------------------------------------------------
  98.  
  99.  
  100. # set cleanup registiry keys
  101.  
  102.  
  103.  
  104.  
  105.  
  106. # reset options if values are changed
  107.  
  108.  
  109. $rootpath = "HKLM:\Software\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\"  
  110.  
  111.  
  112. $keys = Get-ChildItem -path $rootpath -Recurse | Get-ItemProperty -name $stateflags -ErrorAction SilentlyContinue
  113.  
  114.  
  115.  
  116.  
  117.  
  118. foreach($key in $keys.pspath)
  119.  
  120.  
  121. {
  122.  
  123.  
  124.       
  125.  
  126.  
  127.        Set-ItemProperty -path $key -name $stateflags -value "0" -Type Dword
  128.  
  129.  
  130.  
  131.  
  132.  
  133. }
  134.  
  135.  
  136.  
  137.  
  138.  
  139. #define options
  140.  
  141.  
  142. foreach($option in $options)
  143.  
  144.  
  145. {
  146.  
  147.  
  148.        $path = $rootpath + $option
  149.  
  150.  
  151.        Set-ItemProperty -path $path -name $stateflags -value "2" -Type Dword
  152.  
  153.  
  154.  
  155.  
  156.  
  157. }
  158.  
  159.  
  160. #----------------------------------------------------------------------------------
  161.  
  162.  
  163. # define cleanup variables
  164.  
  165.  
  166. $error.Clear();
  167.  
  168.  
  169. $prog = "$env:SystemRoot\System32\cleanmgr.exe"
  170.  
  171.  
  172. $param = "/sagerun:$counter /setup"
  173.  
  174.  
  175. # start cleanup process
  176.  
  177.  
  178. Invoke-Expression "$prog $param"
  179.  
  180.  
  181.       
  182.  
  183.  
  184.        # errorhandling
  185.  
  186.  
  187.        if ($error.Count -gt 0)
  188.  
  189.  
  190.        {
  191.  
  192.  
  193.              errorhandling -code 1;
  194.  
  195.  
  196.  
  197.        }
  198.  
  199.  
  200.  
  201.