CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 11 of 11
  1. #1
    Join Date
    Dec 2003
    Location
    newyork
    Posts
    28

    enum domain & computers in a network

    hello again,
    i refered your suggession and created one MFC application ....in which i m creating a button , a combo box a list box and some other control for my project.

    1. what i did (achieved) is :

    when i clicked the button the application is flooding the no of domains ,servers and the individual computers at a time in a sequence by a callback function NetServerEnum() (callback --->i think so till now not checked) & i m displaying in the list box. but my requirement is different in the following manner ....
    2. my requirement is :

    when i click the button the application should enumerate the no of domains first and should put in the combo box.then when i will select one of the domain from the combo , i should get the list of computers in that particular domain , which i want to show in the list box.

    how to do that ... using the same function ...??

    please guide me ...

    thanking u.

    panda

  2. #2
    Join Date
    Feb 2002
    Posts
    5,757
    Add a CComboBox object into your dialog window and fill it.

    Kuphryn

  3. #3
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,244
    As kuphryn already stated we must fill something
    Code:
    // NOTE: UNICODE defined
    void CDDlg::OnSomeButtonPushed() 
    {
       FillDomainsCombo();
    }
    void CDDlg::OnSelchangeComboDomains() 
    {
       FillWorkstationsList();
    }
    void CDDlg::FillDomainsCombo()
    {
       m_comboDomains.ResetContent();
    
       LPBYTE lpServers  = NULL;
       DWORD dwLen       = (DWORD)-1;
       DWORD dwTotal     = 0;
       DWORD dwPreffered = MAX_PREFERRED_LENGTH;
       DWORD dwRead      = 0;
       DWORD dwType      = SV_TYPE_DOMAIN_ENUM;
       DWORD dwResume    = 0;
    
       DWORD dwRet  = ::NetServerEnum( NULL,
                                       100,
                                       &lpServers,
                                       dwPreffered, 
                                       &dwRead,
                                       &dwTotal,
                                       dwType,
                                       NULL,
                                       &dwResume ) ;
       if( NERR_Success == dwRet )
       {
          SERVER_INFO_100* pSvr = (SERVER_INFO_100*)(PVOID)lpServers;
          for( DWORD dwIndex = 0; dwIndex < dwRead ; dwIndex ++, pSvr ++ )
          {
             m_comboDomains.AddString( pSvr->sv100_name );
          }
          if( dwRead > 0 )
          {
             m_comboDomains.SetCurSel( 0 );
             FillWorkstationsList();
          }
       }
       else
       {
          // Handle error
       }
    }
    void CDDlg::FillWorkstationsList()
    {
       m_listWorkstations.ResetContent();
    
       const int nCurSel = m_comboDomains.GetCurSel();
       if( CB_ERR == nCurSel )
       {
          return;
       }
       
       LPBYTE lpServers  = NULL;
       DWORD dwLen       = (DWORD)-1;
       DWORD dwTotal     = 0;
       DWORD dwPreffered = MAX_PREFERRED_LENGTH;
       DWORD dwRead      = 0;
       DWORD dwType      = SV_TYPE_WORKSTATION;
       DWORD dwResume    = 0;
    
       CString strWorkstation;
       m_comboDomains.GetLBText( nCurSel, strWorkstation );
    
       DWORD dwRet  = ::NetServerEnum( NULL,
                                       100,
                                       &lpServers,
                                       dwPreffered, 
                                       &dwRead,
                                       &dwTotal,
                                       dwType,
                                       strWorkstation,
                                       &dwResume ) ;
       if( NERR_Success == dwRet )
       {
          SERVER_INFO_100* pSvr = (SERVER_INFO_100*)(PVOID)lpServers;
          for( DWORD dwIndex = 0; dwIndex < dwRead ; dwIndex ++, pSvr ++ )
          {
             m_listWorkstations.AddString( pSvr->sv100_name );
          }
       }
       else
       {
          // Handle error
       }
    }
    Ovidiu
    "When in Rome, do as Romans do."
    My latest articles: https://codexpertro.wordpress.com/

  4. #4
    Join Date
    Dec 2003
    Location
    newyork
    Posts
    28
    hello,
    yeah i added your 2 functions but got some error .

    like ...
    some typecast & type conversion errors...

    next i have to include some header file ....can u list out those which i have to include in the view class .

    some type conversion like :


    CString' to 'LPCWSTR ,

  5. #5
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,244

    Net...bla-bla functions

    The first line in my example was:
    Code:
    // NOTE: UNICODE defined
    So...

    To build your project in UNICODE configuration:
    Add UNICODE to "Project Setings\C/C++\Preprocessor definitions"
    Type wWinMainCRTStartup in "Project Setings\Link\Output(category)\Entry-point symbol"

    Other issues:
    Add netapi32.lib to "Project Setings\Link\General(category)\Object/library modules".
    Add the following includes in your source file:
    #include <LMCONS.H>
    #include <lmserver.h >
    #include <LMERR.H>


    However a sample project is attached here.
    Attached Files Attached Files
    Last edited by ovidiucucu; January 30th, 2005 at 07:42 AM.
    Ovidiu
    "When in Rome, do as Romans do."
    My latest articles: https://codexpertro.wordpress.com/

  6. #6
    Join Date
    Dec 2003
    Location
    newyork
    Posts
    28
    hi,

    heartly thanks for the early reply & help material.

    i got the result in some way by refering your articles...

    if i got again some doubt i will contact u...in near future...

    again thanks

    skpanda

  7. #7
    Join Date
    Oct 2003
    Location
    Romania
    Posts
    127

    To ovidiucucu

    Quite nice the Send2 program that you have uploaded here (netblabla.zip).
    But I have to report something:
    It can send messages only to workstations from the primary domain.
    Is this a bug, or a missing feature?
    Last edited by marsh_pottaye; February 5th, 2004 at 09:06 AM.

  8. #8
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,244

    Re: To ovidiucucu

    Quote Originally Posted by marsh_pottaye
    Quite nice the Send2 program that you have uploaded here (netblabla.zip).
    But I have to report something:
    It can send messages only to workstations from the primary domain.
    Is this a bug, or a missing feature?
    It's a missing feature... Maybe I will implement it in version 2.0
    Ovidiu
    "When in Rome, do as Romans do."
    My latest articles: https://codexpertro.wordpress.com/

  9. #9
    Join Date
    Nov 2001
    Posts
    323

    Re: enum domain & computers in a network

    Hi,
    my program using NetServerEnum is not getting all of the workstations on the network the MSDN states:
    ERROR_MORE_DATA More entries are available. Specify a large enough buffer to receive all entries.

    So how do I specify a large enough buffer to get all the workstations??

    Code:
       
       LPSERVER_INFO_101 pBuf = NULL;
       LPSERVER_INFO_101 pTmpBuf;
       DWORD dwLevel = 101;
       DWORD dwPrefMaxLen = MAX_PREFERRED_LENGTH;
       DWORD dwEntriesRead = 0;
       DWORD dwTotalEntries = 0;
       DWORD dwTotalCount = 0;
       DWORD dwServerType = SV_TYPE_WORKSTATION; //  all workstations
       DWORD dwResumeHandle = 0;
       NET_API_STATUS nStatus;
       LPCWSTR pszServerName = NULL;
       LPCWSTR domain = (LPCWSTR)m_strDom.GetBuffer();
       DWORD i;
    
    
       // Call the NetServerEnum function to retrieve information
       //  for all workstations, specifying information level 101.
       //
       nStatus = NetServerEnum(pszServerName,
                               dwLevel,
                               (LPBYTE *) &pBuf,
                               dwPrefMaxLen,
                               &dwEntriesRead,
                               &dwTotalEntries,
                               dwServerType,
                               domain,
                               &dwResumeHandle);
       //
       // If the call succeeds,
       //
       if ((nStatus == NERR_Success) || (nStatus == ERROR_MORE_DATA))
       {
          if ((pTmpBuf = pBuf) != NULL)
          {
             //
             // Loop through the entries and 
             //  print the data for all server types.
             //
             for (i = 0; i < dwEntriesRead; i++)
             {
                ASSERT(pTmpBuf != NULL);
    
                if (pTmpBuf == NULL)
                {
                   break;
                }
    	
                  CString n = pTmpBuf->sv101_name;
    			
                 GetListCtrl().InsertItem(i,n);
    	
       
                pTmpBuf++;
                dwTotalCount++;
             }
      
            
          }
       }
        // Free the allocated buffer.
       
       if (pBuf != NULL)
          NetApiBufferFree(pBuf);
    Best Regards,

    --Zim
    If you find this post useful, please rate it.
    _________________________________
    "Have you the brain worms?!?!?"

  10. #10
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,244

    Re: enum domain & computers in a network

    Well, in MSDN is stated that If you specify MAX_PREFERRED_LENGTH, the function allocates the amount of memory required for the data. Still returns ERROR_MORE_DATA?
    Ovidiu
    "When in Rome, do as Romans do."
    My latest articles: https://codexpertro.wordpress.com/

  11. #11
    Join Date
    Nov 2001
    Posts
    323

    Re: enum domain & computers in a network

    Hi ovidiucucu, thanks for replying,

    with max_preferred_length set it NEVER returns ERROR_MORE_DATA.
    it only returns ERROR_MORE_DATA if I change the value to greater than or less than max_preferred_length
    either netserverenum is failing to return all workstations OR it only lists those workstations with someone logged onto them
    In other words, it's not like reading the active directory which will return every workstation.

    I found an undocumented function NetServerEnumEx which is supposed to return more workstations (the resume variable is not reserved in this function) but I couldn't get it to work. It kept reporting Linker errors, but I don't know why, NetServerEnumEx is in the same file as NetServerEnum!
    And since it's undocumented, I don't know what additional libraries or files to include to make it work!!
    Best Regards,

    --Zim
    If you find this post useful, please rate it.
    _________________________________
    "Have you the brain worms?!?!?"

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