Delphi 如何以编程方式启用驱动器的系统还原监视?

Delphi 如何以编程方式启用驱动器的系统还原监视?,delphi,wmi,delphi-7,Delphi,Wmi,Delphi 7,我找到了一个,但它是C#的,我需要将它转换为Delphi。代码如下: ManagementScope scope = new ManagementScope("\\\\localhost\\root\\default"); ManagementPath path = new ManagementPath("SystemRestore"); ObjectGetOptions options = new ObjectGetOptions(); ManagementClass process = ne

我找到了一个,但它是C#的,我需要将它转换为Delphi。代码如下:

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吗?

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

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;

“我需要将下面的C#代码行转换为Delphi7”。好的,说吧。在这成为一个有效的问题之前,你需要做出一些努力,展示你已经尝试过的,解释它是如何失败的等等-1,投票结束。@Jan,你不喜欢这个代码吗?:-)@用户382591,这对你有帮助吗?