2011-10-25 58 views
1

我用下面的代碼,以檢查是否certin用戶存在於DACL如何檢查用戶是否具有對共享文件夾的完全控制權限?

Dim l_managemantObject As ManagementBaseObject() = CType(securityDescriptor.Properties("DACL").Value, ManagementBaseObject()) 

For Each mObject As ManagementBaseObject In l_managemantObject 
    l_name = CType(mObject.GetPropertyValue("Trustee"), ManagementBaseObject).Properties("Name").Value.ToString 
    If CType(mObject.GetPropertyValue("Trustee"), ManagementBaseObject).Properties("Domain").Value IsNot Nothing Then 
     l_domain = CType(mObject.GetPropertyValue("Trustee"), ManagementBaseObject).Properties("Domain").Value.ToString() 
    End If 

    If users.UserName.ToLower = (l_domain & "\" & l_name).ToLower Then 
     Return True     
    End If 
Next 

正如你所看到的,我能夠獲取用戶名和域名。但是,如何檢查用戶是否擁有FullControl權限?

編輯:

我做furthur調查,發現使用GetAccessMask,我可以檢索的訪問權限由用戶或組代表其返回的實例所持股份。

所以還剩下什麼是: 如何獲得特定用戶AccessMask

AccessMask on MSDN

回答

0

這是我的鼻子底下的時候,使用GetPropertyValue("AccessMask")上的ManagementObject得到的權限級別。

全部方法:

Dim l_managemantObject As ManagementBaseObject() = CType(securityDescriptor.Properties("DACL").Value, ManagementBaseObject()) 

    For Each mObject As ManagementBaseObject In l_managemantObject 
     l_name = CType(mObject.GetPropertyValue("Trustee"), ManagementBaseObject).Properties("Name").Value.ToString 
     If CType(mObject.GetPropertyValue("Trustee"), ManagementBaseObject).Properties("Domain").Value IsNot Nothing Then 
      l_domain = CType(mObject.GetPropertyValue("Trustee"), ManagementBaseObject).Properties("Domain").Value.ToString() 
     End If 

     Dim l_accessMask as UInteger = mObject.GetPropertyValue("AccessMask") 

     If users.UserName.ToLower = (l_domain & "\" & l_name).ToLower Then 
      if l_accessMask = 2032127 then 
       Return True 
      endif        
     End If 
    Next 
相關問題