Registry ReadString method is not working in Windows 7 in Delphi 7

前端 未结 6 535
感动是毒
感动是毒 2021-01-12 22:03

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         


        
6条回答
  •  温柔的废话
    2021-01-12 22:57

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

    Modify your code to create the TRegistry instance with

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

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

    Alternatively, use DSiWin32 and call

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

提交回复
热议问题