簡體   English   中英

如何獲得甚至沒有讀取權限的注冊表項的句柄

[英]How to get the handle of a registry key without even read permission

我正在嘗試調用此函數以獲取所有者作為密鑰。

[DllImport("Advapi32.dll", CharSet = CharSet.Auto)]
public extern static int SetSecurityInfo(IntPtr hKeySrc, SE_OBJECT_TYPE lpSubKey, SECURITY_INFORMATION securityInfo, IntPtr psidOwner, IntPtr psidGroup, IntPtr pDacl, IntPtr pSacl);

但是,要調用此函數,我首先需要鍵的句柄(IntPtr hKeysrc)。 在使用這些功能獲取句柄之前。

RegistryKey key = root.OpenSubKey(keyName);

private static IntPtr GetRegistryKeyHandle(RegistryKey registryKey)
    {
        IntPtr ret = IntPtr.Zero;
        try
        {
            Type registryKeyType = typeof(RegistryKey);

            System.Reflection.FieldInfo fieldInfo =
            registryKeyType.GetField("hkey", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);

            SafeHandle handle = (SafeHandle) fieldInfo.GetValue(registryKey);
            ret = handle.DangerousGetHandle();
        }
        catch (Exception ex)
        {
            LogError("GetRegistryKeyHandle ERROR:" + ex.ToString());
        }
        return ret;
    }

但是現在,我定位的密鑰僅具有系統帳戶的權限!

當我嘗試在注冊表編輯器中打開密鑰的權限時,收到錯誤消息您沒有權限查看當前的權限設置,但是可以進行權限更改。

我什至沒有對該密鑰的讀取權限。 然后,我用來獲取方法的方法將因未授權錯誤而失敗。

在這種情況下,如何獲得鑰匙的手柄? 實際上,regedit可以做到。 所以我認為可能有一個API可以做到。 但是我不知道要調用哪個API。

@HarryJohnston得到了正確的解決方案。

  1. 啟用S​​eTakeOwnershipPrivilege
  2. 打開用於WRITE_OWNER訪問的密鑰

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM