在VB.NET中大家有没有遇到过有关于Array的问题,VB.NET实例教程教你如何解决这个问题,大家快来尝试一下吧。
VB.NET实例教程Array案例:
本实例需要项目引用:
- Imports Microsoft.Win32 '用途 : 注册表操作
- Imports System.Security.AccessControl'用途 : 访问权限控制
首先,对注册表的键增加权限,细分起来共有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
以下为增加注册表键权限的函数
以下两函数中 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实例教程建议大家在做注册表编程调试的时候,采用虚拟机调试 或者备份好本机资料,注册表一旦破坏或者修改不当可能导致系统崩溃,切记!
【编辑推荐】