J
						
					
					
						
					
				
				
					Das Thema passt auch in unsere FAQ, deshalb eine "BCB-Version" dieses Beitrags aus dem WinAPI-Forum. Vorausgesetzt wird ein ListView mit sechs Columns, im ViewStyle vsReport.
//---------------------------------------------------------------------------
#ifndef UNICODE
#define UNICODE
#endif
#include <vcl.h>
#include <lm.h>
#pragma hdrstop
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
  : TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
  LPSERVER_INFO_101 pBuf = NULL;
  LPSERVER_INFO_101 pTmpBuf;
  DWORD dwLevel = 101;
  DWORD dwPrefMaxLen = -1;
  DWORD dwEntriesRead = 0;
  DWORD dwTotalEntries = 0;
  DWORD dwTotalCount = 0;
  DWORD dwServerType = SV_TYPE_SERVER; // all servers
  DWORD dwResumeHandle = 0;
  NET_API_STATUS nStatus;
  LPTSTR pszServerName = NULL;
  DWORD i;
  // Call the NetServerEnum function to retrieve information
  // for all servers, specifying information level 101.
  nStatus = NetServerEnum(pszServerName,
                          dwLevel,
                          (LPBYTE *) &pBuf,
                          dwPrefMaxLen,
                          &dwEntriesRead,
                          &dwTotalEntries,
                          dwServerType,
                          NULL,
                          &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++)
      {
        TListItem  *ListItem = ListView1->Items->Add();
        ListItem->Caption = pTmpBuf->sv101_name;
        ListItem->SubItems->Add(pTmpBuf->sv101_platform_id);
        ListItem->SubItems->Add(String(pTmpBuf->sv101_version_major) + "." +
                                String(pTmpBuf->sv101_version_minor));
        ListItem->SubItems->Add(pTmpBuf->sv101_type);
        // Check to see if the server is a domain controller;
        // if so, identify it as a PDC or a BDC.
        if (pTmpBuf->sv101_type & SV_TYPE_DOMAIN_CTRL)                
          ListItem->SubItems->Add("PDC");
        else if (pTmpBuf->sv101_type & SV_TYPE_DOMAIN_BAKCTRL)
          ListItem->SubItems->Add("BDC");
        ListItem->SubItems->Add(pTmpBuf->sv101_comment);
        pTmpBuf++;
        dwTotalCount++;
      }
      // Display a warning if all available entries were not enumerated,
      // print the number actually enumerated, and the total number available.
      if (nStatus == ERROR_MORE_DATA)
        Application->MessageBox(("Total entries: " + String(dwTotalEntries)).c_str(),
                                 "More entries available!", MB_OK | MB_ICONSTOP);
      Caption = "Entries enumerated: " + String(dwTotalCount);
    }
  }
  // Free the allocated buffer.
  if (pBuf)
    NetApiBufferFree(pBuf);
}
//---------------------------------------------------------------------------
Im Originalbeitrag wird ausdrücklich darauf hingewiesen die netapi32.lib einzubinden, hier im BCB6 war dies jedoch nicht erforderlich.