Tell me what you need to do, so that the program can be run by name through the console?

For example, if you write the word Skype in the CMD, Skype starts.

  • five
    the easiest option is probably to add the program path to the PATH environment variable, I don’t know how right it is. - pavel
  • @pavel: This is not a good idea. There may be other executable files in the program directory, and all of a sudden they will all be available without a path. This is probably not quite right. - VladD
  • 3
    Create a folder to add to PATH, and in this folder put batch file on the program. Then extra testers will not be available - vitidev

2 answers 2

When you write a command in the console, it is searched in directories from the PATH environment variable.

There are only two options.

Or add a directory with the program in the PATH - or put the program in the directory that already exists in the PATH.

  • Only in the root or also in the subdirectories? - iluxa1810
  • one
    @ iluxa1810 Why would it look in subdirectories? - Pavel Mayorov

The recommended Microsoft method is the App Paths registry key . When you enter a program name, it is searched in the working directory, in the Windows and Windows\System32 directories, in the directories listed in the PATH environment variable, and in the App Paths registry key.

To register only for the current user, use the key.

  HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\App Paths 

For global registration, use the same path, but in HKEY_LOCAL_MACHINE .

Let your program be called myapp.exe . Create a nested key myapp.exe in App Paths . Place a (Default) value of type REG_SZ containing the full path to the application. You can also specify other application launch options here. For example, you can make the directories of interest to you add to the value of the PATH environment variable when you start your program.

C # code:

 using System; using System.Linq; using System.Reflection; using Microsoft.Win32; namespace AppPathRegistration { class Program { static void Main(string[] args) { if (args.FirstOrDefault() == "/install") Install(); else Run(); } const string appPathsName = @"Software\Microsoft\Windows\CurrentVersion\App Paths"; static void Install() { var name = "lalafa.exe"; var path = Assembly.GetEntryAssembly().Location; using (var appPaths = Registry.CurrentUser.CreateSubKey(appPathsName)) using (var subkey = appPaths.CreateSubKey(name)) subkey.SetValue(null, path); } static void Run() { Console.WriteLine("Test application, press any key to finish..."); Console.ReadKey(intercept: true); } } } 

Please note that the name you are registering does not have to match the name of your program.

For other features, see the official documentation .


The App Paths registry key is taken into account when programs are started using ShellExecute / ShellExecuteEx functions. CreateProcess in the registry does not spy, and redirection will not find. But the Windows shell and the command line use exactly shell functions.


Here is a little history of this key (in English).