我正在嘗試製作通用函數來設置註冊表用戶權限。無法修改註冊表用戶訪問
的問題是,如果我使用的代碼,然後如果我將允許它再次,它拋出時,試圖讀取此行的主要異常否認了關鍵的fullcontrol ACCES:
Dim RK As RegistryKey = RootKey.OpenSubKey(KeyPath, RegistryKeyPermissionCheck.ReadWriteSubTree, RegistryRights.ChangePermissions Or RegistryRights.ReadKey)
我這樣調用的程序:
RegEdit.Set_UserAccess_Key("hkcu\appevents", RegistryRights.FullControl, AccessControlType.Deny)
即工作,之後我稱之爲:
RegEdit.Set_UserAccess_Key("hkcu\appevents", RegistryRights.FullControl, AccessControlType.Allow)
當我試圖讓一個先前拒絕的例外:
Requested registry access denied
Acceso denegado al Registro solicitado.
這是代碼:
''' <summary>
''' Modify the User permissions of a registry key.
''' </summary>
Public Shared Sub Set_UserAccess_Key(ByVal RegKey As String, _
ByVal RegUserAccess As RegistryRights, _
ByVal AccessType As AccessControlType, _
Optional ByVal UserName As String = Nothing)
If UserName = Nothing Then UserName = Environment.UserDomainName & "\" & Environment.UserName
Dim RootKey As RegistryKey = Get_Root_Key(RegKey) ' Registrykey.Currentuser
Dim KeyPath As String = Get_Key_Path(RegKey) ' AppEvents
Dim RS As New RegistrySecurity()
Dim RK As RegistryKey = RootKey.OpenSubKey(KeyPath, RegistryKeyPermissionCheck.ReadWriteSubTree, RegistryRights.ChangePermissions Or RegistryRights.ReadKey)
RS.AddAccessRule(New RegistryAccessRule(UserName, RegUserAccess, InheritanceFlags.None, PropagationFlags.None, AccessType))
RK.SetAccessControl(RS)
RK = RootKey.OpenSubKey(KeyPath, RegistryKeyPermissionCheck.ReadWriteSubTree, RegUserAccess)
RK.SetAccessControl(RS)
End Sub
這個問題以及「可能重複」的意思與我的問題無關。 – ElektroStudios