How to write in a registry key own by TrustedInstaller

前端 未结 3 1954
[愿得一人]
[愿得一人] 2021-02-19 17:21

In order to install a new property page into the Active Directory SnapIn, I need to write into the following registry key of W2K8 R2 (as documented by Microsoft)

HKEY_LO

相关标签:
3条回答
  • 2021-02-19 17:28

    If you use the Registry table in an MSI installer you should be able to write the entry without problems. This is because the installation process is performed under the TrustedInstaller account (you don't need to change ownership).

    Edit: It seems that you are trying to write in a registry key that is under the Windows protection system. The TrustedInstaller account doesn't matter in this case.

    Basically, a regular MSI cannot write in that key because it's protected by Windows. You will need to find another approach for installing the property page.

    0 讨论(0)
  • 2021-02-19 17:42

    So I found one of my problem.

    When you want to take ownership on a resource you add to enable the SeTakeOwnershipPrivilege this allow you to change the owner SID. But the new Owner Sid must be in the caller’s token, plus, that Sid must have attribute SE_GROUP_OWNER. So in my case I was not able to change back SID owner to S-1-5-80-956008885-3418522649-1831038044-1853292631-2271478464 (TrustedInstaller). I was just able to take ownership, or to give ownership to the group "Administrators". I discover that there is a king of work-around whereby you can assign any arbitrary user as the owner, even if its SID is not in the token. SeRestorePrivilege privilege that is granted to administrators and backup operators, but NOT enabled by default. Enbling it allow me to give back ownership to TrustedInstaller.

    So it works doing the following (user is member of administrator group):

    1. I give the user the privilege to take ownership and enable the privilege of restore
    2. The user take ownership
    3. The user write the registry
    4. the user give ownership to the previous owner TrustedInstaller.

    I use InteropServices to call Win32 AdjustTokenPrivileges API, and it seems to be the only way to do it in C#

    I will soon post on my blog a small tool that allow to give back ownership to TrustedInstaller.


    Edited : Sorry for the delay I just forget it, you can find the code on Gist.

    0 讨论(0)
  • 2021-02-19 17:47

    If you run program as an administrator (don't forget to enable 'requireAdministrator' as the UAC execution level in the manifest) or any other user having SE_RESTORE_NAME privilege you can enable the privilage and then use RegCreateKeyEx with REG_OPTION_BACKUP_RESTORE flag. You can use the same flag in RegOpenKeyEx (see ulOptions parameter), but it is undocumented and I would recommend you better to use RegCreateKeyEx instead. The key handle returned can be used to set the value with respect of RegSetValueEx for example. In the way you will be able to set any registry key. If you additionally enable SE_BACKUP_NAME privilege you will be able to read any registry key (for example from HKEY_LOCAL_MACHINE\SECURITY or HKEY_LOCAL_MACHINE\SAM\SAM).

    0 讨论(0)
提交回复
热议问题