53

What is difference between %Windir% and %Systemroot% in Windows Path Location?
Both of them show "Windows" folder location.

3 Answers 3

51

To expand upon Mr. Dave’s answer, %SystemRoot% is a built-in variable (along with a small handful of others like %SystemDrive%). That is, it is not actually defined in the environment variable store at HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment in the registry.

On the other hand, %windir% is a regular variable and is defined in the variable store as %SystemRoot%. (There is no “real variable” counterpart to %SystemDrive%.)

Which to use doesn’t really matter, but you may run into problems with variable expansion in batch-files, in which case you could try the other one. (I don’t recall having problems with this specifically, but it’s worth keeping in mind.)

In addition, %SystemRoot% (and %SystemDrive%) are set during the installation process (when you choose the destination drive) and is thus available from the earliest point when Windows is being installed whereas %windir% is set at a later point during the install, so if you are creating some sort of custom installation (e.g., OEM, PE, etc.), you will want to use %SystemRoot%.

4
  • So, %windir% built AFTER installation? Aug 29, 2013 at 17:18
  • 4
    No, during installation, but after %SystemRoot%. Windows has enough information to set SystemDrive and SystemRoot as soon as you choose the drive where to install it (plus it uses a default if you don’t modify the destination). It sets several default environment variables (including windir) later in the installation when it initializes the registry. This only matters if you are modifying the installation process.
    – Synetech
    Aug 29, 2013 at 17:25
  • 1
    in which case you could try the other one. I assume the other one is %windir%. Is that correct? Sep 13, 2019 at 11:52
35

On Win 7 %SystemRoot% is a read-only system variable while %windir% can be changed and is set by default as windir=%SystemRoot% . The OS relies on %SystemRoot%. According to Wikipedia, %WinDir% pre-dates Windows NT and seems to be superseded by %SystemRoot%.

0

For maximum batch compatibility %windir% is preferable (ie: running in an old windows on a virtual machine). %windir% will also work on win 3.11, win95, win95 and winME. Otherwise they are basically the same.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .