I am curious how the developers of CCleaner have accomplished an aspect of their product. How does CCleaner clean the thumbnail cache on Windows? I'm writing something and part of it requires the thumbnail cache to be deleted. Trouble is, depending on Windows settings, the cache is almost always locked/in use by the Explorer process. I can not for the life of me figure out how to unlock these files to delete them. I've tried the following:
Always set the "show icons, not thumbnails" setting via registry
- Close and restart explorer (I think this would work, but halts script--Python)
- Send a WM_CHANGESETTING message to all Windows
- Close all open handles to the files
Does CCleaner not delete the the in-use files? Disk Cleanup deletes them too, so it must be able to be done.
You probably need to run your script (or the program that runs the script) with administrator privileges if it's for instance Windows 10.
--------
As to what CCleaner does "under the hood," it's highly unlikely they'll give such details since it's closed source even though they offer a freeware version -- but that doesn't mean free software or open source software.
It will probably depend what programming language you are writing your 'something' in. (I'm not familiar with Python).
Maybe your best bet would be to ask on a forum dedicated to Python?
Someone else may have figured it out.
The only way I have found to do it in a batch is to kill File Explorer, delete the Thumbnail cache, restart File Explorer and let it rebuild the cache.
You have to do the same and close FE if/when you want to rebuild the icon cache.
I've had similar problems trying to get the recycle bin icon to refresh without having to close FE and refreshing the whole icon cache.
You can refresh the bin icon when you empty the bin from a Powershell script. (but that then throws up a UAC warning so not what I want).
You can use the following in Powershell to remove the thumbnail db so that Windows will rebuild it (you'll need to be in an admin account).
Maybe you could call Powershell from Python?
PS. This won't work if you have an Explorer window open so that the db is in use, you'll get an error message.
<div class="ipsQuote_contents">
<p>
You probably need to run your script (or the program that runs the script) with administrator privileges if it's for instance Windows 10.
</p>
<p>
--------
</p>
<p>
As to what CCleaner does "under the hood," it's highly unlikely they'll give such details since <strong>it's <a href="https://en.wikipedia.org/wiki/Proprietary_software" rel="external nofollow">closed source</a></strong> even though they offer a freeware version -- but that doesn't mean <a href="https://en.wikipedia.org/wiki/Free_software" rel="external nofollow">free software</a> or <a href="https://en.wikipedia.org/wiki/Open-source_software" rel="external nofollow">open source software</a>.
</p>
</div>
I know it's closed source, but it doesn't hurt to ask.
2 hours ago, nukecad said:
<div class="ipsQuote_contents">
<p>
It will probably depend what programming language you are writing your 'something' in. (I'm not familiar with Python).
</p>
<p>
Maybe your best bet would be to ask on a forum dedicated to Python?
Someone else may have figured it out.
</p>
<p>
The only way I have found to do it in a batch is to kill File Explorer, delete the Thumbnail cache, restart File Explorer and let it rebuild the cache.
You have to do the same and close FE if/when you want to rebuild the icon cache.
</p>
<p>
I've had similar problems trying to get the recycle bin icon to refresh without having to close FE and refreshing the whole icon cache.
You can refresh the bin icon when you empty the bin from a Powershell script. (but that then throws up a UAC warning so not what I want).
</p>
<p>
You can use the following in Powershell to remove the thumbnail db so that Windows will rebuild it (you'll need to be in an admin account).
Maybe you could call Powershell from Python?
PS. This won't work if you have an Explorer window open so that the db is in use, you'll get an error message.
</p>
<pre class="ipsCode prettyprint lang-html prettyprinted">
That's similar to the way I found to do it too. I've worked with the process more and more, and have managed to clear the cache, but it requires restarting Explorer. At the time of my post, I hadn't figured it out. CCleaner doesn't have to restart Explorer, so them fellers have figured something out. Oh well, there's no harm I can think of from restarting Explorer.
2 hours ago, hazelnut said:
<div class="ipsQuote_contents">
<p>
Some more info on where it is stored.
</p>
<p>
<a href="https://www.tenforums.com/tutorials/103762-prevent-windows-10-deleting-thumbnail-cache.html#:~:text=Starting%20with%20Windows%2010%20Fall,responsible%20for%20this%20when%20enabled." rel="external nofollow">https://www.tenforums.com/tutorials/103762-prevent-windows-10-deleting-thumbnail-cache.html#:~:text=Starting with Windows 10 Fall,responsible for this when enabled.</a>
</p>
</div>
<div class="ipsQuote_contents ipsClearfix" data-gramm="false">
<p>
CCleaner doesn't have to restart Explorer, so them fellers have figured something out.
</p>
</div>
With Win10 I often see in Task Manager (near the bottom of the list) two instances of Explorer running and other times I don't. So maybe after I've just ran CCleaner it's closing one instance that isn't for what's seen on screen but is instead doing something else.
Another tool, BleachBit when deleting thumbnail cache it uses TaskKill ("C:\Windows\System32\taskkill.exe"), and on XP it's obvious it's restarting Explorer, I haven't tried to have it delete thumbnail cache on Win10 yet though since it's built into Windows Disk Cleanup.
I looked at Bleachbit in my research and yeah, it restarts explorer. I briefly looked at the source but didn't find the thumbcache related code. I can live with restarting explorer to do what I want.