比如说 HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\DRM下的二进制值 DataPath如何读取这个值,然后将其转换成字符串显示出来?

解决方案 »

  1.   


    var
      Reg: TRegistry;
    begin
      Reg:=TRegistry.create;
      Reg.rootkey:=HKEY_LOCAL_MACHINE;
      Reg.openkey('SOFTWARE\Microsoft\DRM',true);
      Reg.ReadString('DataPath');            //读取出来的值,返回值直接是字符串类型的
      Reg.closekey;
      Reg.free;
    end;
      

  2.   

    TRegistry.ReadBinaryData
    不是刚发帖问过了吗,重开帖讨论?
      

  3.   

    参看http://topic.csdn.net/u/20100508/10/754b5570-5c1d-4c69-acb9-748b6cae042c.html?27657分类型读取
      

  4.   

    var
      DRM : TRegistry;
      buffer : array[1..1024] of Char;
      i:Integer;
    begin
      DRM := TRegistry.create;
      DRM.RootKey := HKEY_LOCAL_MACHINE;
      DRM.OpenKey('\SOFTWARE\Microsoft\DRM', True);
      i:=DRM.GetDataSize('DataPath');
      DRM.ReadBinaryData('DataPath',buffer,i);
      ShowMessage(Copy(buffer,1,i div 2));
      DRM.Free;
    end;
      

  5.   


    {我只给出如何读取,至于如何比较我认为网络上很多
    delphi2010测试通过
    2010-05-09
    }
    var
      Reg: TRegistry;
      P: PByte;
      DataInfo: TRegDataInfo;
    begin
      Reg := TRegistry.Create;
      Reg.RootKey := HKEY_LOCAL_MACHINE;
      Reg.OpenKey('SOFTWARE\Microsoft\DRM', False);
      try
        Reg.GetDataInfo('DataPath', DataInfo);
        GetMem(P, DataInfo.DataSize);
        Reg.ReadBinaryData('DataPath', P^, DataInfo.DataSize);
        ShowMessage(PChar(P));//得到结果咯
      finally
        FreeMem(P);
        Reg.CloseKey;
        Reg.Free;
      end;
    end;
      

  6.   

    {我发现我也够无聊的
    下面是 delphi7 测试通过代码,
    结果显示为:C:\Documents and Settings\All Users\DRM
    2010-05-09
    }
    var
      Reg: TRegistry;
      P: PByte;
      DataInfo: TRegDataInfo;
    begin
      Reg := TRegistry.Create;
      Reg.RootKey := HKEY_LOCAL_MACHINE;
      Reg.OpenKey('SOFTWARE\Microsoft\DRM', False);
      try
        Reg.GetDataInfo('DataPath', DataInfo);
        GetMem(P, DataInfo.DataSize);
        Reg.ReadBinaryData('DataPath', P^, DataInfo.DataSize);
        ShowMessage(PWideChar(P));//得到结果咯
      finally
        FreeMem(P);
        Reg.CloseKey;
        Reg.Free;
      end;
    end;
      

  7.   

    {我发现我也够无聊的
    下面是 delphi2007 测试通过代码,
    结果显示为:C:\Documents and Settings\All Users\DRM
    2010-05-09
    }
    var
      Reg: TRegistry;
      P: PByte;
      DataInfo: TRegDataInfo;
    begin
      Reg := TRegistry.Create;
      Reg.RootKey := HKEY_LOCAL_MACHINE;
      Reg.OpenKey('SOFTWARE\Microsoft\DRM', False);
      try
        Reg.GetDataInfo('DataPath', DataInfo);
        GetMem(P, DataInfo.DataSize);
        Reg.ReadBinaryData('DataPath', P^, DataInfo.DataSize);
        ShowMessage(PWideChar(P));//得到结果咯
        Edit1.Text := PWideChar(P);
      finally
        FreeMem(P);
        Reg.CloseKey;
        Reg.Free;
      end;
    end;