Недавно добавленные исходники

•  DeLiKaTeS Tetris (Тетрис)  166

•  TDictionary Custom Sort  3 340

•  Fast Watermark Sources  3 093

•  3D Designer  4 849

•  Sik Screen Capture  3 348

•  Patch Maker  3 554

•  Айболит (remote control)  3 664

•  ListBox Drag & Drop  3 016

•  Доска для игры Реверси  81 712

•  Графические эффекты  3 946

•  Рисование по маске  3 250

•  Перетаскивание изображений  2 631

•  Canvas Drawing  2 754

•  Рисование Луны  2 584

•  Поворот изображения  2 191

•  Рисование стержней  2 169

•  Paint on Shape  1 569

•  Генератор кроссвордов  2 237

•  Головоломка Paletto  1 767

•  Теорема Монжа об окружностях  2 232

•  Пазл Numbrix  1 685

•  Заборы и коммивояжеры  2 057

•  Игра HIP  1 282

•  Игра Go (Го)  1 230

•  Симулятор лифта  1 475

•  Программа укладки плитки  1 218

•  Генератор лабиринта  1 548

•  Проверка числового ввода  1 366

•  HEX View  1 497

•  Физический маятник  1 358

 
скрыть


Delphi FAQ - Часто задаваемые вопросы

| Базы данных | Графика и Игры | Интернет и Сети | Компоненты и Классы | Мультимедиа |
| ОС и Железо | Программа и Интерфейс | Рабочий стол | Синтаксис | Технологии | Файловая система |



Delphi Sources

Получить Primary Domain Controller (PDC)



Оформил: DeeCo

{ 
  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. 
  Windows 2000/XP: Applications that support DNS-style names should call the  function. 
  Domain controllers in this type of environment have a multi-master 
  directory replication relationship. 
  Therefore, it may be advantageous for your application to use a DC that is not the PDC. 
  You can call the DsGetDcName function to locate any DC in the domain; 
  NetGetDCName returns only the name of the PDC. 
}

 type
   EAccessDenied = Exception;
   EInvalidOwner = Exception;
   EInsufficientBuffer = Exception;
   ELibraryNotFound = Exception;

   NET_API_STATUS = Integer;

 const
   NERR_Success = 0;

 var
   NTNetGetDCName: function (Server, Domain: pWideChar; var DC: pWideChar): NET_API_STATUS; stdcall;
   NTNetGetDCNameA: function (Server, Domain: PChar; var DC: PChar): NET_API_STATUS; stdcall;
   NTNetApiBufferFree: function (lpBuffer: Pointer): NET_API_STATUS; stdcall;

 procedure NetCheck(ErrCode: NET_API_STATUS);
 begin
   if ErrCode <> NERR_Success then
   begin
     case ErrCode of
       ERROR_ACCESS_DENIED:
         raise EAccessDenied.Create('Access is Denied');
       ERROR_INVALID_OWNER:
         raise EInvalidOwner.Create('Cannot assign the owner of this object.');
       ERROR_INSUFFICIENT_BUFFER:
         raise EInsufficientBuffer.Create('Buffer passed was too small');
       else
         raise Exception.Create('Error Code: ' + IntToStr(ErrCode) + #13 +
           SysErrorMessage(ErrCode));
     end;
   end;
 end;

 function GetPDC(szSystem: string): string;
   { if szSystem = '' return the PDC else return DC for that domain }
 const
   NTlib = 'NETAPI32.DLL';
   Win95lib = 'RADMIN32.DLL';
 var
   pAnsiDomain: PChar;
   pDomain: PWideChar;
   System: array[1..80] of WideChar;
   ErrMode: Word;
   LibHandle: THandle;
 begin
   Result := '';
   LibHandle := 0;
   try
     if Win32Platform = VER_PLATFORM_WIN32_NT then
     begin
       ErrMode := SetErrorMode(SEM_NOOPENFILEERRORBOX);
       LibHandle := LoadLibrary(NTlib);
       SetErrorMode(ErrMode);
       if LibHandle = 0 then
         raise ELibraryNotFound.Create('Unable to map library: ' +
           NTlib); @NTNetGetDCName := GetProcAddress(Libhandle, 'NetGetDCName');
         @NTNetApiBufferFree       := GetProcAddress(Libhandle,
         'NetApiBufferFree');
       try
         if szSystem <> '' then
           NetCheck(NTNetGetDCName(nil, StringToWideChar(szSystem, @System, 80), pDomain))
         else
           NetCheck(NTNetGetDCName(nil, nil, pDomain));
         Result := WideCharToString(pDomain);
       finally
         NetCheck(NTNetApiBufferFree(pDomain));
       end;
     end
     else
     begin
       ErrMode := SetErrorMode(SEM_NOOPENFILEERRORBOX);
       LibHandle := LoadLibrary(Win95lib);
       SetErrorMode(ErrMode);
       if LibHandle = 0 then
         raise ELibraryNotFound.Create('Unable to map library: ' +
           Win95lib); @NTNetGetDCNameA := GetProcAddress(Libhandle, 'NetGetDCNameA');
         @NTNetApiBufferFree := GetProcAddress(LibHandle, 'NetApiBufferFree');
       try
         if szSystem <> '' then
           NetCheck(NTNetGetDCNameA(nil, PChar(szSystem), pAnsiDomain))
         else
           NetCheck(NTNetGetDCNameA(nil, nil, pAnsiDomain));
         Result := StrPas(pAnsiDomain);
       finally
         NetCheck(NTNetApiBufferFree(pAnsiDomain));
       end;
     end;
   finally
     if LibHandle <> 0 then
     begin
       FreeLibrary(Libhandle); // free handle if it has been allocated 
    end;
   end;
 end;

 // Example call, Beispielaufruf: 

procedure TForm1.Button1Click(Sender: TObject);
 begin
   try
     Screen.Cursor  := crHourGlass;
     label1.Caption := GetPDC('');
   finally
     Screen.Cursor := crDefault;
   end;
 end;




Похожие по теме исходники

Domain Name, IP, Traffic




Copyright © 2004-2024 "Delphi Sources" by BrokenByte Software. Delphi World FAQ

Группа ВКонтакте