VB.NET实例教程对关于Array问题的解决

在VB.NET中大家有没有遇到过有关于Array的问题,VB.NET实例教程教你如何解决这个问题,大家快来尝试一下吧。

VB.NET实例教程Array案例:

本实例需要项目引用:

 
 
 
  1. Imports Microsoft.Win32  '用途 : 注册表操作  
  2. Imports System.Security.AccessControl'用途 : 访问权限控制  

首先,对注册表的键增加权限,细分起来共有11种可选的权限类型,它们对应的参数如下:

 
 
 
  1. Select Case ComboBox1.Text  
  2. Case "完全控制"  
  3. ObjRegRight = RegistryRights.FullControl  
  4. Case "查询数值"  
  5. ObjRegRight = RegistryRights.QueryValues  
  6. Case "设置数值"  
  7. ObjRegRight = RegistryRights.SetValue  
  8. Case "创建子项"  
  9. ObjRegRight = RegistryRights.CreateSubKey  
  10. Case "枚举子项"  
  11. ObjRegRight = RegistryRights.EnumerateSubKeys  
  12. Case "通知"  
  13. ObjRegRight = RegistryRights.Notify  
  14. Case "创建链接"  
  15. ObjRegRight = RegistryRights.CreateLink  
  16. Case "删除"  
  17. ObjRegRight = RegistryRights.Delete   
  18. Case "写入DAC"  
  19. ObjRegRight = RegistryRights.WriteKey  
  20. Case "写入所有者"  
  21. ObjRegRight = RegistryRights.TakeOwnership  
  22. Case "读取控制"  
  23. ObjRegRight = RegistryRights.ReadPermissions  
  24. End Select 

而每个细分权限 又分"允许"和"拒绝"两种访问控制类型

 
 
 
  1. Select Case ComboBox2.Text  
  2. Case "允许"  
  3. ObjRegAccess = AccessControlType.Allow  
  4. Case "拒绝"  
  5. ObjRegAccess = AccessControlType.Deny  
  6. End Select 

以下为增加注册表键权限的函数

以下两函数中 Account代表系统nt帐户  Rights和ControlType分别为上文提及的权限类型和访问控制类型

 
 
 
  1. Private Sub AddRegistrySecurity(ByVal Str_FileName As String, ByVal Account As String, ByVal Rights As RegistryRights, ByVal ControlType As AccessControlType)  
  2. Dim RegKey As RegistryRegistryKey = Registry.CurrentUser.CreateSubKey("此处填写具体键地址")  
  3. Dim RegkeyAcl As RegistrySecurity = RegKey.GetAccessControl()  
  4. Dim AccessRule As RegistryAccessRule = New RegistryAccessRule(Account, Rights, ControlType)  
  5. RegkeyAcl.AddAccessRule(AccessRule)  
  6. RegKey.SetAccessControl(RegkeyAcl)  
  7. RegKey.Close()  
  8. End Sub 

以下为移除注册表键权限的函数

 
 
 
  1. Private Sub RemoveRegistrySecurity(ByVal Str_FileName As String, ByVal Account As String, ByVal Rights As RegistryRights, ByVal ControlType As AccessControlType)  
  2. Dim RegKey As RegistryRegistryKey = Registry.CurrentUser.CreateSubKey("此处填写具体键地址")  
  3. Dim RegkeyAcl As RegistrySecurity = RegKey.GetAccessControl()  
  4. Dim AccessRule As RegistryAccessRule = New RegistryAccessRule(Account, Rights, ControlType)  
  5. RegkeyAcl.RemoveAccessRule(AccessRule)  
  6. RegKey.SetAccessControl(RegkeyAcl)  
  7. RegKey.Close()  
  8. End Sub 

VB.NET实例教程建议大家在做注册表编程调试的时候,采用虚拟机调试 或者备份好本机资料,注册表一旦破坏或者修改不当可能导致系统崩溃,切记!

【编辑推荐】

  1. 深入分析VB.NET条件语句中的两类
  2. 五大类VB.NET运算符全面介绍
  3. 全面讨论VB.NET申明Windows API函数
  4. 剖析VB.NET平台调用是如何执行操作
  5. 分享个人总结VB.NET多线程
THE END