Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Platform SDK: Get domain name

Platform SDK: Get domain name

Scheduled Pinned Locked Moved C / C++ / MFC
question
4 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Stefan Spenz
    wrote on last edited by
    #1

    I need to get the domain name for the currently logged on user. ::GetUserName gets me the user name, but how do I get the domain name for that user? Thanks!

    S S K 3 Replies Last reply
    0
    • S Stefan Spenz

      I need to get the domain name for the currently logged on user. ::GetUserName gets me the user name, but how do I get the domain name for that user? Thanks!

      S Offline
      S Offline
      Supriya Tonape
      wrote on last edited by
      #2

      With, Win32_LogonSession you will get 'LogonId' use this logonId to query the Win32_LoggedOnUser. After querying 'Win32_LoggedOnUser' you will get all the fields, like - Domain, Name etc Supriya

      1 Reply Last reply
      0
      • S Stefan Spenz

        I need to get the domain name for the currently logged on user. ::GetUserName gets me the user name, but how do I get the domain name for that user? Thanks!

        S Offline
        S Offline
        Stuart Dootson
        wrote on last edited by
        #3

        Use NetWkstaUserGetInfo[^] and retrieve level 1 information, as below. Requires Windows NT 3.1, 2000, XP, Vista.

        #include <Windows.h>
        #include <lm.h>

        std::wstring GetDomainName()
        {
        WKSTA_USER_INFO_1* workstationInfo;
        const NET_API_STATUS status = NetWkstaUserGetInfo(NULL, 1, (LPBYTE*)&workstationInfo);
        if (status == NERR_Success)
        {
        return workstationInfo->wkui1_logon_domain;
        NetApiBufferFree((LPBYTE*)&workstationInfo);
        }
        return std::wstring();
        }

        1 Reply Last reply
        0
        • S Stefan Spenz

          I need to get the domain name for the currently logged on user. ::GetUserName gets me the user name, but how do I get the domain name for that user? Thanks!

          K Offline
          K Offline
          krmed
          wrote on last edited by
          #4

          Another option is the environment variables USERDNSDOMAIN and USERDOMAIN. Hope that helps.

          Karl - WK5M PP-ASEL-IA (N43CS) PGP Key: 0xDB02E193 PGP Key Fingerprint: 8F06 5A2E 2735 892B 821C 871A 0411 94EA DB02 E193

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups