Solved

how to get environment variables in delphi3

Posted on 1998-12-01
5
264 Views
Last Modified: 2010-04-04
How can I get the environment variables (e.g.: PATH or USERNAME) in a Delphi3-program ??? What is the function therfor?
0
Comment
Question by:pman
  • 3
  • 2
5 Comments
 

Accepted Solution

by:
mtieland earned 50 total points
ID: 1348746
The solution is as follows:

uses Windows

function TForm1.GetEnvVar(EnvName : EnvInp):string;
var EnvBuffP : array [0..255] of Char;
begin
   EnvBuffP:='';
   GetEnvironmentVariable(EnvName,EnvBuffP,30);
   GetEnvVar:=EnvBuffP;
end;

Good Luck

Martijn
0
 

Expert Comment

by:mtieland
ID: 1348747
Forgot to tell you:

how to use the function:
type SET in a dosbox to find out the names of the EnvVars

Lets say you want the username:

var UserName : String;

UserName:=GetEnvVar('USERNAME');

Good Luck
0
 
LVL 3

Expert Comment

by:williams2
ID: 1348748
..Wouldn't it be nice to now, which variables were available?

/Williams
0
 

Expert Comment

by:mtieland
ID: 1348749
That was not the question I think? Williams
0
 
LVL 3

Expert Comment

by:williams2
ID: 1348750
I know, that's why I asked pman. Maybe he didn't know it was possible :-)

Relax Martijn ..You answered his question, so you well enough deserve the credits!

/Williams
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

756 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question