Solved

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

Posted on 2008-10-07
1
479 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
1 Comment
 
LVL 85

Accepted Solution

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

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
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…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

762 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now