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

前端 未结 6 559
感动是毒
感动是毒 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条回答
  •  猫巷女王i
    2021-01-12 22:50

    I'd say that this is caused by UAC - try starting as administrator!

    If it works when started as administrator, then you need to change your read request to use read only mode (not at desk at mo so can't remember exactly how you do that)

    edit:

    function GetWindowsID: string; 
    var 
      Registry: TRegistry; 
      str:string; 
    begin 
      Registry := TRegistry.Create(KEY_READ); 
      try 
        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; 
    

提交回复
热议问题