2

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.

2
  • 1
    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. Commented Mar 2, 2023 at 18:53
  • 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. Commented Mar 2, 2023 at 23:32

1 Answer 1

3

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

1
  • 1
    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. Commented Mar 3, 2023 at 7:41

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.