CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Jun 2000
    Location
    Maryland
    Posts
    181

    How do I get a list of Domain names that a Win NT/Win 2000 box can see

    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 them because I do not know how to extract information from

    LPWSTR wkui1_logon_domain;
    LPWSTR wkui1_oth_domains;

    I have looked at articles

    http://support.microsoft.com/directo...icle.asp?ID=KB;EN-US;Q111544

    and

    http://support.microsoft.com/directo...icle.asp?ID=KB;EN-US;Q155698

    but they seem to just give the (one) domain name of the user. I want to get all the domain names that an NT box can have access to.



    Wango



    //
    // 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. #2
    Join Date
    Jan 2002
    Location
    Germany
    Posts
    203

    Re: How do I get a list of Domain names that a Win NT/Win 2000 box can see

    try NetServerEnum

    Hope this helps
    Regards
    Kini


  3. #3
    Join Date
    Jun 2000
    Location
    Maryland
    Posts
    181

    Re: How do I get a list of Domain names that a Win NT/Win 2000 box can see

    Thanks! After a lot of struggle, NetServerEnum
    worked.

    Wango


  4. #4
    Join Date
    May 2002
    Posts
    107

    Re: Re: How do I get a list of Domain names that a Win NT/Win 2000 box can see

    Originally posted by Wango
    Thanks! After a lot of struggle, NetServerEnum
    worked.

    Wango
    I thought NetServerEnum only gives you the primary domain, what about the rest?
    For example, my primary domain is test, my other domain is test1, test2. Can NetServerEnum detect test1 and test2 as well?
    Thanks.

  5. #5
    Join Date
    Jun 2000
    Location
    Maryland
    Posts
    181
    I will research this when I get a chance to do so. Right now I am swamped .

    Wango

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