Clean+up+on+shut+down

Clean up on shut down

Note: This will only work on Professional editions of Windows XP, Vista, and Windows 7.

Unwanted files and folders have been plaguing PC users since the first computers were made. Every time you install a program, surf the web or use an application, new files and folders are created on your computer. Some are created by you and are useful, but many others are temporary files, copies of files or files that are obsolete.

Of course you can delete them manually but it can be a bit of a phaff!

You can let Windows handle the cleanup process automatically. Windows has its own cleanup utility that will do a better job at cleaning your computer of excess files and folders.

When using the Disk Cleanup Tool integrated in Windows and the Local Group Policy Editor, you can create an automated command to empty the Recycle Bin and delete temporary files and other unwanted files from your computer at each shutdown.

Here is how:-

First, we need to access the Disk Cleanup Tool.

Go to :- Start Menu > Run command, which is situated in the search field in Vista and 7.

Then type without the quotes “ cleanmgr ” in the Open box and click the OK button.

Note: To access the Disk Cleanup Tool in Windows Vista and Windows 7 you must log in with an administrator account.

In the Disk Cleanup Settings window which appears, check all the items on the list that you want cleaning and click OK.

Next you need to open the Local Group Policy Editor.

Go to:- Start > Run. Then type without the quotes “ gpedit.msc “ and click the OK button.

Note: To access the Local Group Policy Editor in Windows Vista and Windows 7 you must log in with an administrator account.

The Local Group Policy Editor will now open.

On the left side of the window, under User Configuration, double-click the Windows Settings folder.

Then, under Windows Settings, double click on Scripts (Logon/Logoff). On the right side of the window, double-click the Logoff option.

In the Logoff Properties window, click the Show Files… button.

This will open the Logoff folder. Now it is necessary to create a command file in this folder that will run automatically at every system shutdown.

Prior to creating the file, you need to go into the advanced folder options and make Windows show file extensions.

Still in the Logoff folder, click on Tools (located in the top left). Then click on Folder Options…, from the menu.

In the Folder Options window, click on the View tab. Uncheck the Hide extensions for known file types box and click OK.

Return to the Logoff folder, right-click on an empty spot and in the menu choose New and then click on Text Document.

Name this new file Cleanup.cmd, press the Enter key and click Yes.

Note: Make sure the file has the .cmd extension, and not the .txt extension

Then right-click on the Cleanup.cmd file and choose Edit from the menu. This will open the file in Notepad.

Next, type without the quotes “ cleanmgr /sagerun:1” and press Ctrl + S on the keyboard to save the file.

Close the Cleanup.cmd file and the Logoff folder and go back to the Logoff Properties window

Next, click the Add… button. Then click the Browse… button, in the Add a Script window.

Now, click on the Cleanup.cmd file, click Open and then OK.

In the Logoff Properties window, click OK and exit the Local Group Policy Editor.

Alright I know it was long winded but you will later say it was worth it.

Now each time you shutdown the computer, the Disk Cleanup Tool will start to remove any temporary files and empty the Recycle Bin.

Note: If you use Windows Vista or Windows 7, the User Account Control security feature could block the script from running. As such, the Cleanup script might ask you to enter an administrator password to continue or it might not work at all. An alternative solution would be to change the User Account Control options to a lower setting and allow the script to run.

Note:- This only works in some versions of Windows  