您可能知道Windows 中磁盘清理实用程序(Disk Cleanup Utility)的命令行版本提供了更多清理选项。就在今天早些时候,我们看到了如何强制磁盘清理实用程序删除所有临时文件(Disk Cleanup Utility to delete ALL temporary files),包括过去 7 天创建的临时文件。
在本教程中,我们将了解如何激活一些额外的清理选项并自动执行清理操作,这样您就无需每次都手动运行Windows 11/10/8/7中的磁盘清理实用程序(Disk Cleanup Utility)或Cleanmgr.exe . 我们将看到如何使用带有更多清理选项的磁盘清理工具或 Cleanmgr.exe的命令行版本。(Command line version of Disk Cleanup Tool)使用任务计划程序(Use Task Scheduler)使用和参数自动运行它。sagesetsagerun
磁盘清理实用程序(Disk Cleanup Utility)或Cleanmgr.exe的命令行版本
首先,打开提升的命令提示符,键入cleanmgr /sageset:n - 其中 n 可以是 1 到 255 之间的任何整数。

此开关/sageset显示磁盘清理设置(Disk Cleanup Settings)对话框并创建一个注册表项来存储设置。该数字(number)表示稍后运行sagerun切换时将存储在注册表(Registry)中的设置- 基本上可以让您创建不同存储配置的快捷方式或在任务计划程序(Task Scheduler)中安排自动清理。
实际上/sagerun:n开关将运行通过使用/sageset开关分配给n值的指定任务。
让我们从执行以下命令开始:
cleanmgr /sageset:1
这将打开磁盘清理实用程序的(Disk Cleanup Utility)命令行(Command Line)版本,提供更多清理选项。
如果您注意到,这些是您手动运行(manually)Cleanmgr.exe时可用的选项。

如上所述,当您使用sageset(sageset)打开它时,您将看到以下清理选项。
但是,提供的选项可能因您的系统而异。

You may be surprised to see so many options being available and wonder why Microsoft chose not to make accessing them easier!
提供的选项可能包括:(The options being offered may include:)
- 临时设置文件
- 下载的程序文件
- 临时网络文件
- 离线网页
- 分支缓存
- 调试转储文件
- 旧 chkdsk 文件
- 以前的 Windows 安装
- 回收站
- 更新包备份文件
- 设置日志文件
- 系统错误内存转储文件
- 临时文件
- Windows 更新清理
- Windows 升级丢弃的文件
- 用户文件历史
- Windows Defender的
- 每个(Per)用户归档的Windows错误报告文件
- 每个用户(Per-user)排队的Windows错误报告文件
- 系统(System)归档的Windows错误报告文件
- 系统(System)排队的Windows错误报告文件
- Windows ESD 安装文件
- Windows 升级日志文件
- Zune 临时转换文件。
选择您想要的,然后单击“确定”以保存它们。单击确定后,设置(选择)将存储在注册表(Registry)中以供将来使用。当您使用cleanmgr /sagerun:1安排它运行任务计划程序(Task Scheduler)时,它将采用这些设置进行磁盘清理(Disk Cleanup)。
如果要立即运行此“增强型”磁盘清理实用程序(“Enhanced” Disk Cleanup Utility),请在 cmd 窗口中 键入 cleanmgr /sagerun:1
或者,您可以在 运行(Run)窗口中键入C:\Windows\system32\cleanmgr.exe /sagerun:1
磁盘清理操作将立即开始。

提示(TIP):要启动磁盘清理工具(Disk Cleanup Tool)并预先选择所有选项,请使用/lowdisk开关。也就是说,打开运行(Run)框并输入以下内容并按 Enter:cleanmgr /lowdisk
安排和自动(Automate)运行磁盘清理实用程序(Disk Cleanup Utility)
如果您想安排磁盘清理实用程序(Disk Cleanup Utility)每隔一段时间自动运行一次,您可以使用任务计划程序(Task Scheduler)执行此操作。为此,请从控制面板中打开(Control Panel)任务计划程序(Task Scheduler)。这篇关于如何在 Windows 中安排任务的(How to Schedule a Task in Windows )帖子将为您提供有关它的更多详细信息。单击(Click)创建基本任务(Create Basic Task)。给它一个名称和描述。

选择触发器(Trigger);在这种情况下频率。单击下一步(Click Next)。

由于我们选择了Monthly,请填写其他所需的详细信息,然后单击Next。

作为操作,选择启动程序(Start a program)并单击下一步。

由于我们要运行Disk Cleanup Utility,请编写C:\Windows\system32\cleanmgr.exe并将参数添加为/sagerun:1。由于我们使用数字“1”保存了磁盘清理设置,因此我们在这里使用相同的数字“1”。单击下一步(Click Next)。

