Hello, I'm a newbye in here and I would like to know how to run a command, when in a cmd.exe window in vista, without to go first in the directory where that command is located.

In other words, when I run cmd.exe it opens up in a default directory and some command cannot be run from there; only if I go to the directory where that command is located the command can run.

How that command may be run from any directory? I mean what have to be edit to get that please?


Cypherinfo.

Dani AI

Generated

Good question, . To run a tool from any folder, make sure the folder that contains it is listed in PATH. Windows also auto-tries the extensions in PATHEXT (so typing program1 runs program1.exe or program1.cmd, etc.). You can see which copy will run with the where command. (learn.microsoft.com)

About your follow-up: yes, %SystemRoot%\System32 (typically C:\Windows\System32) should be in the System PATH on Vista/7/8 by default. If it is missing, PATH was likely overwritten by an installer or by manually replacing it instead of appending. Restore it by adding %SystemRoot%\System32 back into the System PATH entry. (learn.microsoft.com)

A few tips that build on //:

  • Prefer editing System PATH for all users, or User PATH just for you. On Vista, if you are not an admin and only need a per-user change, use Control Panel > User Accounts > Change my environment variables. (learn.microsoft.com)
  • After changing PATH, open a new Command Prompt; processes read environment variables when they start. (learn.microsoft.com)
  • Command-line options: use set for the current window, or setx to make it persistent (add /M to write the System PATH). Be careful: on some builds, setx truncates very long values, so prefer the GUI if your PATH is already big. (learn.microsoft.com)
  • You rarely need to type the extension; PATHEXT controls which ones are tried and in what order. Defaults include .COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC. (learn.microsoft.com)

Handy commands you can use right now:

echo %PATH%
where program1
setx PATH "%PATH%;D:\programdir" /M
setx PATHEXT "%PATHEXT%;.PY"

Recommended Answers

All 4 Replies

If you are trying to run program1.exe (example) located in d:\programdir you have to add d:\programdir to the path variable. You can do this by rightclicking on computer then properties -> advanced system settings -> advanced -> environment variables. Make sure that you separate it by the entry in front of it by a semicolon. Now you should be able to type program1 in cmd.

I'm not fully sure what you're looking for.

If you browse in Windows Explorer to the folder where the program you want to run is located, shift+right-click and choose Open Command Window Here. You then are in a command window at that folder.

If you want to be able to open a command window directly, and be somewhere other than your home folder ( Users\your_user_name), you can create a shortcut to cmd.exe and change the Start In folder location.

Or even more simply you can just click

Start->run->cmd (click enter). Then the command window will open. From there lets say you are in the directory C:\Users\Kyle. Typing "cd .\Documents" will take you to the C:\Users\Kyle\Documents directory.

Short answer: use the "cd" command to change directory.

Or even more simply you can just click

Start->run->cmd (click enter). Then the command window will open. From there lets say you are in the directory C:\Users\Kyle. Typing "cd .\Documents" will take you to the C:\Users\Kyle\Documents directory.

Short answer: use the "cd" command to change directory.

Thank you all. Great community here! :-) To tell the truth the solution to make global the command folder is the best one for me. The point is: how ever that folder: c:\windows\system32 was not in the path variable after the vista installation?

I mean, after an installation, by default it has to be there or not?


Cypherinfo.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.