?
Solved

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

Posted on 2008-10-07
1
Medium Priority
?
507 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Over the years I have built up my own little library of code snippets that I refer to when programming or writing a script.  Many of these have come from the web or adaptations from snippets I find on the Web.  Periodically I add to them when I come…
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
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…
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
Course of the Month12 days, 19 hours left to enroll

777 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