Results 1 to 11 of 11

Thread: Role of Current User

Threaded View

  1. #1

    Thread Starter
    Lively Member
    Join Date
    May 2011
    Posts
    76

    Role of Current User

    I am running Visual Studio 2013 under Win 8 and moving my project from VB6 to vb.net

    I need to know whether the user is running as an Administrator (if not, then I will ask them to either do so or go and do something else)

    After the usual searching, I built this:

    Code:
      If My.User.IsInRole(ApplicationServices.BuiltInRole.Administrator) = True Then
        MsgBox("User IS running as Administrator", MsgBoxStyle.SystemModal)
      End If
    
      If My.User.IsInRole(ApplicationServices.BuiltInRole.AccountOperator) = True  Then
        MsgBox("User IS running as AccountOperator", MsgBoxStyle.SystemModal)
      End If
    
      If My.User.IsInRole(ApplicationServices.BuiltInRole.BackupOperator) = True  Then
        MsgBox("User IS running as BackupOperator", MsgBoxStyle.SystemModal)
      End If
    
      If My.User.IsInRole(ApplicationServices.BuiltInRole.Guest) = True  Then
        MsgBox("User IS running as Guest", MsgBoxStyle.SystemModal)
      End If
    
      If My.User.IsInRole(ApplicationServices.BuiltInRole.PowerUser) = True  Then
        MsgBox("User IS running as PowerUser", MsgBoxStyle.SystemModal)
      End If
    
      If My.User.IsInRole(ApplicationServices.BuiltInRole.PrintOperator) = True  Then
        MsgBox("User IS running as PrintOperator", MsgBoxStyle.SystemModal)
      End If
    
      If My.User.IsInRole(ApplicationServices.BuiltInRole.Replicator) = True  Then
        MsgBox("User IS running as Replicator", MsgBoxStyle.SystemModal)
      End If
    
      If My.User.IsInRole(ApplicationServices.BuiltInRole.SystemOperator) = True  Then
        MsgBox("User IS running as SystemOperator", MsgBoxStyle.SystemModal)
      End If
    
      If My.User.IsInRole(ApplicationServices.BuiltInRole.User) = True  Then
        MsgBox("User IS running as User", MsgBoxStyle.SystemModal)
      End If
    But it produces nothing - even when I right click on the exe file and Run as Administrator. Anybody know why this does not work?

    I also found this routine which does produce output as per screen shot below:

    Code:
    Private Sub GetUserInfo()
      Dim UserIdentityInfo As System.Security.Principal.WindowsIdentity
      Dim strMsg           As String
    
      UserIdentityInfo = System.Security.Principal.WindowsIdentity.GetCurrent()
    
      strMsg = "User Name: " & UserIdentityInfo.Name & vbCrLf
    
      strMsg = strMsg & " Token: " & UserIdentityInfo.Token.ToString() & vbCrLf
    
      strMsg = strMsg & " AuthenticationType: " & UserIdentityInfo.AuthenticationType & vbCrLf
    
      strMsg = strMsg & " System: " & UserIdentityInfo.IsSystem & vbCrLf
    
      strMsg = strMsg & " Guest: " & UserIdentityInfo.IsGuest & vbCrLf
    
      strMsg = strMsg & " Anonymous: " & UserIdentityInfo.IsAnonymous & vbCrLf
    
      strMsg = strMsg & " User: " & UserIdentityInfo.User.ToString & vbCrLf
    
      strMsg = strMsg & " Owner: " & UserIdentityInfo.Owner.ToString & vbCrLf
    
      strMsg = strMsg & " Authenticated: " & UserIdentityInfo.IsAuthenticated.ToString & vbCrLf
    
      MsgBox(strMsg,MsgBoxStyle.SystemModal)
    
    End Sub
    Anybody know how to achieve my objective?
    Attached Images Attached Images  

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width