如何在 C# 中删除 Windows 还原点?
我正在寻找一种使用 C# 或许通过调用 WMI 来删除 Windows 还原点的方法。
任何代码片段都会非常有帮助。
Im looking for a way to delete Windows restore points using C# perhaps by invoking WMI.
Any code snippet would be very helpful.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
谈到 Morten 所说的你可以使用该 API。 据我所知,WMI 不提供删除还原点的方法。 如果您有序列号,SRRemoveRestorePoint 可以删除还原点。 您可以通过 WMI 获得它。 这是我删除还原点的代码。
我只是输入了 335,因为这是我在系统上能找到的最远的一个。 计数很可能从 1 开始并不断递增。 所以它并不像在数组中拥有一个索引那么简单。
至于获取序列号,我将代码从 Microsoft 转换为 C#,这将为您提供信息。 请务必添加 System.Management 作为参考。 否则这段代码将无法正常工作。
我在我的盒子(顺便说一下 Vista)上测试了这个,它工作没有问题。 还必须以管理员身份运行,但我想你已经想到了这一点。
Touching on what Morten said you can use that API. WMI doesn't provide a method to delete a Restore Point as far as I can tell. The SRRemoveRestorePoint can remove a restore point, provided you have the sequence number. You can get that through WMI. Here is my code to Remove a restore point.
I just threw in 335 since that was the farthest one back as I could find on my system. Its likely that the count starts at 1 and keeps incrementing. so it isn't as simple as just having an index like you would in an array.
As for getting the sequence numbers, I converted the code from Microsoft to C# which will give you that info. Be sure to add System.Management as a reference. Otherwise this code won't work right.
I tested this on my box (Vista by the way) and it worked without issue. Also have to be running as Admin, but I think you figured that.
虽然我对 WMI 一无所知,但此资源可能会帮助您入门。 它不会直接触及您的问题,但也许它在某种程度上有用。 无论如何,相关的Win32/COM函数似乎是SRRemoveRestorePoint。 我希望这有任何用处。
或者,如果您愿意,也可以使用 VBScript。
While I know nothing about WMI, this resource might get you started. It does not directly touch your issue, but perhaps it can be useful somehow. Anyhow, it seems that the relevant Win32/COM function is SRRemoveRestorePoint. I hope this was of any use.
Alternatively, you can work with VBScript, if you're so inclined.