The code must be compatible with D2007 and D2009.
My answer: Thanks to everyone who answered, I went with:
function ComputerName : String; var buffer: array[0..255] of char; size: dword; begin size := 256; if GetComputerName(buffer, size) then Result := buffer else Result := '' end;
Windows API
Another approach that works well is to get the computer name through an environment variable. The advantage of this approach (or a flaw depending on your software) is that you can easily trick the program as another machine.
Result := GetEnvironmentVariable('COMPUTERNAME');
. "" , , , ( "" , ).
GetComputerName Windows API - . .
function GetLocalComputerName : string; var c1 : dword; arrCh : array [0..MAX_PATH] of char; begin c1 := MAX_PATH; GetComputerName(arrCh, c1); if c1 > 0 then result := arrCh else result := ''; end;
:
function GetComputerName: string; var buffer: array[0..MAX_COMPUTERNAME_LENGTH + 1] of Char; Size: Cardinal; begin Size := MAX_COMPUTERNAME_LENGTH + 1; Windows.GetComputerName(@buffer, Size); Result := StrPas(buffer);<br/> end;
http://exampledelphi.com/delphi.php/tips-and-tricks/delphi-how-to-get-computer-name/
,
function GetLocalPCName: String; var Buffer: array [0..63] of AnsiChar; i: Integer; GInitData: TWSADATA; begin Result := ''; WSAStartup($101, GInitData); GetHostName(Buffer, SizeOf(Buffer)); Result:=Buffer; WSACleanup; end;
Bye
sComputerNamesComputerNamesComputerNamesComputerNamesComputerNamesComputerNamesComputerNamesComputerNamesComputerNamesComputerNamesComputerNamesComputerNamesComputerNamesComputerNamesComputerNamesComputerNamesComputerNamesComputerNamesComputerNamesComputerNamesComputerNamesComputerNamesComputerNamesComputerNamesComputerNamesComputerNamesComputerNamesComputerNamesComputerNamesComputerNamesComputerNamesComputerNamesComputerNamesComputerNamesComputerNamesComputerNamesComputerNamesComputerNamesComputerNamesComputerNamesComputerNamesComputerNamesComputerNamesComputerNamesComputerNamesComputerName
Source: https://habr.com/ru/post/1713109/More articles:java socket server, client discovery server - javausing LINQ to XML to query internal xml of child nodes - c #eclipse pdt >> publish from workspace - eclipseProcessing a multidimensional data structure in .Net 3.5 and later - arraysHow to overload the operator without changing the initial values? - c ++How to write an exception in section 7 of GPLv3? - gplEncapsulate a Windows message loop in a DLL - c ++Primary keys - root, serial or GUID keys? - ormReset jQuery Accordion - jqueryCombining keys / values ββfrom C ++ STL associative containers - c ++All Articles