Discussion:
Environment variable
(too old to reply)
Peter
2008-06-04 23:29:31 UTC
Permalink
Hi,

It was suggested to me to test for a particular environment variable to test
for a certain condition.
The information was limited and I couldn't immediately vadem how I could
check an undefined variable ... until I released it must be an environment
variable set in the OS.
However, I have no idea how to test that in the software ?
Is there a function for that ?

Thanks.
Remy Lebeau (TeamB)
2008-06-05 00:57:37 UTC
Permalink
Post by Peter
It was suggested to me to test for a particular environment variable
to test for a certain condition.
That is a bit too vague. Can you be more specific?
Post by Peter
The information was limited and I couldn't immediately vadem
how I could check an undefined variable ... until I released it
must be an environment variable set in the OS.
However, I have no idea how to test that in the software ?
Is there a function for that ?
What EXACTLY are you trying to test? Please provide an example.


Gambit
Peter
2008-06-05 12:02:04 UTC
Permalink
Post by Remy Lebeau (TeamB)
Post by Remy Lebeau (TeamB)
What EXACTLY are you trying to test? Please provide an example.
I have no idea, that's my point.
All the documentation states (without any example available) is to test for
an environment variable !
If it is present, certain third party software is running. This is the only
information I have myself.

I have been thinking about what it could mean and the only thing that comes
to mind is the environment variables that are set in the OS.
So when you open a DOS box, and issue the command 'SET' you get all the
environment variables and their value !
So I suppose I need a way to get that list in the software, or simply one of
the values in the list.

For test purposes, let's assume I need the value of SYSTEMDRIVE (first see
if it is present, and if so, the value of it)

The environment variable is set in a virtual environment. So I can't test
it easily right now. I am going to try and run cmd.exe in the virtual
environment to see if I got it right. Once my software is able to test for
that value, it can run in that virtual environment as well.



------------------------------------------------------------------
Post by Remy Lebeau (TeamB)
Post by Remy Lebeau (TeamB)
It was suggested to me to test for a particular environment variable
to test for a certain condition.
That is a bit too vague. Can you be more specific?
Post by Remy Lebeau (TeamB)
The information was limited and I couldn't immediately vadem
how I could check an undefined variable ... until I released it
must be an environment variable set in the OS.
However, I have no idea how to test that in the software ?
Is there a function for that ?
What EXACTLY are you trying to test? Please provide an example.
Gambit
Peter
2008-06-05 13:40:26 UTC
Permalink
Post by Peter
So when you open a DOS box, and issue the command 'SET' you get all the
environment variables and their value !

So the question then is, how do I test for these variables in my program ?
chenzero
2008-06-05 14:48:42 UTC
Permalink
Post by Peter
Post by Peter
So when you open a DOS box, and issue the command 'SET' you get all the
environment variables and their value !
So the question then is, how do I test for these variables in my program ?
Hi Peter,
maybe following API is what you looking for. more details can be
found on MSDN.
http://msdn.microsoft.com/en-us/library/ms683188(VS.85).aspx

char buf[1000];
GetEnvironmentVariable("SystemDrive", buf, 1000);
ShowMessage(buf);

char* v = getenv("SystemDrive");
ShowMessage(v);
Remy Lebeau (TeamB)
2008-06-05 17:23:52 UTC
Permalink
Post by Peter
I have been thinking about what it could mean and the only
thing that comes to mind is the environment variables that
are set in the OS.
That is exactly what it is referrring to.
Post by Peter
So when you open a DOS box, and issue the command 'SET'
you get all the environment variables and their value ! So I
suppose I need a way to get that list in the software, or simply
one of the values in the list.
Both the Win32 API and the VCL have GetEnvironmentVariable() functions.
Post by Peter
For test purposes, let's assume I need the value of SYSTEMDRIVE
(first see if it is present, and if so, the value of it)
#include <SysUtils.hpp>

AnsiString SystemDrive = GetEnvironmentVariable("SYSTEMDRIVE");
if( SystemDrive != "" )
{
//...
}


Gambit
Peter
2008-06-06 13:22:18 UTC
Permalink
Post by Remy Lebeau (TeamB)
Both the Win32 API and the VCL have GetEnvironmentVariable() functions.
Thanks Gambit and chenzero, I got it to work

Continue reading on narkive:
Loading...