Delphi Basics Home  |  Delphi Basics .NET Home  |  System.Environment  |  GetEnvironmentVariable Method
GetEnvironmentVariable  
Method  
Gets a single environment variable, by name
Environment Class
System NameSpace
NotCF1.  Function GetEnvironmentVariable ( Name : String ) : String; Static;
CF : Methods with this mark are Compact Framework Compatible
Description
Returns a single environment variable, by name.
 
The name must be be one of the following :
 
ALLUSERSPROFILE
APPDATA
BDS
CLIENTNAME
CommonProgramFiles
COMPUTERNAME
ComSpec
Cor_Debugging_Control_424242
DBCONFIG
DBROOT
DBWORK
HOMEDRIVE
HOMEPATH
INCLUDE
LIB
LOGONSERVER
NUMBER_OF_PROCESSORS
OS_ROOTDIR
OS_TMPDIR
OS
Path
PATHEXT
PROCESSOR_ARCHITECTURE
PROCESSOR_IDENTIFIER
PROCESSOR_LEVEL
PROCESSOR_REVISION
ProgramFiles
SESSIONNAME
SystemDrive
SystemRoot
TEMP
TMP
USERDOMAIN
USERNAME
USERPROFILE
windir
Microsoft MSDN Links
System
System.Environment
System.Environment.GetEnvironmentVariable
 
A simple example
program Project1;
{$APPTYPE CONSOLE}

var
  userName, computerName : String;

begin
  // Display the computer name and user name
  userName     := Environment.GetEnvironmentVariable('USERNAME');
  computerName := Environment.GetEnvironmentVariable('COMPUTERNAME');

  Console.WriteLine('You are {0} logged on to {1}',
                    userName, computerName);

  Console.ReadLine;
end.
   You are Thomas logged on to DEVELOPMENT
 
© CodeGear 2006 - 2007. All rights reserved.