如何在Inno Setup中获取完整的计算机名称

Ala*_*ain 4 inno-setup

我想知道如何在Inno Setup中获取完整的计算机名称,例如Win8-CL01.cpx.local在下图中.

windows系统计算机名称

我已经知道如何使用GetComputerNameString获取计算机名称,但我也想拥有计算机的域名.如何获取此完整的计算机名称或此域名?

TLa*_*ama 6

在Inno Setup中没有内置功能.您可以使用GetComputerNameExWindows API函数:

[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;
Run Code Online (Sandbox Code Playgroud)