I am trying to get the app name while my program initializes.
for eg. I have an exe called tempName.exe
How do I know get the tempName in my program? so instead of getting the parameter passed. I want the exe name.
Thank You Kind Regards
You can use the Process
class (using System.Diagnostics
):
string name = Process.GetCurrentProcess().MainModule.FileName;
or
string name = System.AppDomain.CurrentDomain.FriendlyName;
There are several ways as pointed out in other answers. One such way is following:
Environment.GetCommandLineArgs()[0];
GetCommandLineArgs() returns the command line arguments as a list of strings for the current application. 0th element in the list is application name. See here for more detail on the GetCommandLineArgs().
If you need to know which shortcut was used to run your application, you can do that creating a shortcut of your application with argument that denotes shortcut. For example yourapp.exe /s1 , yourapp.exe /s2 , etc.
Try this:
string exeAssembly = Assembly.GetEntryAssembly().FullName;
string exeAssemblyName = Assembly.GetEntryAssembly().GetName().Name;