Bill Wert's weblog

Striving to make managed code fast...

Tip: Don't rely on environment variables for critical decisions

I saw a mail this week asking how you can determine what bitness your process is running in, and one of the suggestions was to check for the PROCESSOR_ARCHITEW6432 environment variable. If that variable exists, you know you're on 64 bit Windows in a 32 bit process. It's likely that the questioner needs to know which bitness the application is running in so the correct bitness DLL can be loaded, since by default native code is processor agnostic.

This is one example, but the broader point really is that you shouldn't rely on environment variables as proof of things important to your application. It is too easy for someone to intentionally or accidentally corrupt your environment and cause your program to function incorrectly. Please don't do this in shipping code.

Published Sunday, February 24, 2008 6:35 PM by billwert
Filed under:

Comments

No Comments
Anonymous comments are disabled

© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Microsoft
Page view tracker