Accessing HKLM from a vb6 exe that calls a .net dll

Greetings!
I have a vb6 exe that calls a .NET 2.0 dll. The dll needs to write to odbc settings. If run as an admin this fails with the exception: that I am not allowed to access HKLM - this is expected.
What is the best way to gain write permissions for the dll I read about manfiests, and created the following manifest for my dll:

< xml version="1.0" encoding="UTF-8" standalone="yes" >
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<assemblyIdentity version="1.0.0.0"
processorArchitecture="X86"
name="MyLibrary.Common.Database.Tools.PowerTool.Library"
type="win32"/>

<description>This application is used to give higher security permissions to other users</description>
<!-- Identify the application security requirements. -->
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
<security>
<requestedPrivileges>
<requestedExecutionLevel
level="requireAdministrator"
uiAccess="false"/>
</requestedPrivileges>
</security>
</trustInfo>
</assembly>

I use the following command to insert the manifest into the dll:
"C:\Program Files\Microsoft Platform SDK for Windows Server 2003 R2\Bin\mt" -nologo -manifest "C:\NET\MyLibrary.Common.Database.Tools.PowerTool.Library.target.dll.manifest" -outputresource:"C:\NET\MyLibrary.Common.Database.BackupAndRestore\bin\Release\MyLibrary.Common.Database.Tools.PowerTool.Library.dll";#2

Once the program is run, and I try to run the executable, I get a generic exception.

What is going on

Thanks.



Answer this question

Accessing HKLM from a vb6 exe that calls a .net dll

  • Chris Honcoop

    If you're getting an access denied as admin, then elevating from standard user to admin (which is what the manifest with requireAdministrator does) is not going to help.

    BTW, you can leave the uiAccess out. This is for UIPI settings. There is more to it than just flipping the switch and it will be ignored anyway.

    If you're trying to overwrite a WRP protected setting, you most likely want to leave that to Microsoft merge modules.



  • kenlefeb

    David,

    Thanks for the reply, I modified my manifest as following to refer to the exe:

    < xml version="1.0" encoding="UTF-8" standalone="yes" >
    <assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
    <assemblyIdentity version="1.0.0.0"
    processorArchitecture="X86"
    name="BackupAndRestore.exe"
    type="win32"/>

    <description>This application is used to give higher security permissions to other users</description>
    <!-- Identify the application security requirements. -->
    <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
    <security>
    <requestedPrivileges>
    <requestedExecutionLevel
    level="requireAdministrator"
    uiAccess="true"/>
    </requestedPrivileges>
    </security>
    </trustInfo>
    </assembly>

    I put it in the same folder as the exe. However, when I double click on BackupAndRestore.exe, and try to run the function that accesses the HKLM hive, I still get security exception. What gives

    Thanks.

  • Badajoz95

    The requestedExecutionLevel is used to decide whether to launch a process elevated or not; sticking it on a .dll doens't give the dll admin rights.

    You might seperate this functionality out into a small executable with that same manifest, then invoke it. Or you could look on MSDN for docs on the 'COM Elevation Moniker'.


  • Accessing HKLM from a vb6 exe that calls a .net dll