IIS and Environment Variables

IIS and Environment Variables

am 19.09.2007 15:02:17 von gilad

Hi,
Is it possible to get the updated environment variables in an IIS
application (ISAPI for example) ? The problem is that IIS get the
environment variables when the computer restarts and does not lookup
for updated values.

Thanks,
Gilad.

Re: IIS and Environment Variables

am 19.09.2007 15:20:15 von tiago.halm

IIS, as any other rexecutable, is tipically started with a copy of the
environment variables of the parent process. Since IIS is a windows
service, it gets a copy of the environment variables at start time.
If, inside an ISAPI that runs inside an AppPool (w3wp.exe), you update
a certain environment variable, the ISAPI can read the updated value.

Now, if your question is about changing an environment variable on
another process, and expect IIS to have this variable updated, then
no. Imagine opening 2 command prompts, and setting an environment
variable in one of them:
> set foo=bar
The other command prompt will not *see* this environment variable,
because each process has its own snapshot of the environment variables
at start time.

There are of course exceptions. You can start a process with a
determined set of environment variables of your choosing but that
involves the registry, and is a bit messy.

Now ... in hacking terms, you can always have your ISAPI be *notified*
by another process to update a certain environment variable with a
certain value. But I believe this is already outside of your original
scope.

Tiago Halm

Re: IIS and Environment Variables

am 20.09.2007 12:20:30 von David Wang

On Sep 19, 6:02 am, gilad wrote:
> Hi,
> Is it possible to get the updated environment variables in an IIS
> application (ISAPI for example) ? The problem is that IIS get the
> environment variables when the computer restarts and does not lookup
> for updated values.
>
> Thanks,
> Gilad.


Not possible.

IIS is an NT Service and inherits its environment variables from
services.exe, which does not update its environment variables without
a reboot of the system. It is hardly a problem because the idea that a
process should poll for updated values (that's what you mean by lookup
for updated values) is quite out of the question. Please come up with
a better way to communicate configuration/values between processes -
passing it through the Environment is a legacy idea.

You may be able to get IIS to load up user profiles, which would
contain user environment changes, but that's for IIS7.


//David
http://w3-4u.blogspot.com
http://blogs.msdn.com/David.Wang
//

Re: IIS and Environment Variables

am 20.09.2007 12:23:26 von David Wang

On Sep 20, 3:20 am, David Wang wrote:
> On Sep 19, 6:02 am, gilad wrote:
>
> > Hi,
> > Is it possible to get the updated environment variables in an IIS
> > application (ISAPI for example) ? The problem is that IIS get the
> > environment variables when the computer restarts and does not lookup
> > for updated values.
>
> > Thanks,
> > Gilad.
>
> Not possible.
>
> IIS is an NT Service and inherits its environment variables from
> services.exe, which does not update its environment variables without
> a reboot of the system. It is hardly a problem because the idea that a
> process should poll for updated values (that's what you mean by lookup
> for updated values) is quite out of the question. Please come up with
> a better way to communicate configuration/values between processes -
> passing it through the Environment is a legacy idea.
>
> You may be able to get IIS to load up user profiles, which would
> contain user environment changes, but that's for IIS7.
>
> //Davidhttp://w3-4u.blogspot.comhttp://blogs.msdn.com/David. Wang
> //


And everything Tiago says about the environment and IIS's interaction
stands. Only the part with IIS7 now optionally loading user profiles
which can give the appearance of updated environment is new.


//David
http://w3-4u.blogspot.com
http://blogs.msdn.com/David.Wang
//