注册表ReadString方法在Delphi 7中的Windows 7中不起作用 [英] Registry ReadString method is not working in Windows 7 in Delphi 7

查看:351
本文介绍了注册表ReadString方法在Delphi 7中的Windows 7中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下代码示例用于返回我之前的Windows ID,但现在它不起作用,并返回空字符串,dunno为什么。

The following code sample used to return me windows id before, but now it doesn't work, and returns empty string, dunno why.

  function GetWindowsID: string;
  var
    Registry: TRegistry;
    str:string;
  begin
    Registry := TRegistry.Create(KEY_WRITE);
    try
      Registry.Lazywrite := false;
      Registry.RootKey := HKEY_LOCAL_MACHINE;
   //   Registry.RootKey := HKEY_CURRENT_USER;
      if CheckForWinNT = true then
       Begin
       if not Registry.OpenKeyReadOnly('\Software\Microsoft\Windows NT\CurrentVersion') then showmessagE('cant open');
       end
      else
        Registry.OpenKeyReadOnly('\Software\Microsoft\Windows\CurrentVersion');
      str := Registry.ReadString('ProductId');
      result:=str;
      Registry.CloseKey;
    finally
      Registry.Free;
    end; // try..finally
  end;

任何人都可以帮助?

推荐答案

这是因为虚拟化键'\Software\Wow6432Node\Microsoft\Windows NT\CurrentVersion\'不包含'ProductID'项目。

That is because the virtualized key '\Software\Wow6432Node\Microsoft\Windows NT\CurrentVersion\' doesn't contain the 'ProductID' item.

修改代码以使用

Registry := TRegistry.Create(KEY_WRITE OR KEY_WOW64_64KEY);

其中KEY_WOW64_64KEY = $ 0100。这将给你预期的结果。

where KEY_WOW64_64KEY = $0100. That will give you the expected result.

或者,使用 DSiWin32 并且调用

DSiReadRegistry('\Software\Microsoft\Windows NT\CurrentVersion', 
  'ProductID', '', HKEY_LOCAL_MACHINE, KEY_QUERY_VALUE OR KEY_WOW64_64KEY);

这篇关于注册表ReadString方法在Delphi 7中的Windows 7中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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