Obscure #Windows question: After restarting explorer.exe, is there a way to force it to refresh environment variables from the registry? Or, a way to restart Explorer in a way that it picks up the latest ones from the registry on its own, rather than from when I last restarted the computer which was... ahem... December.
The answer is yes. Quit Explorer, run cmd from Task Manager, do a refreshenv command, then start Explorer from cmd instead of Task Manager. Will there be unintended side effects of starting my shell from a command prompt that is now closed? Who knows.
@jscholes This must be Windows 11, as my Cmd in Windows 10 doesn't know what refreshenv is.
@jaybird110127 Hmm. It is Windows 10, so that's a bit of a mystery.
@jscholes @jaybird110127 I'm also in win10 and typed 'refreshenv' to see what happened, and it happened just fine.
@jaybird110127 Ah, looks like that command comes from having Chocolatey installed.
@jscholes good ol' windows
@jscholes Nah, shouldn't be, just typing 'start explorer' is usually fine to close the shell after.
@jscholes I didn't realize how fiddly environment variables were until I added GPTCMD to my path, tried to assign a hotkey in my ancient autoit launcher, and found the launcher wasn't picking up the new path variable and GPTCMD wasn't picking up my openai_api_key. Eventually realized the actual problem was my long-running xplorer^2 instance, which I was using to manually restart the launcher. This whole process felt oddly reminiscent of trying to fix Linux. I usually don't see Explorer itself fall over though. If the run dialog invokes cmd, and cmd picks up on the new environment every time it's relaunched, I wonder why that works.
@simon My understanding is: If launched from the Run dialog which is a component of explorer.exe, cmd.exe inherits env vars from explorer.exe. If Explorer's environment is outdated, so will cmd's be.
Which is the exact frustration I've been running into. I restart Explorer, open a command prompt, and can't use environment variables correctly that were created or modified since I last logged in without forcing it via the refreshenv command.
When I launch Task Manager with Ctrl+Shift+Escape, that keyboard shortcut isn't handled by Explorer at all, but a lower-level system process. That process has the old, outdated environment that it read from the registry when I logged in like four months ago.
@simon Having said that: If I restart Explorer from a Task Manager instance that I launched from the Run dialog, the new Explorer process also gets an outdated environment. So it's possible that Task Manager creates processes in such a way that causes them not to inherit Task Manager's own environment.
@jscholes I wonder if the ctrl alt delete / alt+t task manager is any different since that's launched by something on the secure screen.
@jscholes That's really strange, because if I update the environment and relaunch cmd, it seems to handle that just fine. I've never experienced being stuck with an outdated environment. But when I think about the way Windows passes the environment onto subprocesses, I now have no idea why. Your scenario seems like what should happen, it's just definitely not what happens here. There is a registry hack to automatically run a batch file when cmd starts, so you could always do that as a permanent fix. I used this to add aliases, because I couldn't find a better way.
@simon If you don't restart Explorer between updating the environment and launching cmd, the results you're seeing are expected. Windows sends appropriate messages to applications to let them know the environment has changed, and Explorer seems to take notice of those.
@simon Or to put it another way, the following works fine: Update environment, launch cmd, use new environment. What doesn't work is: Update environment, restart Explorer, launch cmd, use new environment.
@jscholes That seems very counterintuitive because if explorer receives the message about the updated environment, shouldn't it pass it onto taskmgr, which would pass that onto the new explorer?
@simon Sure. Hence my comment that taskmgr must create processes in such a way that results in them not receiving taskmgr's environment at all. Maybe for security, maybe by accident.
@simon Really, the Explorer restart is a red herring. The minimal repro steps are:
1. Make a new environment variable.
2. Launch Task Manager; the specific method doesn't seem to matter.
3. Use File -> Run new task to launch cmd.
4. Try to echo your new variable.
I claim that it won't work, even though launching cmd from the Run dialog and then echoing the new variable will.
@jscholes huh. I think my record for days without reboot is like 47 or so, usually around the 30-40 mark random things start getting really odd
@zstg for one, these aren't servers, and for second
https://github.com/calamares/calamares/issues/470
https://www.reddit.com/r/linux/comments/1ed0j10/the_state_of_accessibility_is_worse_than_i/
https://scribe.rip/@r.d.t.prater/linux-accessibility-an-unmaintained-mess-8fbf9decaf8a
I'm good, thanks. Things are, very, very, slowly, improving, but I actually need to get stuff done while all this is happening soooo ...