CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Jun 2006
    Posts
    16

    Get domain name of current user belongs to?

    Instead of WindowsIdentity.GetCurrent().Name to get {Domain}\{User}.
    Is there other way to get the domain name?

  2. #2
    Join Date
    Jul 2003
    Location
    Bali, Indonesia
    Posts
    103

    Re: Get domain name of current user belongs to?

    Code:
    Environment.UserDomainName

  3. #3
    Join Date
    Mar 2004
    Location
    Prague, Czech Republic, EU
    Posts
    1,701

    Re: Get domain name of current user belongs to?

    I would recommend to extract it from the Name property of WindowsIdentity object
    Code:
    System.Security.Principal.WindowsIdentity.GetCurrent().Name
    • Make it run.
    • Make it right.
    • Make it fast.

    Don't hesitate to rate my post.

  4. #4
    Join Date
    Jun 2006
    Posts
    16

    Re: Get domain name of current user belongs to?

    boudino, could you explain a little more? Thanks.

    I should explain a little about this problem.

    If the user log into windows using a local account. WindowsIdentity.GetCurrent().Name will get {computer name}\{User}.
    If the computer name is setup longer than 15 chars. The Netbios name got truncated to the first 15 chars. Comparing the non-truncated computer name to the truncated computer name, I cannot tell they are actually the same name. But I just found out I can use Environment.MachineName, which returns the Netbios name accordingly.

  5. #5
    Join Date
    Mar 2004
    Location
    Prague, Czech Republic, EU
    Posts
    1,701

    Re: Get domain name of current user belongs to?

    If the user is logged in domain, the part before "\" is name of the domain. If he is loged localy, the computer makes its own domain. But I don't know much about NetBIOS, so sorry, but I cannot help you.
    • Make it run.
    • Make it right.
    • Make it fast.

    Don't hesitate to rate my post.

  6. #6
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: Get domain name of current user belongs to?

    WHOAMI (W2K8 Server - Domain)

    text\administrator
    WHOAMI (XP Media Center)
    MEDIA05HP\David
    Not sure why one is capitalized.
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

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

Featured