<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-1632085368384154" crossorigin="anonymous"></script><script src="https://autohotkey.top/gtag.js"></script></head> <body> <h1>EnvGet</h1> <p>检索环境变量.</p> <pre class="Syntax">Value := <span class="func">EnvGet</span>(EnvVarName)</pre> <h2 id="Parameters">参数</h2> <dl> <dt>EnvVarName</dt> <dd> <p>类型: <a href="../Concepts.htm#strings">字符串</a></p> <p>要检索的<a href="../Concepts.htm#environment-variables">环境变量</a>的名称. 例如: <code>Path := EnvGet("Path")</code>.</p> </dd> </dl> <h2 id="Return_Value">返回值</h2> <p>类型: <a href="../Concepts.htm#strings">字符串</a></p> <p>函数返回指定的环境变量的值. 如果指定的环境变量为空或不存在, 则返回空字符串.</p> <h2 id="Remarks">备注</h2> <p>操作系统限制每个环境变量的文本最多为 32 KB.</p> <p>此函数的存在是因为<a href="../Variables.htm">普通脚本变量</a>没有存储在环境变量中. 这是因为性能会变差, 也因为操作系统将环境变量限制为 32 KB.</p> <h2 id="Related">相关</h2> <p><a href="EnvSet.htm">EnvSet</a>, <a href="../Concepts.htm#environment-variables">环境变量</a>, <a href="Run.htm">Run</a>, <a href="Run.htm">RunWait</a></p> <h2 id="Examples">示例</h2> <div class="ex" id="ExBasic"> <p><a class="ex_number" href="#ExBasic"></a> 检索一个环境变量, 并将其值存储在 <var>LogonServer</var>.</p> <pre>LogonServer := EnvGet("LogonServer")</pre> </div> <div class="ex" id="ExProgramFiles"> <p><a class="ex_number" href="#ExProgramFiles"></a> 检索并报告 "Program Files" 目录的路径. 有关替代方法, 请参阅 <a href="RegRead.htm#ExProgramFiles">RegRead 示例 #2</a>.</p> <pre>ProgramFilesDir := EnvGet(<a href="../Variables.htm#Is64bitOS">A_Is64bitOS</a> ? "ProgramW6432" : "ProgramFiles") MsgBox "Program files are in: " ProgramFilesDir</pre> </div> <div class="ex" id="ExLocalAppData"> <p><a class="ex_number" href="#ExLocalAppData"></a> 检索并报告当前用户的本地 AppData 目录.</p> <pre>LocalAppData := EnvGet("LocalAppData") MsgBox A_UserName "'s Local directory is located at: " LocalAppData</pre> </div> <a href="https://dftg.net">dftg</a><!-- Cloudflare Pages Analytics --><script defer src='https://static.cloudflareinsights.com/beacon.min.js' data-cf-beacon='{"token": "d5a9c4fcb9b6482fa53ce820d892f969"}'></script><!-- Cloudflare Pages Analytics --><script defer src="https://static.cloudflareinsights.com/beacon.min.js/vcd15cbe7772f49c399c6a5babf22c1241717689176015" integrity="sha512-ZpsOmlRQV6y907TI0dKBHq9Md29nnaEIPlkf84rnaERnq6zvWvPUqr2ft8M1aS28oN72PdrCzSjY4U6VaAw1EQ==" data-cf-beacon='{"rayId":"92d7be252ecf86da","version":"2025.3.0","r":1,"serverTiming":{"name":{"cfExtPri":true,"cfL4":true,"cfSpeedBrain":true,"cfCacheStatus":true}},"token":"51750bb5dc4f40cc91a5ec55c63bbc01","b":1}' crossorigin="anonymous"></script> </body> </html>