|
Here's a collection of Delphi functions I've found useful.
Network
Using the DsGetDcName function to return the name of a domain controller in a specified domain

Determine if the computer is a member of a Domain or Workgroup - Method 1: Using NetGetJoinInformation
Determine if the computer is a member of a Domain or Workgroup - Method 2: Using NetRenameMachineInDomain
File System
Determine what File System a Drive is Formatted with using GetVolumeInformation
Get the Disk Label using GetVolumeInformation using GetVolumeInformation
Get the Size of a File
|
Using the DsGetDcName function to return the name of a domain controller in a specified domain |
This function uses the DSGetDCName API call to retrieve the name of a Domain
Controller, site information etc. You can pass in the the NetBIOS name of a
domain if you want to query a foreign doamin or if your client is in a
workgroup, or just pass an empty string ("") for the default domain.
Function
DSGetDCName(const sTargetDomainName: String; out sDomainControllerName :
string; out sDomainControllerAddress : string; out sDomainName : string; out
sDnsForestName : string; out sClientSiteName : string): integer;
Type
TDomainControllerInfoA = record
DomainControllerName: LPSTR;
DomainControllerAddress: LPSTR;
DomainControllerAddressType: ULONG;
DomainGuid: TGUID;
DomainName: LPSTR;
DnsForestName: LPSTR;
Flags: ULONG;
DcSiteName: LPSTR;
ClientSiteName: LPSTR;
end;
PDomainControllerInfoA = ^TDomainControllerInfoA;
Type_DsGetDcName = function(ComputerName, DomainName: PChar; DomainGuid: PGUID;
SiteName: PChar; Flags: ULONG; var DomainControllerInfo: PDomainControllerInfoA):
longint; stdcall;
const
DS_IS_FLAT_NAME = $00010000;
DS_RETURN_DNS_NAME = $40000000;
var
DomainControllerInfo: PDomainControllerInfoA;
lngResultCode : LongInt;
iResultCode : integer;
_DsGetDcName : Type_DsGetDcName;
pTargetDomain : PChar;
begin
sDomainControllerName:='';
sDomainControllerAddress:='';
sDomainName:='';
sDnsForestName:='';
sClientSiteName:='';
if sTargetDomainName = '' then
pTargetDomain:=nil
else
pTargetDomain:=PChar(sTargetDomainName);
try
iResultCode:=LoadLibrary(pchar('NetAPI32.dll'));
@_DsGetDcName:=GetProcAddress(iResultCode,pchar('DsGetDcNameA'));
lngResultCode:=_DsGetDcName(nil,pTargetDomain
, nil, nil, DS_IS_FLAT_NAME or DS_RETURN_DNS_NAME,
DomainControllerInfo);
FreeLibrary(iResultCode);
if lngResultCode = NO_ERROR then
begin
sDomainControllerName:=DomainControllerInfo^.DomainControllerName;
sDomainControllerAddress:=DomainControllerInfo^.DomainControllerAddress;
sDomainName:=DomainControllerInfo^.DomainName;
sDnsForestName:=DomainControllerInfo^.DnsForestName;
sClientSiteName := DomainControllerInfo^.ClientSiteName;
Result := 0;
FreeBuffer(DomainControllerInfo);
end;
finally
end;
Result:=lngResultCode;
end;
|