1

I am trying to run the command %windir% in a command prompt, but I am getting an below error:

enter image description here

  • 6
    Short answer: %windir% isn't a command. Its just a Windows built-in environment variable. %windir% contains the path where your Windows directory resides in. Likewise, %homedrive% contains the drive that windows is installed in. – Don't Root here plz... Sep 10 '16 at 13:40
  • 8
    The real question is: Why were you trying to 'run %windir%? What did you think would happen? – underscore_d Sep 10 '16 at 19:52
12

Strangely enough, no one has explained the entire story, i.e. the error.

Indeed %windir% is an variable, and its contents on your system are C:\Windows.
So when you 'execute' %windir% its contents are substituted and your command is C:\Windows, which, as Windows informs you is not recognized as an internal or external command, operable program or batch file.

A fun experiment would be to place an executable named windows.exe in your C:\ root ;-)

| improve this answer | |
  • For the fun experiment (which works as expected) +1 – DavidPostill Sep 11 '16 at 11:22
  • windows.com, windows.vbs, windows.bat... also works – phuclv Nov 24 '17 at 13:24
23

%windir% is a variable and should be used in conjunction with standard commands or actions.

For example CD %WINDIR% will take you to the windows directory...

| improve this answer | |
4

You must be used to a different shell (in particular 4DOS/4NT/TakeCommand) where a directory name is treated as a command to change to that directory. That’s not the case with CMD, and you have to use CD before it (if it is already on the same drive. I don’t know if CMD has cdd command to change drive and directory).

| improve this answer | |
  • 4
    no cdd, just add /d – Uberfuzzy Sep 10 '16 at 16:18
0

when you do %windir% you are meant to use it with other commands with it. so that is why there is an error. for example if you do cd %windir%, you will not get an error

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.