Solved

Reading an environment variable

Posted on 1999-01-12
22
474 Views
Last Modified: 2010-04-06
Hello folks!

I have VERY embarassing question ;-)

HOW DO I READ AN ENVIRONMENT VARIABLE IN DELPHI ?

Forgive me ;-)


GOMF
0
Comment
Question by:GOMF
  • 10
  • 8
  • 4
22 Comments
 
LVL 20

Expert Comment

by:Madshi
Comment Utility
Hi GOMF,

use this function...

function GetEnvVar(variable: string) : string;
begin
  SetLength(result,MAX_PATH+1);
  SetLength(result,GetEnvironmentVariable(pchar(variable),pchar(result),MAX_PATH));
end;

Example:   MessageBox(0,pchar(GetEnvVar('path')),'path=',0);

Regards, Madshi.
0
 

Author Comment

by:GOMF
Comment Utility
Dear Madshi,

Problem! I tested your suggestion, which worked. However
if I use Set Test=SOMETHING and run the suggestion with
Test then it doesn't work. Thirdly I wasn't beeing very
precise as to what I needed :-) (sorry)
Actually I need to know a variable from a browser
called HTTP_REFERER which gives me a path which is needed
in an ISAPI extentsion.
I was told that the HTTP_REFERER is an environment variable
however I don't think its is in the extend of what I think
is an environment-variable (me beeing dum ;-) )

GOMF.
0
 

Author Comment

by:GOMF
Comment Utility
Above ;-)

GOMF
0
 
LVL 20

Expert Comment

by:Madshi
Comment Utility
Hmmm. The function I gave you, works only for "Set" variables, that are set in dos (before starting windows) or for variables that are set by your own program.
Don't know how you can get other environment variables, if it is that, what you need.
Perhaps you should ask the writer of the browser, how to get this path...

Regards, Madshi.
0
 

Author Comment

by:GOMF
Comment Utility
Madshi,

asking Microsoft about anything isn't exactly a ballgame ;-)
IF I ever receive an answer its probably because they
released an MS Explorer 18.0 ;-) and the version I am using
is utterly outdated ;-)

GOMF
0
 

Author Comment

by:GOMF
Comment Utility
Adjusted points to 250
0
 
LVL 20

Expert Comment

by:Madshi
Comment Utility
Hmmm. Looks like a CGI environment variable, right?
I have no experience with CGI programming. Do you have Delphi4? Which CGI component are you using?
In the help for the CGI component that is being shipped with Delphi, there's a property called "environmentStrings", which could help you.

Regards, Madshi.
0
 

Author Comment

by:GOMF
Comment Utility
Madshi,

Well its not CGI, its ISAPI, but I if CGI components hold
environmentstrings, then ISAPI should too - if this
is not something that only exists in Delphi 4.
I use Delphi 3 (unfortunately :-))
I use Tsessions & TPageProducer, and I can't see
they hold any valuable information about the
environment variables.

Best wishes,

GOMF
0
 
LVL 20

Expert Comment

by:Madshi
Comment Utility
I've Delphi4, but unfortunately only the professional version, so I don't have any of these CGI/ISAPI/blabla components. And my help file only sais, "object not supported in this Delphi version". So I can't help you further...   :-(

Regards, Madshi.
0
 
LVL 44

Expert Comment

by:bruintje
Comment Utility
Hi GOMF,

Saw in the helpfile of the IE 18.0 Beta :O) that your HTTP_Referer is :

"Returns a string containing the URL of the original request when a redirect has occurred."

And indeed its in the Servervariables collection, but I will read on, and will be back on this question.

brUINTje.
0
 
LVL 44

Expert Comment

by:bruintje
Comment Utility
And they help us a hand with this one

You can iterate through each server variable name. For example, the following script prints out all of the server variables in a table:

<TABLE BORDER="1">

<TR><TD><B>Server Variable</B></TD><TD><B>Value</B></TD></TR>

<% For Each strKey In Request.ServerVariables %>

<TR><TD> <%= strKey %> </TD><TD> <%= Request.ServerVariables(strKey) %> </TD></TR>

<% Next %>

</TABLE>

I'm absolute no genie in this field so I guess this is some sort of Script piece to be placed in a HTML page.

Hope this helps you any further.
brUINTje
0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
LVL 44

Expert Comment

by:bruintje
Comment Utility
Well, looked at the TPageProducer component and saw in the derived TCustomePageProducer a few methods to retrieve content, contentfromstream and contentformstring, so I guess you have to look in there to retrieve your environment variable.

If you register for the helpfile of MS called MSDN this is the link you have to follow:

http://premium.microsoft.com/isapi/devonly/prodinfo/msdnprod/msdnlib.idc?theURL=/msdn/library/sdkdoc/iisref/vbob5vsj.htm

Hope this helps
:O)
brUINTje.
0
 
LVL 44

Expert Comment

by:bruintje
Comment Utility
Hi GOMF,

Think it's a piece of script to be placed into a ASP page, as I said I'm no expert in this field, but maybe I willl look into it further if the need may arise..

:O)
brUINTje.
0
 

Author Comment

by:GOMF
Comment Utility
bruintje,

Well then, we are getting closer ;-) Yes these are the
variables I need! And thanks! But this is only half-way
around the problem. Now I can read them in the browser,
thats neat, but my ISAPI extension needs the variables,
and your suggestion about ContentFromStream


The TStream contains a bunchs of properties and methods,
and to be frank I don't know my around that!

function ContentFromStream(Stream: TStream): string; override;

This is getting complex, I am upping the points for this.

GOMF
0
 

Author Comment

by:GOMF
Comment Utility
Adjusted points to 400
0
 
LVL 44

Expert Comment

by:bruintje
Comment Utility
Hi GOMF,

I'm currently at work so it have to wait till I'm home :O(.
But as a starter in the field of ISAPI, I can try to read in the variables out of the stream into your ISAPI extensions. Maybe you can mail me a few pieces of your code where the variables need to be read or where you goin' to use these.

email is mulbum@worldonline.nl

Maybe 10 hours from now I'll be back on this one, because it's getting interesting.
:O)
brUINTje.

0
 

Author Comment

by:GOMF
Comment Utility


bruintje,

This doesn't return anything

<A HREF = "http://<%= Request.ServerVariables("SERVER_NAME") %> "></A>



I wonder why ?

GOMF
0
 

Author Comment

by:GOMF
Comment Utility
bruintje,

This doesn't do it :(


GOMF
0
 
LVL 44

Expert Comment

by:bruintje
Comment Utility
Hi GOMF,

Could you send me some code fragments so I can start up a bit.

my email adress

mulbum@worldonline.nl

I will get back soon.
:O)
brUINTje
0
 
LVL 44

Expert Comment

by:bruintje
Comment Utility
Sorry for that second request my head is a bit spinning today............
0
 
LVL 44

Accepted Solution

by:
bruintje earned 400 total points
Comment Utility
Hi,

Well, I'm glad that the suggestions about the TWebRequest led you indirectly in the right direction.

:O)
bruintje.
0
 

Author Comment

by:GOMF
Comment Utility

Much obliged for the "stakes" you took to help me out there.


Best wishes!


GOMF
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
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…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

762 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

9 Experts available now in Live!

Get 1:1 Help Now