这篇文章主要介绍如何解决VB.NET注册表权限问题,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!
本实例需要项目引用:
Imports Microsoft.Win32 '用途 : 注册表操作 Imports System.Security.AccessControl'用途 : 访问权限控制
首先,对VB.NET注册表权限增加,细分起来共有11种可选的权限类型,它们对应的参数如下:
Select Case ComboBox1.Text Case "完全控制" ObjRegRight = RegistryRights.FullControl Case "查询数值" ObjRegRight = RegistryRights.QueryValues Case "设置数值" ObjRegRight = RegistryRights.SetValue Case "创建子项" ObjRegRight = RegistryRights.CreateSubKey Case "枚举子项" ObjRegRight = RegistryRights.EnumerateSubKeys Case "通知" ObjRegRight = RegistryRights.Notify Case "创建链接" ObjRegRight = RegistryRights.CreateLink Case "删除" ObjRegRight = RegistryRights.Delete Case "写入DAC" ObjRegRight = RegistryRights.WriteKey Case "写入所有者" ObjRegRight = RegistryRights.TakeOwnership Case "读取控制" ObjRegRight = RegistryRights.ReadPermissions End Select
而每个细分权限 又分"允许"和"拒绝"两种访问控制类型
Select Case ComboBox2.Text Case "允许" ObjRegAccess = AccessControlType.Allow Case "拒绝" ObjRegAccess = AccessControlType.Deny End Select
以下为增加VB.NET注册表权限的函数
以下两函数中 Account代表系统nt帐户 Rights和ControlType分别为上文提及的权限类型和访问控制类型
Private Sub AddRegistrySecurity(ByVal Str_FileName As String, ByVal Account As String, ByVal Rights As RegistryRights, ByVal ControlType As AccessControlType) Dim RegKey As RegistryRegistryKey = Registry.CurrentUser.CreateSubKey("此处填写具体键地址") Dim RegkeyAcl As RegistrySecurity = RegKey.GetAccessControl() Dim AccessRule As RegistryAccessRule = New RegistryAccessRule(Account, Rights, ControlType) RegkeyAcl.AddAccessRule(AccessRule) RegKey.SetAccessControl(RegkeyAcl) RegKey.Close() End Sub
以下为移除注册表键权限的函数
Private Sub RemoveRegistrySecurity(ByVal Str_FileName As String, ByVal Account As String, ByVal Rights As RegistryRights, ByVal ControlType As AccessControlType) Dim RegKey As RegistryRegistryKey = Registry.CurrentUser.CreateSubKey("此处填写具体键地址") Dim RegkeyAcl As RegistrySecurity = RegKey.GetAccessControl() Dim AccessRule As RegistryAccessRule = New RegistryAccessRule(Account, Rights, ControlType) RegkeyAcl.RemoveAccessRule(AccessRule) RegKey.SetAccessControl(RegkeyAcl) RegKey.Close() End Sub
以上是“如何解决VB.NET注册表权限问题”这篇文章的所有内容,感谢各位的阅读!希望分享的内容对大家有帮助,更多相关知识,欢迎关注编程网行业资讯频道!