Solved

how to get environment variables in delphi3

Posted on 1998-12-01
5
249 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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

708 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now