检查摘要(Summary)。选择打开(Open) 属性(Properties)框并单击完成(Finish)。

每月磁盘清理属性(Monthly Disk Cleanup Properties)框将打开,您可以在其中查看触发器(Triggers)、历史记录(History)、常规设置(General Settings)、操作(Actions)和条件(Conditions)等详细信息。

就是这样!
磁盘清理实用程序((Disk Cleanup Utility –)带有附加选项集)将每月运行以保持磁盘清洁。
How to use Command-line version of Advanced Disk Cleanup Utility
You may be aware that the command-line version of the Disk Cleanup Utility in Windows offers many more clean-up options. Just earlier today, we saw how we could force Disk Cleanup Utility to delete ALL temporary files, including those temporary files created in the last 7 days.
In this tutorial, we will see how to activate some additional cleaning options and automate the cleanup operation, so that you don’t need to run the Disk Cleanup Utility or Cleanmgr.exe in Windows 11/10/8/7 manually, every time. We will see how to use the Command line version of Disk Cleanup Tool or Cleanmgr.exe with more cleaning options. Use Task Scheduler to run it automatically using sageset and sagerun arguments.
Command-line version of Disk Cleanup Utility or Cleanmgr.exe
To begin, open an elevated command prompt, type cleanmgr /sageset:n – where n can be any integer between 1 and 255.

This switch /sageset displays the Disk Cleanup Settings dialog box and creates a registry key to store the settings. The number denotes the settings which will be stored in the Registry when your run sagerun switch later on – and basically lets you make shortcuts to different stored configurations or schedule automatic cleanup in the Task Scheduler.
In effect the /sagerun:n switch will run the specified tasks that are assigned to the n value by using the /sageset switch.
Let’s begin with executing the following command:
cleanmgr /sageset:1
This will open the Command Line version of Disk Cleanup Utility offering many more cleanup options.
If you have noticed, these are the options available in Cleanmgr.exe when you run it manually.

When you open it using sageset, as mentioned above, you will see the following clean-up options.
The options offered may vary depending on your system, however.

You may be surprised to see so many options being available and wonder why Microsoft chose not to make accessing them easier!
The options being offered may include:
- Temporary setup files
- Downloaded program files
- Temporary internet files
- Offline web pages
- BranchCache
- Debug dump files
- Old chkdsk files
- Previous Windows installations
- Recycle bin
- Update package backup files
- Setup log files
- System error memory dump files
- Temporary files
- Windows Update Cleanup
- Files discarded by Windows upgrade
- User file history
- Windows Defender
- Per user archived Windows error reporting files
- Per-user queued Windows error reporting files
- System archived Windows error reporting files
- System queued Windows error reporting files
- Windows ESD installation files
- Windows upgrade log files
- Zune temporary converted files.
Select the ones you want and click OK to save them. After you click OK, the settings (selection) will be stored in the Registry for future use. When you schedule it using cleanmgr /sagerun:1 to run through the Task Scheduler, it will take these settings for Disk Cleanup.
If you want to run this “Enhanced” Disk Cleanup Utility right away, type cleanmgr /sagerun:1 in the cmd window and hit Enter.
Alternatively, you could type C:\Windows\system32\cleanmgr.exe /sagerun:1 in a Run window and hit Enter.
The disk cleanup operation will start right away.

TIP: To start the Disk Cleanup Tool with all the options pre-selected, use the /lowdisk switch. That is, open Run box and type the following and hit Enter: cleanmgr /lowdisk
Schedule and Automate running of Disk Cleanup Utility
If you would like to schedule Disk Cleanup Utility to run automatically, every once in a while, you can do so using the Task Scheduler. To do so, open Task Scheduler from the Control Panel. This post on How to Schedule a Task in Windows will give you more details about it. Click on Create Basic Task. Give it a name and description.

Select the Trigger; in this case the frequency. Click Next.

Since we have selected Monthly, fill in the other required details, and click Next.

As Action, select Start a program and click Next.

Since we want to run the Disk Cleanup Utility, write C:\Windows\system32\cleanmgr.exe and Add argument as /sagerun:1. As we have saved the disk cleanup setting using the number ‘1’, we are using the same number ‘1’ here. Click Next.

Check the Summary. Select the Open Properties box and click Finish.

The Monthly Disk Cleanup Properties box will open where you will get to see details like Triggers, History, General Settings, Actions, and Conditions.

That’s it!
The Disk Cleanup Utility – with the additional options set – will run every month to keep your disk clean.