Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run Wpf application from CMD/Run like calc?

Tags:

c#

cmd

wpf

I want to provide my WPF application a custom command so I can start up it from command prompt by not writing it's name but by writing specific command like calc or appwiz.cpl. I have searched google for the same but it is taking me wrong like almost concepts are of command line argument but I am not looking for the same. Is there any possibility to start a custom application from command line or run utility. Thanks in advance.

like image 552
RaviKant Hudda Avatar asked Jun 07 '15 13:06

RaviKant Hudda


1 Answers

Yes. That can be done easily using Windows Registry. You can open any desired 3rd party program by just typing its name in RUN or Start menu Search box and press Enter.

You'll need to set the application path in Windows Registry so that Windows can know about the application at the time of execution.

  1. Type regedit in RUN or Start Menu search box and press Enter. It'll open Registry Editor.
  2. Now go to:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths

  1. Now we'll need to create a new key under "App Paths" key. Right-click on "App Paths" key and select "New -> Key". Set its name to your desired application name along with its extension e.g. My_Application.exe

  2. Select the key created in Step 3 and in right-side pane, set value of "Default" to the full path of application's EXE file e.g. C:\Program Files\My Application\My Application.exe

  3. Again in right-side pane, create a new String value "Path" and set its value to the folder containing your application EXE file e.g. C:\Program Files\My Application\

  4. That's it. Now you can launch your desired application by just typing its name in RUN or Start menu Search box.

NOTE: If you want a ready-made registry script to do the task automatically, then copy paste following code in Notepad and save the file with name "AskVG.REG" (including quotes).

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths]

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\My Application]
@="C:\\Program Files\\My Application\\My Application.exe"
"Path"="C:\\Program Files\\My Application\\"

You just need to replace BOLD part of the above script with the correct application name and path. After saving the file, run it and it'll add the program path to Registry so that you can launch it directly from RUN and Start menu Search box.

Edit: Based on your comment you can write the following action with C# code

like image 130
Marshal Avatar answered Nov 01 '22 17:11

Marshal