Vista automatically cleans up junk files

  
Many friends in Windows XP are using "Shutdown Script + One-Click Batch Processing" to automatically clean up junk files, but this trick is not working under Vista, although the batch command can still be executed, but found A lot of junk files have not been cleaned up. What is the reason for this? How to automatically clean up junk files under Vista? Master Dong has solved these problems for you today.
First, why the garbage order is invalid under Vista
The batch command to automatically clean up the garbage is believed to be known to many friends. It is actually a collection of a lot of delete commands. Since Vista uses NTFS format partitions, the deletion of files (especially files in the system directory) requires permission to complete. Since many commands in the batch script are to delete files in the system directory (such as the "del/f/s/q%systemdrive%\\*.log" command, try to delete "C:\\Windows\\SoftwareDistribution\\DataStore\\Logs" When \\edb.log", the system will give a prompt to deny access, because the permissions are insufficient.
Dong Shifu reminds: Many junk file cleaning scripts on the Internet may not be suitable for everyone, because it is also possible to delete important files by mistake. You should understand the role of the script before using it.
For security reasons, even if we log in to the system as a system administrator in Vista, in practice we still only have the authority to have a standard account. The shutdown script is loaded through the command prompt. By default, it runs as a standard user, so some cleanup spam commands cannot complete the deletion of files due to insufficient permissions.
Second, how to automatically clean up the garbage under Vista
After knowing the cause of the problem, the solution to the problem is of course to improve the permissions to run the batch command. If it is to manually clean up the garbage, we just need to save the cleanup script as a BAT file, then right click on it and select "Run as administrator". However, manual execution encounters UAC "blocking." Our goal is to automate the batch command, so we have to bypass UAC to let the command execute automatically. It is certainly not wise to turn off UAC, where you can automate the command with the help of the mission plan.
Dong Shifu Tip: For some important files in the system directory, by default only the built-in SYSTEM and ADMINISTRATOR users have full control. If the file cannot be deleted after "Run as administrator", then the file ownership should be changed to the currently logged in user and the permission set to "Full Control". Ownership and permission settings can be obtained with the system's takeown and cacls commands. For specific commands, please refer to Windows Help and Support.
Step 1: Save the script downloaded online as "clean.bat" and place it in c:\\. Then click Start→All Programs→-Attachments→System Tools→Task Scheduler to start the task plan and click “Create Basic Task” to start the New Task Schedule Wizard.
Step 2: According to the prompt of the wizard, create a task named “clean”. The trigger will select a time that cannot be executed, such as setting it to 2006-1-1 (so the task will not be executed automatically). ). Select "Startup Program" and click "Browse" to select "c:clean.bat".
Step 3: After finishing, check "Dialog box for opening this task property when you click Finish", and switch to the "General" tab in the dialog box that opens. Click "Change User and Group" under Security Options, select the system administrator account to run the task, and check "Run with highest privileges" below. This way, once the mission plan is run, it has administrator privileges.
Step 4: Start Notepad to create a new batch of processing cl.bat, placed in c:, the code is as follows:
Rem uses the task plan command to start cleaning garbage, /run means running, /tn followed by task name Schtasks/run /tnclean
Step 5: Click Start→Run and type gpedit.msc to start the Group Policy Editor. Expand Computer Configuration→Windows Settings/Scripts (Startup/Shutdown), double-click Shut Down in the right pane, click Add in the window that opens, and add c:cl.bat to the shutdown script. OK. After each shutdown, the system will automatically call this batch command to activate the above task plan to clear the garbage. Since we have set the task run to "Run with the highest privilege" (equivalent to the right "Run as administrator", but will not pop up the UAC prompt), this will run the administrator privilege, which can effectively delete the system junk files. .
After editing: Due to the characteristics of Vista's NTFS partition, some of the original unobstructed operations under Windows XP, if you encounter a failure in Vista, you must see if it is because of operational rights. The solution to the problem is to improve the operation rights. If you need to automatically increase the permission to run, you can use the task planning method described in the article.

Copyright © Windows knowledge All Rights Reserved