Bayesean Blog - Desktop, Mobile and IOT Developer Blog


Delphi using Environment Variables in your App

Posted on 20th Aug 2018 in Delphi FMX, Delphi VCL


EnvironmentV12.png

Delphi using Environment Variables in your App

Environment Variables can help you extract data that require some in-depth coding to achieve the same result. So here is a simple way to replace lengthy legacy code or create some new code with

function GetEnvironmentVariable(const Name: string): string;  found in the System.SysUtils library.

Envirnment.gif

What it is?

The ‘GetEnvironmentVariable’ method is a way to retrieve the value of an environment variable passed as a string (name) for the current process using a standard list of Windows based variables that can be extracted.

How useful is it?

These Environment Variables are a standard across all OS’s and for different processors thereby ensuring that there is no requirements for ‘IFDEFs’.

I found it useful to extract :-

  • certain directories such as ‘Appdata’ that calls the Roaming directory.
  • to determine / show who has logged onto the Windows machine.
  • extract the CMD.exe directory using ‘Comspec’.
  • Obtaining the OS Processor info.
  • obtaining the ‘Tmp / Temp’ drive for processing.

 Downloadt the simple App that calls each Environment Variable via a combobox that shows the result real time on your Windows machine. Perhaps there are a few other options that you could find useful.

Here is the list of the Standard Environment Variables.

ALLUSERSPROFILE - Generic user profile.

APPDATA - Path of the application data folder.

CLIENTNAME - Name of Client machine.

COMMONPROGRAMFILES - Path of common program files folder.

COMPUTERNAME - Name of Computer code is running on.

COMSPEC - Path of the cmd.exe program.

HOMEDRIVE - Current home drive designation, such as 'C:'

HOMEPATH - Path to current location for document storage.

LOGONSERVER - Specifies a domain controller for user logon authentication.

NUMBER_OF_PROCESSORS - Number of processors on current machine.

OS - Base name of the Operating System.

PATH - The current program path.

PATHEXT - Extension types of executable files.

PROCESSOR_ARCHITECTURE - Type of CPU architecture. For example, X86 for Intel Pentium processors.

PROCESSOR_IDENTIFIER - ID number of current machine.

PROCESSOR_LEVEL - More detailed description of the CPU architecture.

PROCESSOR_REVISION - Processor revision level.

PROGRAMFILES - Path of the program files folder.

SESSIONNAME - Name of the current OS session.

SYSTEMDRIVE - Drive the OS operates from.

SYSTEMROOT - Sets the system directory.

TEMP - Path of the temporary files folder.

TMP - Directory to store temporary files to.

USERDOMAIN - Specifies the domain of the current machine.

USERNAME - Name of the current user.

USERPROFILE - Path of the folder holding the current user's information.

WINDIR - Path of the Windows folder.

Feel Free to download the sample App from here

Download Code

 

Happy Coding


Be the First to Comment...

Add a Comment

9+5

Recent News

Delphi VCL Buttons in DBGrid
Two Helper Apps for Delphi LibUSB
Delphi Libusb Library Introduction
Delphi Object directly to a Json string in a REST Client
Delphi using Environment Variables in your App
Delphi FMX Leaflet Plotter using OSM Maps
C2PAS32 Convertor Application
C to Delphi Open Source Convertors Shootout

Categories

Bootstrap 4
Delphi VCL
Delphi FMX
Ajax
Bootstrap 3
CSS
XE4>Delphi > XE4
Delphi < XE4

Archives

October 2018

Delphi VCL Buttons in DBGrid
Two Helper Apps for Delphi LibUSB

September 2018

Delphi Libusb Library Introduction

August 2018

Delphi Object directly to a Json string in a REST Client
Delphi using Environment Variables in your App

July 2018

Delphi FMX Leaflet Plotter using OSM Maps

June 2018

C2PAS32 Convertor Application
C to Delphi Open Source Convertors Shootout
Delphi command-line programs with DOSCommand

May 2018

Delphi PDF Embedded viewer with PDF.js

March 2018

Delphi FMX - Changing TCharacter to TCharHelper
Make Your Delphi App POP using Javascript!

January 2018

Delphi FMX Dashboard using Chart.JS
Delphi FMX Form Docking

December 2017

PHP Slim REST Server & Delphi Auth Part 5

November 2017

Delphi FMX REST Client App Part 4

October 2017

Delphi VCL REST Pricing Client App Part 3

September 2017

Delphi REST VCL Client Basic Auth Part 2B

August 2017

Delphi REST Client Part 2A
PHP PDO REST Server Part 1

July 2017

PHP REST Server and Delphi Client Intro

June 2017

Delphi SQLite Encryptor-Decryptor Tool
Updating Applications Manifest using Delphi

May 2017

Create a Visual IP Address Geolocation with PHP

March 2017

PHP Downloader using Countdown timer
PHP File Downloader from a Inbox Selection

February 2017

Javascript Image-File Uploader with ThumbViewer

January 2017

Morris Charts and PHP-PDO

December 2016

CSS to create a functional Toggle Button