Access to the registry without administrator

I have several long-standing applications written in Delphi that save their settings in the registry. I used HKEY_LOCAL_MACHINE for "hard" settings, such as configuration settings, and HKEY_CURRENT_USER for "soft" information, such as window positions, MRU lists, etc.

Now my users tell me that in non-admin mode (standard user) applications do not work. Looking, I see that I can not read the parameter placed in HKEY_LOCAL_MACHINE when the application was in administrator mode.

What are my options for this? I know little about standard mode and how this affects access to the registry in general. Any information appreciated.

+5
source share
6 answers

You can read from HKLM as a non-administrator user; you just can't write on it.

Use TRegistry.Create (KEY_READ) when creating it and set RootKey to HKLM.

var
  Reg: TRegistry;
begin
  Reg := TRegistry.Create(KEY_READ)
  try
    Reg.RootKey := HKLM;
    // Read value here
  finally
    Reg.Free;
  end;
end;

You can also use TRegistry.OpenKeyReadOnly () when opening a specific registry key; it also helps without administrator access to registry areas.

+14
source
+6
source

, , Vista Win7 ( ). , , , , .
, "" Vista/Win7, - "" HKLM-, . HKLM, .
"" , UAC Vista/Win7. Regedit.exe, , Vista/Win7, UAC.
Vista/Win7, , , , , /, . , , - , /; /, "" .
, HKLM. , HKLM, Vista/Win7 ( XP ):

  • , .
  • , HKLM COM, COM- . , .

SO, .

+2

, , , - ( ..) . , JCL , , Regedit. ( HKLM), , .

+1

Windows UAC Delphi, . .

" ", ....

Windows Vista/7 -

- Windows Vista. UAC -, Windows Vista, , Run As. , Microsoft UAC.

UAC:

: Program Files Windows System32 HKLM\Software ... ...

Delphi Windows

Windows, TRegistry, "" , Windows. , Windows , :

 procedure RunOnStartup(const sCmdLine: string; bRunOnce: boolean = false; Remove: Boolean = false) ;
 var
   sKey: string;
   Section: string;
 const
   ApplicationTitle = "Your Application TITLE";
 begin
   if (bRunOnce) then
     sKey := 'Once'
   else
     sKey := '';

   Section := 'Software\Microsoft\Windows\CurrentVersion\Run' + sKey + #0;

   with TRegIniFile.Create('') do
     try
       RootKey := HKEY_LOCAL_MACHINE;
       if Remove then
         DeleteKey(Section, ApplicationTitle)
       else
         WriteString(Section, ApplicationTitle, sCmdLine) ;
     finally
       Free;
     end;
 end;

Vista/7, , , , - UAC!

UAC -

, , , , , : . , Vista UAC .

:

XML :

 <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
 <assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0]
  <assemblyIdentity version="1.1.1.1"
   processorArchitecture="X86"
   name="YourApplicationExeName"
   type="win32"/>
  <description>elevate execution level</description>
  <trustInfo xmlns="urn:schemas-microsoft-com:asm.v2]
  <security>
   <requestedPrivileges>
    <requestedExecutionLevel level="requireAdministrator" uiAccess="false"/>
   </requestedPrivileges>
  </security>
  </trustInfo>
 </assembly>

XML YourApplicationName.manifest : 1 24 "YourApplicationName.manifest"

YourApplicationName.RC , : brcc32 YourApplicationName.RC -foYourApplicationName.REC

YourApplicationName.REC

YourApplicationName.REC . DPR , : {$R YourApplicationName.REC}

, - Windows Vista. 1: "YourApplicationExeName" . 2: , EXE . Delphi.

http://delphi.about.com/od/delphitips2009/qt/delphi-vista-registry-run-on-startup.htm

+1

(a) INI/XML , , () HKLM , SetACL (public domain).

- XP Vista/W7. , Vista CSIDL COMMON APPDATA - , . , . .

b , , "" , , , , . , , , . , - HKLM .

0
source

All Articles