Freigeben über


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.