无需用户干预即可自动执行磁盘清理 cleanmgr.exe [英] Automate process of Disk Cleanup cleanmgr.exe without user intervention

查看:50
本文介绍了无需用户干预即可自动执行磁盘清理 cleanmgr.exe的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个 powershell 脚本文件,它将在没有用户干预的情况下执行一些磁盘清理.用户不得进行任何配置.

I am developing a powershell script file which shall execute some disk cleanup without user intervention. The user shall not be able to configure anything.

当我运行 cleanmgr.exe/d c: sageset:1 时,会出现一个弹出窗口来选择要清理的文件/文件夹(清理选项).

When I run cleanmgr.exe /d c: sageset:1 a popup window appears to select files/folders to be cleaned(cleanup options).

这将创建一个包含清理选项设置的注册表项,之后,您可以运行 cleanmgr.exe/sagerun:1 这将实际执行清理.

This will create a registry entry containing the settings with the cleanup options and after this, you can run cleanmgr.exe /sagerun:1 which will actually execute the cleanup.

有没有办法直接用powerhell/命令行指定清理选项(不需要手动选择要删除的东西)?

Is there a way to specify the cleanup options directly with powerhell/command line(without the need to manually select things to be deleted)?

推荐答案

我发现的唯一解决方案是手动设置注册表值,如下所示:

The only solution I found is to manually set the registry values like this:

...

#Set StateFlags0012 setting for each item in Windows 8.1 disk cleanup utility
if (-not (get-itemproperty -path 'HKLM:\Software\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Active Setup Temp Folders' -name StateFlags0012 -ErrorAction SilentlyContinue)) {
set-itemproperty -path 'HKLM:\Software\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Active Setup Temp Folders' -name StateFlags0012 -type DWORD -Value 2
set-itemproperty -path 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\BranchCache' -name StateFlags0012 -type DWORD -Value 2
set-itemproperty -path 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Downloaded Program Files' -name StateFlags0012 -type DWORD -Value 2

...

查看完整示例

这篇关于无需用户干预即可自动执行磁盘清理 cleanmgr.exe的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