如何以编程方式检查驱动器是否受 windows 中的系统还原功能约束?

How can I check programmatically if a drive is subject to system restore feature in windows?

如标题所示,我需要一种编程方式来查明特定磁盘驱动器是否受制于 Windows 中的系统还原。 您可能会在 Control Panel/System/System protection 选项卡中看到此信息。

我正在为 windows 开发一个 security-related 应用程序,它的一些内部文件必须严格存在于一个副本中,这一点至关重要。我想防止这些文件被 windows 无意中 copied/backed 提升。或者至少警告用户随之而来的安全风险。

我知道 HKLM\SYSTEM\CurrentControlSet\Control\BackupRestore\FilesNotToBackup但并没有解决问题,因为它只在恢复阶段使用,文件内容仍然存在于备份存储中。

也有HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\SystemRestore,但是没有主题盘的信息,至少我没看到。

非常感谢任何线索。

系统还原由 Volume Shadow Copy api 管理。

您需要调用 QueryVolumesSupportedForDiffAreas method and inside the returned IVssEnumMgmtObject will be a VSS_DIFF_VOLUME_PROP 结构,它会告诉您是否在 m_llVolumeTotalSpace 参数中保留了任何存储区域。

或者,您可以通过探索 Get-CimClass -ClassName *shadow 命令来解析 vssadmin list shadowstorage 命令或 Powershell/WMI 中的等效命令的输出。这些命令对应于 wmiobjects 和 wmi api,根据您的背景和编程环境,它们可能更易于使用和访问。


还可以考虑使用 FilesNotToSnapshot instead of FilesNotToBackup. It is the one used for VSS/System Restore. You should read this document 和 api 来排除文件,并特别注意它可能无法按预期工作的情况。