Get Environment Variable with Delphi

How to use function :
GetEnvironmentVariable

Retrieves an environment variable value.
Call GetEnvironmentVariable to retrieve the value of an environment variable, passed as Name, for the current process.

uses System.SysUtils


procedure TForm1.log(const msg: string);
begin
  Memo1.Lines.Add(msg);
end;

procedure TForm1.GetEnvironmentData;
begin
  log(format('Generic user profile. = %s', [GetEnvironmentVariable('ALLUSERSPROFILE')]));
  log(format('Path of the application data folder.= %s', [GetEnvironmentVariable('APPDATA')]));
  log(format('Name of Client machine.= %s', [GetEnvironmentVariable('CLIENTNAME')]));
  log(format('Path of common program files folder.= %s', [GetEnvironmentVariable('COMMONPROGRAMFILES')]));
  log(format('Name of Computer code is running on.= %s', [GetEnvironmentVariable('COMPUTERNAME')]));
  log(format('Path of the cmd.exe program.= %s', [GetEnvironmentVariable('COMSPEC')]));
  log(format('Current home drive designation, such as ''C:''= %s', [GetEnvironmentVariable('HOMEDRIVE')]));
  log(format('Path to current location for document storage.= %s', [GetEnvironmentVariable('HOMEPATH')]));
  log(format('Specifies a domain controller for user logon authentication.= %s', [GetEnvironmentVariable('LOGONSERVER')]));
  log(format('Number of processors on current machine.= %s', [GetEnvironmentVariable('NUMBER_OF_PROCESSORS')]));
  log(format('Base name of the Operating System. Note that Windows XP is given as Windows_NT.= %s', [GetEnvironmentVariable('OS')]));
  log(format('The current program path.= %s', [GetEnvironmentVariable('PATH')]));
  log(format('Extension types of executable files.= %s', [GetEnvironmentVariable('PATHEXT')]));
  log(format('Type of CPU architecture. For example, X86 for Intel Pentium processors.= %s', [GetEnvironmentVariable('OEPWOPROCESSOR_ARCHITECTUREPEORPWEO')]));
  log(format('ID number of current machine.= %s', [GetEnvironmentVariable('PROCESSOR_IDENTIFIER')]));
  log(format('More detailed description of the CPU architecture.= %s', [GetEnvironmentVariable('PROCESSOR_LEVEL')]));
  log(format('Processor revision level.= %s', [GetEnvironmentVariable('PROCESSOR_REVISION')]));
  log(format('Path of the program files folder.= %s', [GetEnvironmentVariable('PROGRAMFILES')]));
  log(format('Name of the current OS session.= %s', [GetEnvironmentVariable('SESSIONNAME')]));
  log(format('Drive the OS operates from.= %s', [GetEnvironmentVariable('SYSTEMDRIVE')]));
  log(format('Sets the system directory.= %s', [GetEnvironmentVariable('SYSTEMROOT')]));
  log(format('Path of the temporary files folder.= %s', [GetEnvironmentVariable('TEMP')]));
  log(format('Directory to store temporary files to.= %s', [GetEnvironmentVariable('TMP')]));
  log(format('Specifies the domain of the current machine.= %s', [GetEnvironmentVariable('USERDOMAIN')]));
  log(format('Name of the current user.= %s', [GetEnvironmentVariable('USERNAME')]));
  log(format('Path of the folder holding the current user''s information.= %s', [GetEnvironmentVariable('USERPROFILE')]));
  log(format('Path of the Windows folder.= %s', [GetEnvironmentVariable('WINDIR')]));
end;


//How to use

procedure TForm2.FormCreate(Sender: TObject);
begin
  GetEnvironmentData;
end;

Comments