-1

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

Fly
  • 43
  • 1
  • 8

3 Answers3

2

You can use the Process class (using System.Diagnostics):

string name = Process.GetCurrentProcess().MainModule.FileName;

or

string name = System.AppDomain.CurrentDomain.FriendlyName;
yaakov
  • 5,552
  • 35
  • 48
Roman
  • 11,966
  • 10
  • 38
  • 47
  • okay. this gives me the exe. But the true exe name. I have shortcuts that are created that accesses this exe. but I need the shortcut name, of the shortcut selected to run – Fly May 26 '16 at 11:49
  • That's a very different question. – yaakov May 26 '16 at 11:56
  • sorry If I phrased it wrong Codran – Fly May 26 '16 at 12:03
  • Lets try this again. I have one program, the exe is called main.exe. when main.exe is excuted. I allowed the user to be able to create a shortcut off main.exe. But when the user can create any name for the shortcut. so if the user is selecting the shortcut. I need the name of this short cut. not the program its pointing to – Fly May 26 '16 at 12:07
1

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.

Mitesh Budhabhatti
  • 1,583
  • 2
  • 16
  • 20
0

Try this:

 string exeAssembly = Assembly.GetEntryAssembly().FullName;
 string exeAssemblyName = Assembly.GetEntryAssembly().GetName().Name;
error_handler
  • 1,191
  • 11
  • 19
  • This doesnt give me the short cut name. my program has a the functionality to create short cuts. but this doesnt give the short cut name on the exe that is selected on. it gives me the exe it is pointing to – Fly May 26 '16 at 11:56