A Windows background service that automatically cleans temporary files and cache daily at 10:00 AM and when Windows starts.
✅ Automatic Cleanup - Runs daily at 10:00 AM ✅ Startup Cleanup - Cleans on Windows startup ✅ Admin Execution - Runs with LocalSystem privileges ✅ Comprehensive Cleaning - Removes:
- User TEMP folder (
%TEMP%) - User Local Temp (
C:\Users\<User>\AppData\Local\Temp) - System TEMP (
C:\Windows\Temp) - Recycle Bin (
C:\$Recycle.Bin) - Crash Dumps (
C:\Users\<User>\AppData\Local\CrashDumps) - Windows Error Reporting (
C:\ProgramData\Microsoft\Windows\WER\) - Delivery Optimization Cache
- Windows Update Cache
✅ Error Handling - Gracefully handles locked files and permission issues
✅ Detailed Logging - Creates daily log files at C:\ProgramData\TempCleanupService\
✅ Safe Deletion - Skips files/folders that are in use
- Windows 7 or later
- .NET 6.0 Runtime (or .NET Framework 4.7.2 if using Framework version)
- Administrator privileges for installation and operation
cd "d:\DC\My Projects\TempDeleted System"
dotnet publish -c ReleaseOr if using Visual Studio, build in Release configuration.
- Open Command Prompt as Administrator
- Navigate to the project directory
- Run:
install.bat
The script will:
- Check administrator privileges
- Create the Windows Service
- Set startup type to Automatic
- Start the service immediately
Check that the service is running:
sc query TempCleanupServiceStatus should show "RUNNING"
View cleanup activity logs at:
C:\ProgramData\TempCleanupService\CleanupLog_YYYY-MM-DD.txt
Each log file contains timestamped entries showing:
- Cleanup start/end times
- Directories cleaned
- Files and space freed
- Any errors encountered
To remove the service:
- Open Command Prompt as Administrator
- Navigate to the project directory
- Run:
uninstall.bat
The script will stop and remove the service. Log files are preserved.
net start TempCleanupServicenet stop TempCleanupServicesc delete TempCleanupServicesc query TempCleanupServiceMain Windows Service class that:
- Initializes on startup
- Schedules daily cleanup at 10:00 AM
- Manages timers and cleanup execution
Handles the actual cleanup operations:
- Iterates through configured directories
- Deletes files and empty folders
- Tracks statistics (files deleted, space freed)
- Handles access denied errors gracefully
Windows Service installer that:
- Defines service installation parameters
- Sets service to run as LocalSystem
- Configures automatic startup
- On Startup: Service runs cleanup immediately when Windows starts
- Daily: Cleanup runs at 10:00 AM every day
- Check Interval: Service checks every 60 seconds if it's time to run
- Service runs as LocalSystem (highest Windows privileges)
- Only accessible to administrators
- Handles permission errors gracefully
- Skips locked/in-use files
- Creates detailed audit logs
- Ensure .NET 6.0 Runtime is installed
- Check that the executable path is correct
- Verify administrator privileges
- Review event logs:
Event Viewer > Windows Logs > System
- Verify service is running:
sc query TempCleanupService - Check logs at
C:\ProgramData\TempCleanupService\ - Ensure system clock is correct
- This is normal for system files in use
- Service automatically skips them
- Critical system files are protected by Windows
- Some files may be locked by running applications
- Restarting the system can help
- Some protected system files cannot be deleted
v1.0.0 (2026-02-05)
- Initial release
- Daily scheduling at 10 AM
- Startup cleanup
- Comprehensive temp directory coverage