DEV Community

loading...
Cover image for Want to run your exe from just anywhere on your computer?

Want to run your exe from just anywhere on your computer?

pradeepradyumna profile image Pradeep Pradyumna Updated on ・3 min read

Wouldn't it be cool, if we were able to launch an exe that we built/ saved in a particular folder in say F:\ drive be runnable even outside that folder or anywhere you want by typing just the exe name and not including the entire path referencing to it? 😀

And by "anywhere" I mean, you can launch your application
From start menu (shortcut - Windows key)
From Run command dialog box (shortcut - Windows + r)
By typing application name in Windows Address bar of any drive/ folder on your computer
By typing application name from a command prompt opened from any drive/ folder directly without worrying to change the directory.

Sounds interesting?

For demonstration purposes, I have built a very basic C# .NET console application with the name "SayMyName" which outputs the currently logged-in username.

using System;

namespace SayMyName
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine(Environment.UserName.ToUpper());
            Console.ReadLine();
        }
    }
}
Enter fullscreen mode Exit fullscreen mode

The output path of this application is
T:\MyExe\SayMyName\SayMyName\bin\Debug\SayMyName.exe

Just make a copy of your exe's path looking like this on a notepad and that's it. It is all you need and we are very much good to go!

We will be basically doing two things here to let our computer know about this application.
One, registering the path to exe in the system registry HKLM
Two, registering the path to exe in PATH environment variable

Step 1

Open windows registry and go to HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths

Step 2

Right-click on App Paths and add a Key with the name saymyname.exe.

Step 3

On the right side, you see the (Default) value name? Right-click on it click Modify.... Now copy-paste the path T:\MyExe\SayMyName\SayMyName\bin\Debug\SayMyName.exe and click OK. Now add one more value, by right-clicking -> New -> String value and name it Path and set its data value to the exe's containing folder followed by a semicolon i.e. T:\MyExe\SayMyName\SayMyName\bin\Debug;

You're almost done! These steps will enable your application to be accessible via the Windows Address bar of any drive and folder, start menu, and Run box.

For ease, you can find the .reg file here, which I have customized. You can just download, edit, and import it into your registry.

Now, perform just this one last step to make your application accessible from any command prompt anywhere. 😁

Step 4

Now go to the Environment Variable window. You can do this by, right-click 'This PC'->Properties-> Advance System Properties->System properties-> Advanced Tab. There you can find the 'Environment Variables...' button. Just smash it!

You will find Path variable under the 'User variables' section. Edit it. In the variable value, copy-paste the path T:\MyExe\SayMyName\SayMyName\bin\Debug; and click OK.

That's it! There you go. You just made your application a global star on your computer. You can call it from anywhere now with just the name.

Like this 😎
outcome

There is also a tutorial demonstrating the same and it is available here. 👍

Thanks for reading! 💛

Discussion (0)

pic
Editor guide