Run Wpf application from CMD/Run like calc? - c#

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.

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.
Type regedit in RUN or Start Menu search box and press Enter. It'll
open Registry Editor.
Now go to:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths
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
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
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\
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

Related

Programmatically changing assembly (application) name?

I have a WPF project running on Windows 7 Embedded & Windows 8 Pro. In the taskbar when the application is pinned and I right-click the application icon, the C# project name pops up. Is there a way to change this name programmatically?
I want to load the application name from an .ini file at run-time.
UPDATE:
I have prior to asking this question searched and reviewed the other question that asks a similar, but different question on how to change the file name after compilation. I do not want to change the file name, just the name on the taskbar after right-clicking the application icon that is pinned.
I would say there is no "easy" way to do it, necessarily.
I would assume you have to run some sort of script or use Powershell.
Using method ?, create or rename a shortcut to your .exe with the name you want to show up in the pinned application.
Start the application using the shortcut. (At this point the "application name" in the task bar is the name of the shortcut used to launch your .exe)
Pin the application.
Shortcut is added to AppData, and the application will remain the same name of the shortcut.
Here was my pinned task bar info: C:\Users\me\AppData\Roaming\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar
You could also probably modify the registry and add the shortcut straight to the folder listed above, then reload explorer.exe, but you have to worry about user permissions and what not. Either way, this should give you something to roll with.

How to attach the debugger as soon as a file is double-clicked?

As most applications, mine opens files in 2 ways:
(1) Via the "File | Open" menu. This code is fully debugged.
(2) By double-clicking a file whose extension is associated to my application. This part needs some debugging.
What is the process to debug the latter program execution path?
Is there a way to place a statement like: CallDebugger(); ???
TIA
You could try by setting your application to Launch the Debugger Automatically.
To setup an application to launch the debugger automatically
Start the Registry Editor (regedit).
In the Registry Editor, open the HKEY_LOCAL_MACHINE folder.
Navigate to HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Image File Execution Options.
In the Image File Execution Options folder, locate the name of the application you want to debug, such as myapp.exe. If you cannot find the application you want to debug:
Right-click the Image File Execution Options folder, and on the shortcut menu, click New Key.
Right-click the new key, and on the shortcut menu, click Rename.
Edit the key name to the name of your application; myapp.exe, in this example.
Right-click the myapp.exe folder, and on the shortcut menu, click New String Value.
Right-click the new string value, and on the shortcut menu, click Rename.
Change the name to debugger.
Right-click the new string value, and on the shortcut menu, click Modify.
The Edit String dialog box appears.
In the Value data box, type vsjitdebugger.exe.
Click OK.
From the Registry menu, click Exit.
The directory containing vsjitdebugger.exe must be in your system path. To add it to the system path, follow these steps:
Open the Control Panel in Classic view, and double-click System.
Click Advanced System Settings.
In System Properties, click the Advanced tab.
On the Advanced tab, click Environment Variables.
In the Environment Variables dialog box, under System variables, select Path, then click the Edit button.
In the Edit System Variable dialog box, add the directory to the Variable value box. Use a semicolon to separate it from other entries in the list.
Click OK to close the Edit System Variable dialog box.
Click OK to close the Environment Variables dialog box.
Click OK to close the System Properties dialog box.
Now, use any method to start your application. Visual Studio will start and load the application.
Source: http://msdn.microsoft.com/en-us/library/a329t4ed(v=vs.100).aspx
Note:
You may need to run your application As Administrator to succesfully launch the debugger.

Hide console window when executing a .exe with arguments

I've added a "start review" context menu item for .pdf files.
In the registry I've added this as the command:
"c:\myscript\abc.exe" "%1"
The .exe is a C# application built in C# .NET.
The issue is that whenever I right-click a PDF file and choose the "start review" menu item, I get a black command window opening. How can I get rid of this?
To always hide the console, you can go to Project > Properties and change the Output type to Windows Application:
Change the output type to "Windows Application". The following link should help...
http://msdn.microsoft.com/en-us/library/vstudio/s3awkzkh(v=vs.100).aspx
Good Luck!

debugging an executable created by application

I'm having a difficult time finding the right keywords to search on for this. I'm simply trying to figure out a way to debug an executable file that was created by my application. I just created an executable file from my application that contains some encrypted stuff which starts my application when double clicked, that my application uses for certain things. Is it possible to run that executable program that starts the application, and debug the entry into visual studio? I need to verify that the encrypted data is decrypted properly in the application, and the only way to verify this is with debug, or writing to an output file the decrypted information. I'd rather just debug, so I don't have to remember to take out the code that produces the outfile.
Thanks in advance!
Make sure that you application is installed with the .PDBs in the directory with it.
In visual studio, load the solution containing your application.
After you have started the app by double clicking on the associated icon select debug| attach to process ...
Select your process.
If you application is going right into action you may have to add a thread.sleep(10000) (or show a modal dialog) to give you time to attach to the start while you debug - remove it when done.

"Open with" - C# program shows just icon in Windows "Open With" context menu

I have a program, MyApp, where I can open a text file, which works great.
The application is created in C# with Visual Studio 2003, .NET 1.1.
But under the [right-click on file context-menu in Explorer -> "Open With"] just the icon is shown, not the application name or description.
As shown here:
Open With context-menu (http://data.fuskbugg.se/skalman02/4e450ba043602_openwith.png)
If we look at Notepad++ in the image that text seems to be the description text, same as under File properties general tab for notepad++.exe.
What value is used there? How do I set that value?
[EDIT]:
The registry entries automatically generated when using "open With -> browse for application" are:
HKEY_CLASSES_ROOT\Applications\MyApp.exe\shell\open\command
(default) under the key command is: "correct path" "%1"
You need to set the AssemblyTitle in AssemblyInfo.cs. After doing this you may need to remove all the registry entries and re-install your aplication.
(so other people with the same problem don't need to search through the comment thread)

Categories