How to get an .exe file to execute no matter where the user types its name in command shell on windows 7?

4

I have Windows 7.

I have a .exe file here:

c:\tools\dailybackup.exe

When I am in the CMD window, I want to be able to type "dailybackup" in any directory and have it execute.

Do I still need to change the environment variables to do this or does Windows 7 have an easier more user-friendly way to do this now?

Edward Tanguay

Posted 2010-08-09T19:55:23.823

Reputation: 11 955

Answers

10

You still have to change the PATH environment variable to include c:\tools\

Nifle

Posted 2010-08-09T19:55:23.823

Reputation: 31 337

4

To add to Nifle's answer, to add to the PATH permanently:

setx path "%path%;c:\tools"

You need to close and start another CMD prompt to see the changes to PATH.

paradroid

Posted 2010-08-09T19:55:23.823

Reputation: 20 970

1

If you want to do this from ANY directory, then your only choice, as you've pointed out, is to modify the environment variables and add "c:\tools" to your System or current user's $PATH variable.

joyjit

Posted 2010-08-09T19:55:23.823

Reputation: 421

2On Windows, environment variables are delimited by surrounding percents, i.e. %PATH%, not a preceding dollar sign. – Hello71 – 2010-08-09T21:10:53.263

0

There are a couple of ways to get there from here. The simplest (and safest, depending on your comfort level where editing the registry is involved) is to use a batch file and place it in the \Windows folder. For example, your batch file (named "dailybackup.bat" for consistency), might contain the following:

@echo off
pushd
cd /d c:\utils
dailybackup.exe
popd

I use this method for a number of commands/processes that I regularly use at the DOS prompt.

Alternatively, you can create an "alias" for the executable in the registry. To do this, go to "HKLM\Software\Microsoft\Windows\CurrentVersion\App Paths". You'll see a whole lot of sub-keys here. What you want to do is add one for "dailybackup.exe". Right-click on "App Paths" and select "New" and "Key". Enter the key name (ending with .exe). (This is an opportunity to use a shortened version of the name, if you wish, such as "dbu.exe", for example. Anyway, enter your alias (we'll just go with "dailybackup.exe"). Now, in the right-hand pane, double click "Default" and enter the full path and name of your executable "c:\utils\dailybackup.exe". That's all there is to it. You're done with the registry. To use the new alias, you can hit (Windows Key)/R to get the "Run" box and enter your alias. For reasons which escape me, the alias won't work directly from a DOS prompt, but needs to be prefaced with "start", as in:

C:\Some\Random\Folder >START dailybackup

or, if you opted for a shorter alias:

C:\Some\Random\Folder >START dbu

BillP3rd

Posted 2010-08-09T19:55:23.823

Reputation: 5 353