Outlook my.user.isinrole fails

Add-in Express™ Support Service
That's what is more important than anything else

Outlook my.user.isinrole fails
Trying to capture a user role in outlook 
martin ratcliffe




Posts: 15
Joined: 2006-08-17
I am trying to capture a user role in the outlook addin so as i can specify which email disclaimer is added to the email.

msgbox(my.user.isinrole("IT").tostring) - return false

the same line in a windows form return true!

I need to check if a user is in a role because we have a couple of seperate companies on one exchange install, need to have different discliamers for legal reasons
Posted 14 Mar, 2007 07:24:13 Top
Sergey Grischenko


Add-in Express team


Posts: 7233
Joined: 2004-07-05
Hi Martin.

Please look at the code below:

Private Sub AdxCommandBarButton1_Click(ByVal sender As System.Object) Handles AdxCommandBarButton1.Click

' Retrieve a GenericPrincipal that is based on the current user's
' WindowsIdentity.
Dim genericPrincipal As GenericPrincipal = GetGenericPrincipal()

' Retrieve the generic identity of the GenericPrincipal object.
Dim principalIdentity As GenericIdentity = _
CType(genericPrincipal.Identity, GenericIdentity)

' Display identity name and authentication type.
If (principalIdentity.IsAuthenticated) Then
MsgBox(principalIdentity.Name)
End If

' Verify that the generic principal has been assigned the
' NetworkUser role.
If (genericPrincipal.IsInRole("NetworkUser")) Then
MsgBox("User belongs to the NetworkUser role.")
End If
End Sub

' Create generic principal based on values from the current
' WindowsIdentity.
Private Function GetGenericPrincipal() As GenericPrincipal
' Use values from the current WindowsIdentity to construct
' a set of GenericPrincipal roles.
Dim roles(10) As String
Dim windowsIdentity As WindowsIdentity = windowsIdentity.GetCurrent()

If (windowsIdentity.IsAuthenticated) Then
' Add custom NetworkUser role.
roles(0) = "NetworkUser"
End If

If (windowsIdentity.IsGuest) Then
' Add custom GuestUser role.
roles(1) = "GuestUser"
End If


If (windowsIdentity.IsSystem) Then
' Add custom SystemUser role.
roles(2) = "SystemUser"
End If

' Construct a GenericIdentity object based on the current Windows
' identity name and authentication type.
Dim authenticationType As String = windowsIdentity.AuthenticationType
Dim userName As String = windowsIdentity.Name
Dim genericIdentity = _
New GenericIdentity(userName, authenticationType)

' Construct a GenericPrincipal object based on the generic identity
' and custom roles for the user.
Dim genericPrincipal As New GenericPrincipal(genericIdentity, roles)

Return genericPrincipal
End Function


P.S. Note that we take up your forum requests in the order we receive them.
Besides, it may take us some time to investigate your issue. Please be sure we will let you know as soon as the best possible solution is found.
Posted 14 Mar, 2007 17:49:38 Top
martin ratcliffe




Posts: 15
Joined: 2006-08-17
Thanks that works great !
Posted 15 Mar, 2007 04:27:28 Top