Link to home
Start Free TrialLog in
Avatar of NoradEE
NoradEEFlag for Poland

asked on

Delphi 2006 Relative registry open Win7 x64

Hi,

I want to read and then write some key registry in 7x64 but this function doesn't work as I want
FReg.OpenKey('SOFTWARE\Microsoft\Windows NT\CurrentVersion\

it opens automaticly SOFTWARE\Wow6432Node\SOFTWARE\Microsoft\ ...

How to open the same key as requested without this "Wow6432Node" ?
I need solution which will open read and then write IDENTICAL key on x32 XP and 7x64






Avatar of Mike McCracken
Mike McCracken

You may need to run in 32-bit emulation mode under Win 7 or if there is a XP emulation mode.

mlmcc
Avatar of NoradEE

ASKER

"You may need to run in 32-bit emulation mode under Win 7 or if there is a XP emulation mode "

No I cannot just have exe which must modify registry in that way...
Avatar of NoradEE

ASKER

Maybe some Winapi ? Has anyone got Win7 MSDN ?
To write to local machine on Windows Vista/7 your program needs admin rights. There is no way around it.

You'll need this files:

1. administrator.manifest

content:

<?xml version="1.0" encoding="utf-8"?>
<asmv1:assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1"
xmlns:asmv1="urn:schemas-microsoft-com:asm.v1" xmlns:asmv2="urn:schemas-microsoft-com:asm.v2"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <assemblyIdentity version="1.0.0.0" name="MyApplication.app"/>
  <trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
    <security>
      <requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
        <!-- UAC Manifest Options
            If you want to change the Windows User Account Control level replace the
            requestedExecutionLevel node with one of the following.

        <requestedExecutionLevel  level="asInvoker" uiAccess="false" />
        <requestedExecutionLevel  level="requireAdministrator" uiAccess="false" />
        <requestedExecutionLevel  level="highestAvailable" uiAccess="false" />

            If you want to utilize File and Registry Virtualization for backward
            compatibility then delete the requestedExecutionLevel node.
        -->
        <requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
      </requestedPrivileges>
    </security>
  </trustInfo>
<dependency>
    <dependentAssembly>
        <assemblyIdentity
            type="win32"
            name="Microsoft.Windows.Common-Controls"
            version="6.0.0.0"
            processorArchitecture="X86"
            publicKeyToken="6595b64144ccf1df"
            language="*"
        />
    </dependentAssembly>
</dependency>
</asmv1:assembly>

2. administrator.rc

content:

1 24 "administrator.manifest"

now use the command file to create a resource file:

brcc32 administrator.rc

you can a .res file.

Now in your .dpr file add this line:

{$R 'administrator.res' 'administrator.rc'}

Your program will prompt for UAC access and write directly to the registry from now on.

Avatar of NoradEE

ASKER

Dear ThomasReimann.

I'm afraid that you've not read carefully and do not understood problem.
File is running with full admin privileges (right click "Run ad administrator") this is not problem

Problem is to store to reg path without this "Wow6432Node"
In my tests about one year ago, it was not enough to run the program as administrator, you had to have the manifest included in the exe.

What you may also try is to open the registry in 64 bit mode:

     RegOut64 := TRegistry.Create(KEY_ALL_ACCESS OR KEY_WOW64_64KEY);
     RegOut64.RootKey := HKEY_LOCAL_MACHINE;
I forgot this:

const

  KEY_WOW64_64KEY = $0100;
  KEY_WOW64_32KEY = $0200;
Avatar of NoradEE

ASKER

Thomas what is that?

Will this work on Delphi 2006 ?

I need to modify such code:
OpenKey('SOFTWARE\Microsoft\Windows NT\CurrentVersion\Mysoft', False) then
    begin
      FRegValue := Trim(FReg.ReadString('Value'));





You need to search for the Registry object.

You must have something like:

myRegistry.OpenKey()

somewhere in the code myRegistry is created

myRegistry := TRegistry.Create(KEY_ALL_ACCESS);

you must add the 64bit access rights to that:

myRegistry := TRegistry.Create(KEY_ALL_ACCESS OR KEY_WOW64_64KEY);
Avatar of NoradEE

ASKER

I'ts mixed too much
simply again can someone give full code replacement for that?
----------------
I need to modify such code:
OpenKey('SOFTWARE\Microsoft\Windows NT\CurrentVersion\Mysoft', False) then
    begin
      FRegValue := Trim(FReg.ReadString('Value'));
-----------------
You don't have to change OpenKey() at all, you must search where the Registry object is created and change it to 64bit there. Leave OpenKey() alone.
Avatar of NoradEE

ASKER

ok so how to do that?
Sumarry of all your posts?
Please write me in one comment instead of few mixed

Would be thankful.
Regards
ASKER CERTIFIED SOLUTION
Avatar of ThomasReimann
ThomasReimann

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of NoradEE

ASKER

thanks ok