Score:2

How does Windows set the %SystemRoot% variable?

in flag

The %SystemRoot% environment variable contains the path to the Windows directory. (e.g. c:\windows)

SystemRoot is not configured in Computer\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment, it is automagically set.

Now, typically on Windows 10 this directory has the caseing C:\Windows on NTFS disk.

After a script test(*) broke, we noticed:

  • With same OS version Windows 10 (LTSC 1809 17763.3887)
  • Some boxes use %SystemRoot% == C:\WINDOWS (all uppercase, despite the directory on-disk being C:\Windows)
  • Some boxes use %SystemRoot% == C:\Windows (case of dir on disk)
  • We cross checked with ProcessExplorer: The casing difference is already present in the environment block of the wininit.exe process, so it's not overridden somewhere.

Q:

Is the base for the value of SystemRoot read from any specific registry key?

What could explain this difference?


(*): To be clear, the test was broken anyway - thou shall not rely on path casing on Windows.

cn flag
One explanation for the difference is it really doesn't matter. Windows in general and paths specifically are not case sensitive, so there is no impact to the operating system or native commands.
mfinni avatar
cn flag
The OS and filesystem case-AWARE but not case-SENSITIVE. Of course, anyone could choose to make a given script be case-sensitive, which as OP said, appears to be what they accidentally did.
Score:3
cn flag

It's set in the boot process. It's not set in the registry, because the OS boot process needs to know where to find the registry files (and other OS files) before it can read them from the registry.

https://learn.microsoft.com/en-us/windows-hardware/drivers/devtest/boot-options-in-windows

Windows boot options are stored in the Boot Configuration Data (BCD) store on BIOS-based and EFI-based computers.

PS C:\> bcdedit.exe /enum | select-string "device|root"

device                  partition=\Device\HarddiskVolume1
device                  partition=C:
osdevice                partition=C:
systemroot              \WINDOWS

PS C:\> $env:systemroot
C:\WINDOWS

On older Windows OS, it's probably in boot.ini

Martin avatar
in flag
Thanks. This is exactly it. One machine reports systemroot `\WINDOWS` and the other `\Windows`. Doesn't make a whole lot sense to me, but there it is.
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.