[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

what is the code in VB to get current user logon in windows?

Posted on 2008-10-07
1
Medium Priority
?
515 Views
Last Modified: 2013-11-25
what is the code in VB to get current user logon in windows?
here is the code I am using
Function GetUserName() As String

    If TypeOf My.User.CurrentPrincipal Is Security.Principal.WindowsPrincipal Then

        ' The application is using Windows authentication.

        ' The name format is DOMAIN\USERNAME.

        Dim parts() As String
        parts() = Split(My.User.name, "\")

        Dim username As String
        username = parts(1)

        Return username

    Else

        ' The application is using custom authentication.

        Return My.User.Name

    End If

End Function

'Dim name As String
    'name = My.User.name
    'MsgBox (name)
0
Comment
Question by:Harter
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 1500 total points
ID: 22661977
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question