<p>Vous pouvez capturer les variables d’environnement système avec un script VBS, but you need a bat script to actually change the current environment variables, so this is a combined solution.</p>
<p>Create a file named <code>resetvars.vbs</code> containing this code, and save it on the path:</p>
<p>`Set oShell = WScript.CreateObject(“WScript.Shell”)<br>
filename = oShell.ExpandEnvironmentStrings(“%TEMP%\resetvars.bat”)<br>
Set objFileSystem = CreateObject(“Scripting.fileSystemObject”)<br>
Set oFile = objFileSystem.CreateTextFile(filename, TRUE)</p>
<p>set oEnv=oShell.Environment(“System”)<br>
for each sitem in oEnv<br>
oFile.WriteLine("SET " & sitem)<br>
next<br>
path = oEnv(“PATH”)</p>
<p>set oEnv=oShell.Environment(“User”)<br>
for each sitem in oEnv<br>
oFile.WriteLine("SET " & sitem)<br>
next</p>
<p>path = path & “;” & oEnv(“PATH”)<br>
oFile.WriteLine(“SET PATH=” & path)<br>
oFile.Close</p>
<pre><code class="lang-auto">
create another file name resetvars.bat containing this code, same location:
`@echo off
%dp0resetvars.vbs
call "%TEMP%\resetvars.bat"
</code></pre>
<p>When you want to refresh the environment variables, just run <code>resetvars.bat</code></p>
<p><em>Apologetics</em>:</p>
<p>The two main problems I had coming up with this solution were</p>
<p><strong>a.</strong> I couldn’t find a straightforward way to export environment variables from a vbs script back to the command prompt, and</p>
<p><strong>b.</strong> the PATH environment variable is a concatenation of the user and the system PATH variables.</p>
<p>I’m not sure what the general rule is for conflicting variables between user and system, so I elected to make user override system, except in the PATH variable which is handled specifically.</p>
<p>I use the weird vbs+bat+temporary bat mechanism to work around the problem of exporting variables from vbs.</p>
<p><strong>Note</strong>: this script does not delete variables.</p>
<p>This can probably be improved.</p>
<p><strong>ADDED</strong></p>
<p>If you need to export the environment from one cmd window to another, use this script (let’s call it <code>exportvars.vbs</code>):</p>
<p>`Set oShell = WScript.CreateObject(“WScript.Shell”)<br>
filename = oShell.ExpandEnvironmentStrings(“%TEMP%\resetvars.bat”)<br>
Set objFileSystem = C</p>
<p><em>(Réponse tronquée)</em></p>