解決VB.NET注冊(cè)表權(quán)限經(jīng)驗(yàn)總結(jié)
作者:佚名
文章對(duì)VB.NET注冊(cè)表權(quán)限的講解,對(duì)VB.NET注冊(cè)表權(quán)限增加,細(xì)分起來(lái)共有11種可選的權(quán)限類型,它們對(duì)應(yīng)的參數(shù)我們?yōu)槟阋灰涣谐觥?/div>
大家都知道權(quán)限的概念吧,在一個(gè)后臺(tái)你可能有的權(quán)限僅僅就一個(gè),在這里我們來(lái)講講關(guān)于VB.NET注冊(cè)表權(quán)限的例子。
本實(shí)例需要項(xiàng)目引用:
- Imports Microsoft.Win32 '用途 : 注冊(cè)表操作
- Imports System.Security.AccessControl'用途 : 訪問(wèn)權(quán)限控制
首先,對(duì)VB.NET注冊(cè)表權(quán)限增加,細(xì)分起來(lái)共有11種可選的權(quán)限類型,它們對(duì)應(yīng)的參數(shù)如下:
- Select Case ComboBox1.Text
- Case "完全控制"
- ObjRegRight = RegistryRights.FullControl
- Case "查詢數(shù)值"
- ObjRegRight = RegistryRights.QueryValues
- Case "設(shè)置數(shù)值"
- ObjRegRight = RegistryRights.SetValue
- Case "創(chuàng)建子項(xiàng)"
- ObjRegRight = RegistryRights.CreateSubKey
- Case "枚舉子項(xiàng)"
- ObjRegRight = RegistryRights.EnumerateSubKeys
- Case "通知"
- ObjRegRight = RegistryRights.Notify
- Case "創(chuàng)建鏈接"
- ObjRegRight = RegistryRights.CreateLink
- Case "刪除"
- ObjRegRight = RegistryRights.Delete
- Case "寫入DAC"
- ObjRegRight = RegistryRights.WriteKey
- Case "寫入所有者"
- ObjRegRight = RegistryRights.TakeOwnership
- Case "讀取控制"
- ObjRegRight = RegistryRights.ReadPermissions
- End Select
而每個(gè)細(xì)分權(quán)限 又分"允許"和"拒絕"兩種訪問(wèn)控制類型
- Select Case ComboBox2.Text
- Case "允許"
- ObjRegAccess = AccessControlType.Allow
- Case "拒絕"
- ObjRegAccess = AccessControlType.Deny
- End Select
以下為增加VB.NET注冊(cè)表權(quán)限的函數(shù)
以下兩函數(shù)中 Account代表系統(tǒng)nt帳戶 Rights和ControlType分別為上文提及的權(quán)限類型和訪問(wèn)控制類型
- 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
以下為移除注冊(cè)表鍵權(quán)限的函數(shù)
- 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
【編輯推薦】
責(zé)任編輯:田樹(shù)
來(lái)源:
樂(lè)博網(wǎng)


相關(guān)推薦




