相关疑难解决方法(0)

如何从32位进程读取64位注册表项?

我一直在使用键的值MachineGuidHKEY_LOCAL_MACHINE\Software\Microsoft\Cryptography唯一标识主机,但在64位计算机上运行32位的进程,价值似乎已丢失.我猜它正在Wow6432Node下搜索,它确实缺失了.根据这个应该能够通过添加一个标志来获得正确的密钥,但是下面的代码似乎仍然不能完成这项工作.我错过了什么?

const
  KEY_WOW64_64KEY=$0100;
var
  r:HKEY;
  s:string;
  i,l:integer;
begin
  //use cryptography machineguid, keep a local copy of this in initialization?
  l:=40;
  if RegOpenKeyEx(HKEY_LOCAL_MACHINE,PChar('Software\Microsoft\Cryptography'),
    0,KEY_QUERY_VALUE,r)=ERROR_SUCCESS then
   begin
    SetLength(s,l);
    if RegQueryValue(r,'MachineGuid',PChar(s),l)=ERROR_SUCCESS then
     begin
      SetLength(s,l);
      RegCloseKey(r);
     end
    else
     begin
      //try from-32-to-64
      RegCloseKey(r);
      if RegOpenKeyEx(HKEY_LOCAL_MACHINE,PChar('Software\Microsoft\Cryptography'),
        0,KEY_QUERY_VALUE or KEY_WOW64_64KEY,r)=ERROR_SUCCESS then
       begin
        l:=40;
        if RegQueryValue(r,'MachineGuid',PChar(s),l)=ERROR_SUCCESS then
          SetLength(s,l)
        else
          l:=0;
        RegCloseKey(r);
       end;
     end;
   end;
Run Code Online (Sandbox Code Playgroud)

windows delphi registry 64-bit 32bit-64bit

8
推荐指数
2
解决办法
1万
查看次数

标签 统计

32bit-64bit ×1

64-bit ×1

delphi ×1

registry ×1

windows ×1