![]() When you want to refresh the environment variables, just run resetvars.bat Set oFile = objFileSystem.CreateTextFile(filename, TRUE)Ĭreate another file name resetvars.bat containing this code, same location: off Set objFileSystem = CreateObject("Scripting.fileSystemObject") You can capture the system environment variables with a vbs script, but you need a bat script to actually change the current environment variables, so this is a combined solution.Ĭreate a file named resetvars.vbs containing this code, and save it on the path: Set oShell = WScript.CreateObject("WScript.Shell")įilename = oShell.ExpandEnvironmentStrings("%TEMP%\resetvars.bat") SET "PROCESSOR_ARCHITECTURE=%OriginalArchitecture%" SET "OriginalArchitecture=%PROCESSOR_ARCHITECTURE%" :: Caution: do not insert space-chars before > redirection signĮcho/set "Path=%%Path_HKLM%% %%Path_HKCU%%" > "%TEMP%\_env.cmd" :: Special handling for PATH - mix both User and SystemĬall :SetFromReg "HKLM\System\CurrentControlSet\Control\Session Manager\Environment" Path Path_HKLM > "%TEMP%\_env.cmd"Ĭall :SetFromReg "HKCU\Environment" Path Path_HKCU > "%TEMP%\_env.cmd" "%WinDir%\System32\Reg" QUERY "%~1" > "%TEMP%\_envget.tmp"įor /f "usebackq skip=2" %%A IN ("%TEMP%\_envget.tmp") do (Ĭall :GetRegEnv "HKLM\System\CurrentControlSet\Control\Session Manager\Environment" > "%TEMP%\_env.cmd"Ĭall :GetRegEnv "HKCU\Environment">"%TEMP%\_env.cmd" > "%TEMP%\_env.cmd" :: Get a list of environment variables from registry :: Set one environment variable from registry key ::echo "RefreshEnv.cmd only works from cmd.exe, please install the Chocolatey Profile to take advantage of refreshenv from PowerShell"Įcho | set /p dummy="Refreshing environment variables from registry for cmd.exe. :: environment every time you want environment changes to propagate :: With this batch file, there should be no need to reload command ![]() ![]() ![]() :: set session variables to these values. :: Batch file to read environment variables from registry and ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |