如何以编程方式为驱动器启用系统还原监视? [英] How to programatically enable System Restore monitoring for a drive?

查看:96
本文介绍了如何以编程方式为驱动器启用系统还原监视?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现了一个启用系统还原监视的代码,但这是针对C#的,我需要将其转换为Delphi。代码如下:

I found a code that enables System Restore monitoring, but it's for C# and I need to convert it to Delphi. Here's the code:

ManagementScope scope = new ManagementScope("\\\\localhost\\root\\default");
ManagementPath path = new ManagementPath("SystemRestore");
ObjectGetOptions options = new ObjectGetOptions();
ManagementClass process = new ManagementClass(scope, path, options);
ManagementBaseObject inParams = process.GetMethodParameters("Enable");
inParams["WaitTillEnabled"] = true;
inParams["Drive"] = osDrive;
ManagementBaseObject outParams = process.InvokeMethod("Enable", inParams, null);

有人可以帮助我将上述代码转换为Delphi吗?

Could anyone help me to convert the above code to Delphi ?

推荐答案

如果 系统还原 已启用对指定驱动器的监视,否则为False。作为输入 ADrive 参数,指定要监视的完整驱动器路径。当此参数是系统驱动器或空字符串时,将监视所有驱动器。此功能不会等待完全启用监视后再返回。而是在启动系统还原服务和筛选器驱动程序后立即返回:

The following function returns True if the System Restore monitoring of a specified drive has been enabled, False otherwise. As the input ADrive parameter specify the full drive path to be monitored. When this parameter is the system drive, or an empty string, all drives will be monitored. This function does not wait for monitoring to be enabled completely before it returns. Instead, it returns immediately after starting the System Restore service and filter driver:

function EnableSystemRestore(const ADrive: string): Boolean;
var
  WbemObject: OleVariant;
  WbemService: OleVariant;
  WbemLocator: OleVariant;
begin;
  Result := False;
  try
    WbemLocator := CreateOleObject('WbemScripting.SWbemLocator');
    WbemService := WbemLocator.ConnectServer('localhost', 'root\DEFAULT');
    WbemObject := WbemService.Get('SystemRestore');
    Result := WbemObject.Enable(ADrive) = S_OK;
  except
    on E: EOleException do
      ShowMessage(Format('EOleException %s %x', [E.Message, E.ErrorCode]));
    on E: Exception do
      ShowMessage(E.Classname + ':' + E.Message);
  end;
end;

用法:

procedure TForm1.Button1Click(Sender: TObject);
begin;
  if not EnableSystemRestore('D:\') then
    ShowMessage('Failed!')
  else
    ShowMessage('Succeeded!');
end;

这篇关于如何以编程方式为驱动器启用系统还原监视?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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