1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

How do I get a list of Domain names on NT/2000 box

Discussion in 'Software Development' started by wango, Jan 28, 2002.

Thread Status:
Not open for further replies.
Advertisement
  1. wango

    wango Thread Starter

    Joined:
    Nov 13, 2001
    Messages:
    74
    How do I get a list of Domain names that a Win NT/Win 2000 box can see


    According to MSDN:

    wkui1_oth_domains:
    Specifies the list of operating system domains browsed by the workstation.
    The domain names are separated by blanks.

    But I just cannot seem to find

    //
    // Demo ::NetServerEnum() level 101 with a variety of mostly useful
    // parameter settings.
    //
    void CSQLdbImportDlg::EnumerateDomains()
    {
    /*
    The NetGetDCName function returns the name of the primary domain controller (PDC).
    It does not return the name of the backup domain controller (BDC) for the
    specified domain.
    Also, you cannot remote this function to a non-PDC server.

    WKSTA_USER_INFO_1

    The WKSTA_USER_INFO_1 structure contains user information as it pertains to a
    specific workstation. The information includes the name of the current user,
    the domains accessed by the workstation, and user account information.

    typedef struct _WKSTA_USER_INFO_1
    {
    LPWSTR wkui1_username;
    LPWSTR wkui1_logon_domain;
    LPWSTR wkui1_oth_domains;
    LPWSTR wkui1_logon_server;
    }WKSTA_USER_INFO_1, *PWKSTA_USER_INFO_1, *LPWKSTA_USER_INFO_1;


    Members
    wkui1_username:
    Specifies the name of the user currently logged on to the workstation.

    wkui1_logon_domain:
    Specifies the name of the domain in which the user is currently logged on.

    wkui1_oth_domains:
    Specifies the list of operating system domains browsed by the workstation.
    The domain names are separated by blanks.

    wkui1_logon_server:
    Specifies the name of the computer that authenticated the server.


    level
    [in] Specifies the information level of the data.
    This parameter can be one of the following values.
    Value Meaning
    0 Return the name of the user currently logged on to the workstation.
    The bufptr parameter points to a WKSTA_USER_INFO_0 structure.

    1 Return information about the workstation, including the name of
    the current user and the domains accessed by the workstation. The
    bufptr parameter points to a WKSTA_USER_INFO_1 structure.

    1101 Return domains browsed by the workstation. The bufptr parameter
    points to a WKSTA_USER_INFO_1101 structure.


    To translate ACII string to wide char, use


    /////////////////////////////////////////////////////////////////////////

    */


    DWORD dwLevel = 1;

    LPWKSTA_USER_INFO_1 pBuf = NULL;
    //WKSTA_USER_INFO_1101 pBuf = NULL;

    NET_API_STATUS nStatus;

    //
    // Call the NetWkstaUserGetInfo function;
    // specify level 1.
    //
    nStatus = NetWkstaUserGetInfo(NULL,
    dwLevel,
    (LPBYTE *)&pBuf);
    //
    // If the call succeeds, print the information
    // about the logged-on user.
    //
    if (nStatus == NERR_Success)
    {
    if (pBuf != NULL)
    {

    /*
    wprintf(L"Strings in field (2):\n%25S\n%25.4hs\n\t%s%25.3ls\n",
    string, string, wstring, wstring);
    */
    wprintf(L"\n\tUser: %s\n", pBuf->wkui1_username);
    wprintf(L"\tDomain: %s\n", pBuf->wkui1_logon_domain);
    wprintf(L"\tOther Domains: %s\n", pBuf->wkui1_oth_domains);
    wprintf(L"\tLogon Server: %s\n", pBuf->wkui1_logon_server);
    }
    }
    // Otherwise, print the system error.
    //
    else
    fprintf(stderr, "A system error has occurred: %d\n", nStatus);


    USES_CONVERSION;
    //LPWSTR x = A2W(lpsz);
    //

    // this blows up
    LPSTR astring1LPSTR = W2A(pBuf->wkui1_username);
    LPSTR astring2LPSTR = W2A(pBuf->wkui1_logon_domain);
    LPSTR astring3LPSTR = W2A(pBuf->wkui1_oth_domains);
    LPSTR astring4LPSTR = W2A(pBuf->wkui1_logon_server);


    //
    // Free the allocated memory.
    //
    if (pBuf != NULL)
    NetApiBufferFree(pBuf);

    //return 0;

    } //::EnumerateServers()
     
  2. IMM

    IMM

    Joined:
    Feb 1, 2002
    Messages:
    3,257
  3. wango

    wango Thread Starter

    Joined:
    Nov 13, 2001
    Messages:
    74
    Thanks a lot.

    Michael
     
  4. IMM

    IMM

    Joined:
    Feb 1, 2002
    Messages:
    3,257
    The truth is - I couldn't tell what you meant by 'blows up'. I was hoping that something like the #define UNICODE might be a clue.

    What is happening? The compiler throws an error on the string conversion macros? - or the USES CONVERSION stuff isn't found?

    Is the project MFC using unicode - the afx stuff can give problems sometimes depending on the includes and the service pack level on the compiler (VC6 ??)
     
  5. wango

    wango Thread Starter

    Joined:
    Nov 13, 2001
    Messages:
    74
    I just od not know how to get strings out of

    LPWSTR wkui1_logon_domain;
    LPWSTR wkui1_oth_domains;

    "LPWSTR " is a strange data type and I do not know how to handle it. It is supposed to have a list of strings. I just do not know how to unravel them.

    Wango
     
  6. IMM

    IMM

    Joined:
    Feb 1, 2002
    Messages:
    3,257
    LPWSTR not a list of strings - It's just a multibyte string.

    --------- From chap6 of Win32 API programming in the Partial books section of your MSDN library

    An LPSTR string is defined as a pointer to a null-terminated ANSI character array. However, because the only way that we can tell when an LPSTR string ends is by the location of the terminating null, LPSTRs are not allowed to contain embedded null characters. Similarly, an LPWSTR is a pointer to a null-terminated Unicode character set with no embedded nulls. (The W in LPWSTR stands for Wide, which is Microsoft's way of saying Unicode.)

    Finally, the generic LPTSTR data type is used in conditional compilation, just like the TCHAR data type, to cover both ANSI and Unicode in a single source code. Here are the declarations:

    #ifdef UNICODE

    typedef LPWSTR LPTSTR; // LPTSTR is synonym for LPWSTR under Unicode
    typedef LPCWSTR LPCTSTR; // LPCTSTR is synonym for LPCWSTR under Unicode

    #else

    typedef LPSTR LPTSTR; // LPTSTR is synonym for LPSTR under ANSI
    typedef LPCSTR LPCTSTR; // LPTCSTR is synonym for LPCSTR under ANSI

    #endif
    -------------------------------------------------------------------------

    The macros for conversion you're using are ATL'ish
     
  7. IMM

    IMM

    Joined:
    Feb 1, 2002
    Messages:
    3,257
  8. Sponsor

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 733,556 other people just like you!

Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/66857

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice