Is there a way to determine if a Winforms .exe is run by double clicking on it on Windows explorer?
What I wish to achieve is nothing too fancy. I just want to determine if my winforms exe is run from within windows, or through another .exe. A bool like isLaunchedFromWinExplorer or isLaunchedFromAnotherApplication would suffice. I will show Form1 if the former, show Form2 if the latter. Thanks!
7 Replies
I mean, you could check the parent process
but if you control the other exe that's launching it, a better way is to just pass a command line argument
why do you want to do this anyhow?
Thanks. The parent exe is uncontrolled in this context, unfortunately. Parent app will be an app called „mod organizer 2“. It is possible to add executables in it, and run that exe in a VFS environment with deployed mods for video game modding purposes. My exe runs some checks on the installed mods, and displays a report accordingly. I wish to display the report if my exe is run through mo2. And completely another form if it is run from windows explorer.
what do you mean "is run from within windows"?
yes, your WinForms executable is run from "within windows"
that's how WinForms works
I think they meant "from Windows explorer"
but really you should be checking for mod organizer 2
or see if mod organizer 2 allows command line arguments to be passed to what it's running
okay, so we're asking if a program can tell how it was launched?
To answer my own question: found out how to do exactly what I want to accomplish.
after that, yields the desired result, either as "explorer", or "ModOrganizer".
also for further future reference, including the necessary assembly instruction at the top of the code somehow doesn't work, one needs to right click on the project dependencies tree, click on "Add project reference", and then select System.Management from the resulting window.
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.