我有一個打開注冊表符號鏈接并回傳句柄的函式(歸功于@Charlieface ) :RegistryKey
public static RegistryKey OpenSubKeySymLink(this RegistryKey key, string name, RegistryRights rights = RegistryRights.ReadKey, RegistryView view = 0)
{
var error = RegOpenKeyExW(key.Handle, name, REG_OPTION_OPEN_LINK, ((int)rights) | ((int)view), out var subKey);
if (error != 0)
{
subKey.Dispose();
throw new Win32Exception(error);
}
return RegistryKey.FromHandle(subKey); // RegistryKey will dispose subKey
}
我想通過使用密鑰的回傳句柄來洗掉這個注冊表符號鏈接。
允許我洗掉注冊表項的功能需要提供鍵名作為字串,但在我的情況下,這是一個符號鏈接,這還不夠。
我有RegistryKey句柄作為物件,我想洗掉它。
我試影像那樣洗掉它,但它不接受它:
[DllImport("advapi32.dll", EntryPoint = "RegDeleteKeyEx", SetLastError = true)]
public static extern int RegDeleteKeyEx(
UIntPtr hKey,
string lpSubKey,
uint samDesired, // see Notes below
uint Reserved);
static void Main(string[] args)
{
RegistryKey key;
key = OpenSubKeySymLink(Microsoft.Win32.Registry.CurrentUser, @"SOFTWARE\Microsoft\Windows\ABC", RegistryRights.ReadKey, 0);
RegDeleteKeyEx(key, @"SOFTWARE\Microsoft\Windows\ABC", 0x100, 0); // don't know how to delete the RegistryKey handle
}
當我鍵入時key.,我看到它作為洗掉函式,但它再次要求密鑰路徑作為字串。
uj5u.com熱心網友回復:
未記錄但呼叫RegDeleteKey(hKey, @"")(advapi32) 將通過句柄洗掉一個鍵(一直作業到 Win95/NT4)。
我不知道符號鏈接上的行為是什么。它很可能會洗掉鏈接(如果您專門打開了符號鏈接)而不是目標,但您只需檢查以確保。
如果您不想依賴未記錄的行為,則必須ZwDeleteKey按照 RbMm 的建議呼叫 (ntdll)。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/411750.html
標籤:
