Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
130 changes: 120 additions & 10 deletions PJSysInfo.pas
Original file line number Diff line number Diff line change
Expand Up @@ -987,8 +987,58 @@ TPJOSInfo = class(TObject)
/// </summary>
TPJComputerInfo = class(TObject)
public
/// <summary>Returns name of host computer.</summary>
class function ComputerName: string;
/// <summary>Returns the NetBIOS name of host computer.</summary>
/// <remarks>The original ComputerName function returned
/// the NetBIOS name using the GetComputerName() API function. Now
/// it returns the result of TPJComputerInfo.ComputerNameNetBIOS.
/// </remarks>
class function ComputerName: string; overload;

/// <summary>Returns the name format requested.</summary>
class function ComputerName(const AComputerNameFormat: COMPUTER_NAME_FORMAT)
: string; overload;

/// <summary>Returns the name of the DNS domain assigned to the local
/// computer or the cluster associated with the local computer.
/// </summary>
class function ComputerNameDnsDomain: string;

/// <summary>Returns the fully qualified DNS name that uniquely identifies
/// the local computer or the cluster associated with the local computer.
/// </summary>
class function ComputerNameDnsFullyQualified: string;

/// <summary>Returns the DNS name of the local computer or the cluster
/// associated with the local computer.
/// </summary>
class function ComputerNameDnsHostname: string;

/// <summary>Returns the NetBIOS name of the local computer or the cluster
/// associated with the local computer.
/// </summary>
class function ComputerNameNetBIOS: string;

/// <summary>Returns the name of the DNS domain assigned to the local
/// computer. On a cluster, this is the DNS domain of the local
/// node on the cluster.
/// </summary>
class function ComputerNamePhysicalDnsDomain: string;

/// <summary>Returns the fully qualified DNS name that uniquely identifies
/// the computer. On a cluster, this is the fully qualified DNS name of
/// the local node on the cluster.
/// </summary>
class function ComputerNamePhysicalDnsFullyQualified: string;

/// <summary>Returns the DNS host name of the local computer. On a cluster,
/// this is the DNS host name of the local node on the cluster.
/// </summary>
class function ComputerNamePhysicalDnsHostname: string;

/// <summary>Returns the NetBIOS name of the local computer. On a cluster,
/// this is the NetBIOS name of the local node on the cluster.
/// </summary>
class function ComputerNamePhysicalNetBIOS: string;

/// <summary>Returns name of currently logged on user.</summary>
class function UserName: string;
Expand Down Expand Up @@ -4369,19 +4419,79 @@ class function TPJComputerInfo.BootMode: TPJBootMode;
end;
end;

class function TPJComputerInfo.ComputerName: string;
class function TPJComputerInfo.ComputerName(const AComputerNameFormat: COMPUTER_NAME_FORMAT): string;
var
PComputerName: // buffer for name returned from API
array[0..MAX_COMPUTERNAME_LENGTH] of Char;
Size: DWORD; // size of name buffer
begin
Size := MAX_COMPUTERNAME_LENGTH;
if GetComputerName(PComputerName, Size) then
Result := PComputerName
ComputerName: array of Char; // buffer for name returned from API
Size: DWORD; // size of name buffer
begin
// Pass nil in the 2nd argument to determine what the size required
// for ComputerName. Size must be 0 before making the call.
Size := 0;
GetComputerNameEx(AComputerNameFormat, nil, Size);
if Size > 0 then
begin
// Size includes space for the null terminator.
SetLength(ComputerName, Size);
// After calling GetComputerNameEx(), Size is the actual length of the
// ComputerName *excluding* the null terminator.
if GetComputerNameEx(AComputerNameFormat, @ComputerName[0], Size) then
SetString(Result, PChar(@ComputerName[0]), Size)
else
Result := '';
end
else
Result := '';
end;

// The original TPJComputerInfo.ComputerName function returned the
// NetBIOS name using the GetComputerName() API function.
class function TPJComputerInfo.ComputerName: string;
begin
Result := ComputerNameNetBIOS;
end;

class function TPJComputerInfo.ComputerNameDnsDomain: string;
begin
Result := ComputerName(COMPUTER_NAME_FORMAT.ComputerNameDnsDomain);
end;

class function TPJComputerInfo.ComputerNameDnsFullyQualified: string;
begin
Result := ComputerName(COMPUTER_NAME_FORMAT.ComputerNameDnsFullyQualified);
end;

// DnsHostname can up to 63 characters.
class function TPJComputerInfo.ComputerNameDnsHostname: string;
begin
Result := ComputerName(COMPUTER_NAME_FORMAT.ComputerNameDnsHostname);
end;

// NetBIOS name will always be truncated to a max of 15 characters.
class function TPJComputerInfo.ComputerNameNetBIOS: string;
begin
Result := ComputerName(COMPUTER_NAME_FORMAT.ComputerNameNetBIOS);
end;

class function TPJComputerInfo.ComputerNamePhysicalDnsDomain: string;
begin
Result := ComputerName(COMPUTER_NAME_FORMAT.ComputerNamePhysicalDnsDomain);
end;

class function TPJComputerInfo.ComputerNamePhysicalDnsFullyQualified: string;
begin
Result := ComputerName(COMPUTER_NAME_FORMAT.ComputerNamePhysicalDnsFullyQualified);
end;

class function TPJComputerInfo.ComputerNamePhysicalDnsHostname: string;
begin
Result := ComputerName(COMPUTER_NAME_FORMAT.ComputerNamePhysicalDnsHostname);
end;

class function TPJComputerInfo.ComputerNamePhysicalNetBIOS: string;
begin
Result := ComputerName(COMPUTER_NAME_FORMAT.ComputerNamePhysicalNetBIOS);
end;

class function TPJComputerInfo.Is64Bit: Boolean;
begin
Result := Processor in [paX64, paIA64];
Expand Down