My Problem is that I have 2 .exe
files (MainGUI
and it's updater). I only want the update.exe
be executed via Main-program
and not by Double-Clicking it.
Is there a well-known method to realize this?
My idea is that the Program checks if its executed with argc = 0
and if so it just terminates but you can still open it then with an own argument.
-
I meant argc = 1 not 0 because Argument Vector[0] is the name of the program – AidenDean Aug 30 '19 at 04:30
-
You could use the time of day plus or minus 1 second. – cup Aug 30 '19 at 04:31
-
1You can fetch the Parent Process ID like described in [this answer](https://stackoverflow.com/a/18403516/156811) and check if it's the "Main program". – Havenard Aug 30 '19 at 04:46
-
Assuming you just want to block casual double-clicking of an EXE, the mandatory use of command line parameters is the standard solution. My only recommendation is to us a specific command line (e.g. `/run`) instead of just checking `argc > 1` – selbie Aug 30 '19 at 05:13
-
Unrelated: Take care because `argv[0]` isn't usually the program name. It's the command, path and all. If there are symlinks involved you could be mislead. Another common alternative, particularly in baremetal embedded systems, is a null string. – user4581301 Aug 30 '19 at 05:49
1 Answers
I don't know what's well known or not, but anything on the command line is going to be easy to work around; to some extent this all depends on just how determined you are.
1) Parent puts a magic string in the environment, executes the child updater, which expects to find that magic string, refusing to run if not.
2) Child could verify that its parent is the MainGUI executable; there are process helper APIs for that.
3) Parent MainGUI creates a pipe, launches the child with the numeric value of the handle on the command line, then the parent writes some critical data that the updater requires to run (I dunno, actual update content, version info, not sure). If the child updater finds anything out of order, refuses to run.
There are surely other ways, though it's going to be hard to beat somebody who's really determined.

- 3,929
- 1
- 23
- 30