Deleting files older than a specific date or age

I needed to delete a chunk of cookies today – but I didn’t want to delete them all.

Thankfully there is a handy command that is within Windows versions after XP such as Server 2003 and Vista that will enable to clean up without too many problems.

The forfiles command will allow you to set a specific date for a file so that you don’t delete recent cookies:

<code>forfiles /S /p "C:\Users\John\cookies" /D -150 /c "cmd /c del @path"</code>

If you wanted to be super cool and delete multiple user cookie folders you could do something like this:

<code>for /D %D in (C:\Users\*) DO forfiles /S /p "%D\cookies" /D -150 /c "cmd /c del @path"</code>

This will enumerate all of the user folders in the C:\Users folder and then clean up the cookies folders inside.

If you wanted to – you can change the amount of days from 150 days to any other amount you like by changing /D -150 to any other number of days (or even use a specific date).

Stop Windows Server 2003 Hanging When Installing Updates

Some of the servers that I manage in locations have a nasty habit of hanging on the final stage of rebooting when trying to apply Windows Updates automatically.

In most locations, I use WSUS to deploy updates around the site which is OK, but when it comes to servers problems arise.

After roaming around on the internet, I found a useful thread at EggHeadCafe¬†which describes the problem I’m having. Apparently, turning off the default user screensaver using the following registry key will solve the problem:

HKEY_USERS\.DEFAULT\control panel\screensaveractive
Set the value to 0

This would make sense, as there is a similar problem in Windows XP where if you try to shutdown the system with the power button (or an update) while the screen saver is active, the system will shutdown until the screensaver is turned off by touching the keyboard or mouse.

I’ll find out if this works in a month’s time!

EDIT: Just logged onto one of my servers with this change and it works a treat.