Every process in Windows has what’s known as an "environment block" that contains the process' environment variables and their values. Programmatically, you can display the environment variables for a process using the ::GetEnvironmentStrings() function.

But there is a much easier way to view the environment block for a process in the Visual Studio debugger. When you are stopped in the debugger, type $env=0 in the Immediate window. $env is what is known as a pseudo variable. After pressing enter, the debugger will display all the environment variables and their values for the process that you are debugging.

Here is the screen shot showing the Immediate window:

Immediate window showing $env=0

And here is what the Immediate window displays. You can see the list of the environment variables and their values for the process that I’m debugging.

=::=::\
=C:=C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE
ALLUSERSPROFILE=C:\ProgramData
APPDATA=C:\Users\%USERNAME%\AppData\Roaming
AVENGINE=C:\PROGRA~1\CA\SHARED~1\SCANEN~1
CommonProgramFiles=C:\Program Files\Common Files
COMPUTERNAME=%USERNAME%-TABLET
ComSpec=C:\Windows\system32\cmd.exe
FP_NO_HOST_CHECK=NO
HOMEDRIVE=C:
HOMEPATH=\Users\%USERNAME%
LOCALAPPDATA=C:\Users\%USERNAME%\AppData\Local
NUMBER_OF_PROCESSORS=2
OS=Windows_NT
PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC
PROCESSOR_ARCHITECTURE=x86
PROCESSOR_IDENTIFIER=x86 Family 6 Model 14 Stepping 8, GenuineIntel
PROCESSOR_LEVEL=6
PROCESSOR_REVISION=0e08
ProgramData=C:\ProgramData
ProgramFiles=C:\Program Files
PUBLIC=C:\Users\Public
SESSIONNAME=Console
SystemDrive=C:
SystemRoot=C:\Windows
TEMP=C:\Users\%USERNAME%\AppData\Local\Temp
TMP=C:\Users\%USERNAME%\AppData\Local\Temp
USERDOMAIN=DOMAIN
USERNAME=%USERNAME%
USERPROFILE=C:\Users\%USERNAME%
VisualStudioDir=C:\Users\%USERNAME%\Documents\Visual Studio 2008
VS90COMNTOOLS=C:\Program Files\Microsoft Visual Studio 9.0\Common7\Tools\
WecVersionForRosebud.1BD8=2
windir=C:\Windows
PATH=C:\Windows\system32;C:\Windows;c:\Program Files\Microsoft SQL Server\90\Tools\binn\;C:\Program Files\Microsoft Visual Studio 9.0\;
0

Caveats

This tip only works when debugging native C++ applications. It doesn’t work for C#, VB.NET or C++/CLI.