Search code examples
delphidelphi-7

Identifying the server from which a Delphi 7 program is run


Separate versions of a Delphi 7 program have been deployed on various servers. In order to help troubleshoot reported errors, I'm trying to write a function to identify what server the program is running from.

The following code gets me the local computer name.

sbAll.Panels.Items[1].Text := 'Server: ' + GetEnvironmentVariable('COMPUTERNAME');

Assuming that the absolute path of the program is:

\\Swingline\Programs\Folder\Program.exe

How do I get it to return Server: Swingline regardless of what computer it is run from?


Solution

  • You can probably use Application.ExeName, split it by the slashes and get the second element...