Get application launch in App.xaml.cs

How can I run the runnig path to my application from app.xaml.cs itself?

+3
source share
3 answers

You may try

Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)

AppDomain.CurrentDomain.BaseDirectory

and / or

Environment.CurrentDirectory
+11
source

You can simply use the System.Environment.GetCommandLineArgs property to get the command line that starts the application. Parse this using the System.IO.Path methods to extract only the executable file name or full path.

var exeName = System.IO.Path.GetFileName(
    System.Environment.GetCommandLineArgs()[0]);
MessageBox.Show("This exe filename is " + exeName);
+1
source

This always works:

System.Windows.Forms.Application.StartupPath
0
source

Source: https://habr.com/ru/post/1717116/


All Articles