AidenDean
AidenDean

Reputation: 348

C++ prevent program executed manually

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.

Upvotes: 1

Views: 218

Answers (1)

Steve Friedl
Steve Friedl

Reputation: 4247

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.

Upvotes: 4

Related Questions