/AutoHotkey.docset/Contents/Resources/Documents/commands/_NoEnv.htm

https://gitlab.com/ahkscript/Autohotkey.docset · HTML · 32 lines · 29 code · 3 blank · 0 comment · 0 complexity · 5d922562f9267cae519dda6fd23e315f MD5 · raw file

  1. <!DOCTYPE HTML>
  2. <html>
  3. <head>
  4. <title>#NoEnv</title>
  5. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  6. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  7. <link href="../static/theme.css" rel="stylesheet" type="text/css" />
  8. <script src="../static/content.js" type="text/javascript"></script>
  9. </head>
  10. <body>
  11. <h1>#NoEnv <span class="ver">[v1.0.43.08+]</span></h1>
  12. <p>Avoids checking empty variables to see if they are environment variables (recommended for all new scripts).</p>
  13. <pre class="Syntax">#NoEnv</pre>
  14. <p>Specifying the line <code>#NoEnv</code> anywhere in a script prevents empty variables from being looked up as potential environment variables. For example:</p>
  15. <pre>#NoEnv
  16. MsgBox %WinDir%</pre>
  17. <p>The above would <strong>not</strong> retrieve the &quot;WinDir&quot; environment variable (though that could be solved by doing <code>WinDir := A_WinDir</code> near the top of the script).</p>
  18. <p>Specifying <code>#NoEnv</code> is recommended for all new scripts because:</p>
  19. <ol>
  20. <li>It significantly improves performance whenever empty variables are used in an expression or command. It also improves <a href="DllCall.htm">DllCall</a>'s performance when unquoted parameter types are used (e.g. int vs. &quot;int&quot;).</li>
  21. <li>It prevents script bugs caused by environment variables whose names unexpectedly match variables used by the script.</li>
  22. <li>AutoHotkey v2 will make this behavior the default.</li>
  23. </ol>
  24. <p>To help ease the transition to #NoEnv, the built-in variables <a href="../Variables.htm#ComSpec">Comspec</a> and <a href="../Variables.htm#ProgramFiles">ProgramFiles</a> have been added. They contain the same strings as the corresponding environment variables.</p>
  25. <p>When #NoEnv is in effect, the script should use <a href="EnvGet.htm">EnvGet</a> to retrieve environment variables, or use built-in variables like <a href="../Variables.htm#WinDir">A_WinDir</a>.</p>
  26. <h3>Related</h3>
  27. <p><a href="EnvGet.htm">EnvGet</a>, <a href="../Variables.htm#ComSpec">Comspec</a>, <a href="../Variables.htm#ProgramFiles">ProgramFiles</a>, <a href="../Variables.htm#WinDir">A_WinDir</a></p>
  28. </body>
  29. </html>