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.
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.
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.
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).
Source: https://ru.stackoverflow.com/questions/575040/
All Articles