Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the full computer name in Inno Setup

Tags:

inno-setup

I would like to know how to get the Full computer name in Inno Setup, for example Win8-CL01.cpx.local in the following image.

windows System computer Name

I already know how to get the computer name with GetComputerNameString but I also would like to have the Domain name of the computer. How can I get this full computer name or this domain name ?

like image 261
Alain Avatar asked Jan 09 '23 04:01

Alain


1 Answers

There's no built-in function for this in Inno Setup. You can use the GetComputerNameEx Windows API function:

[Setup]
AppName=My Program
AppVersion=1.5
DefaultDirName={pf}\My Program

[Code]
#ifdef UNICODE
  #define AW "W"
#else
  #define AW "A"
#endif

const
  ERROR_MORE_DATA = 234;

type
  TComputerNameFormat = (
    ComputerNameNetBIOS,
    ComputerNameDnsHostname,
    ComputerNameDnsDomain,
    ComputerNameDnsFullyQualified,
    ComputerNamePhysicalNetBIOS,
    ComputerNamePhysicalDnsHostname,
    ComputerNamePhysicalDnsDomain,
    ComputerNamePhysicalDnsFullyQualified,
    ComputerNameMax
  );

function GetComputerNameEx(NameType: TComputerNameFormat; lpBuffer: string; var nSize: DWORD): BOOL;
  external 'GetComputerNameEx{#AW}@kernel32.dll stdcall';

function TryGetComputerName(Format: TComputerNameFormat; out Output: string): Boolean;
var
  BufLen: DWORD;
begin
  Result := False;
  BufLen := 0;
  if not Boolean(GetComputerNameEx(Format, '', BufLen)) and (DLLGetLastError = ERROR_MORE_DATA) then
  begin
    SetLength(Output, BufLen);
    Result := GetComputerNameEx(Format, Output, BufLen);
  end;    
end;

procedure InitializeWizard;
var
  Name: string;
begin
  if TryGetComputerName(ComputerNameDnsFullyQualified, Name) then
    MsgBox(Name, mbInformation, MB_OK);
end;
like image 143
TLama Avatar answered Jan 20 '23 20:01

TLama