#NoEnv [v1.0.43.08+]

Avoids checking empty variables to see if they are environment variables (recommended for all new scripts).

#NoEnv

Specifying the line #NoEnv anywhere in a script prevents empty variables from being looked up as potential environment variables. For example:

#NoEnv
MsgBox %WinDir%

The above would not retrieve the "WinDir" environment variable (though that could be solved by doing WinDir := A_WinDir near the top of the script).

Specifying #NoEnv is recommended for all new scripts because:

  1. It significantly improves performance whenever empty variables are used in an expression or command. It also improves DllCall's performance when unquoted parameter types are used (e.g. int vs. "int").
  2. It prevents script bugs caused by environment variables whose names unexpectedly match variables used by the script.
  3. AutoHotkey v2 will make this behavior the default.

To help ease the transition to #NoEnv, the built-in variables ComSpec and ProgramFiles have been added. They contain the same strings as the corresponding environment variables.

When #NoEnv is in effect, the script should use EnvGet to retrieve environment variables, or use built-in variables like A_WinDir.

Like other directives, #NoEnv cannot be executed conditionally.

EnvGet, ComSpec, ProgramFiles, A_WinDir