If you need to test for the existance of an environment variable, you might consider using:

if not "%var%"

"" @echo var=%var%

While this works, a better method is:

if defined var @echo var=%var%

Try this little test:

                              @echo off                              setlocal                              if not "%var%""" @echo line 3 %var%                              if defined var @echo line 4 %var%                              set var=hello world                              if not "%var%"=="" @echo line 6 %var%                              if defined var @echo line 7 %var%                              endlocal