1

First off, I had this idea from the Windows Command Prompt I mean.. like: - If you launch it from Win+R or "RUN", it will say "C:/Windows/system32/cmd.exe " in the title - If you launch it from Cortana or the Search-type of stuff, it will show "Command Prompt" on its title

Anyways, is it possible to extract that kind of information using C#?

EDIT: To get things straight, Is it possible to extract the "LAUNCH" information of the application? Like, for example, if I launched it from a shortcut, I am able to know the shortcut name, etc.

Nathan A.
  • 48
  • 7
  • @Pikoh That isn't a duplicate. – ProgrammingLlama Jun 01 '17 at 08:19
  • This only works if your application is using the same processor architecture as the target process – NtFreX Jun 01 '17 at 08:21
  • Actually, no, I'm trying to get the launch information of "this C# app" or basically, self. – Nathan A. Jun 01 '17 at 08:22
  • [This](https://stackoverflow.com/questions/38387860/determine-if-process-started-from-shortcut) might be of help. – ProgrammingLlama Jun 01 '17 at 08:24
  • 1
    Oh sorry I misread your post. I thought you wanted to get the start info of another process. But If you want the start info of thje current process you can just use `Process.GetCurrentProcess().MainModule.FileName`. I don't think you can find out if it where started over a shurtcut – NtFreX Jun 01 '17 at 08:24
  • Perfect! That was what I'm looking for, was unable to find it anywhere. Perhaps add that as an answer? – Nathan A. Jun 01 '17 at 08:26
  • Hard to imagine that is what you want if you need the Console.Title string depend on how your program got started. https://stackoverflow.com/questions/2531837/how-can-i-get-the-pid-of-the-parent-process-of-my-application/2533287?s=1|0.8035#2533287 – Hans Passant Jun 01 '17 at 09:04

1 Answers1

0

If you want to find the start path of the current application you can use the following sniped.

Process.GetCurrentProcess().MainModule.FileName
NtFreX
  • 10,379
  • 2
  • 43
  • 63
  • ProcessStartInfo is a lot more than the file name of the process. – Matt Jun 04 '19 at 18:24
  • @Matt True. But the questioner didn't ask for more. – NtFreX Jun 05 '19 at 07:57
  • Its literally the title of this question. Furthermore the FileName property in your answer doesnt tell him "if I launched it from a shortcut, I am able to know the shortcut name". – Matt Jun 06 '19 at 14:15
  • @Matt The questioner confirmed by accepting my answer that it answered his question. As I'm only answering, as you said, what the file name of the process is, I imply that that was what he was asking. And that he could help himself with the shortcuts by the means of file ending or whatever. That makes the title wrong in my eyes and not the question or the answer. But I understand that one could argue otherwise. – NtFreX Jun 06 '19 at 14:34