I have a program named A, which is responsible for telling the user about the news and updates of my program, then it should run program B which is the main program. How would I make program B openable only from program A??
Asked
Active
Viewed 86 times
-3
-
Without more details (and some code..) this is fairly broad. – Broots Waymb May 09 '16 at 18:39
-
@DangerZone This was pretty clear to me. He wants to make a launcher, like the one from the Blizzard games. – T. Sar May 09 '16 at 18:40
-
1@ThalesPereira - Ok, so not unclear. But it is broad. Answerable of course, but answers would be equally broad. – Broots Waymb May 09 '16 at 18:41
-
Possible duplicate of [Run console application from other console app](http://stackoverflow.com/questions/2366168/run-console-application-from-other-console-app) – Matt Rowland May 09 '16 at 18:48
-
@DangerZone Eh, that's not how I see it. It's pretty clear what he wants to do, at least to me. It's just a launcher. Making an App to open only when called by some other app is pretty specific to me. – T. Sar May 09 '16 at 18:59
-
@MattRowland This is not a console application, nor it is launched from a console app. This a question about a launcher, like those that are super common on the gaming industry - NCSoft, Blizzard, etc. – T. Sar May 09 '16 at 19:00
-
1@ThalesPereira How did you get that from this question? The question asks how to run program B from program A with no other details. – Matt Rowland May 09 '16 at 19:01
-
@MattRowland It tells the user about updates in the application. To me, it seems like he want to simulate the behavior you see on the gaming industry in general. It does have other details! – T. Sar May 09 '16 at 19:08
1 Answers
3
I don't guarantee this to be the best solution, but it can be implemented pretty easily: try setting an environment variable for the program you're starting. When the new program starts up, it should check for that environment variable and shut down if it isn't present.
So in Program A:
public static void StartProgramB()
{
Process p = new Process();
p.StartInfo.FileName = "programb.exe";
//Other startinfo calls go here: parameters, start options, etc.
p.StartInfo.EnvironmentVariables["CalledFromProgramA"] = "true";
p.Start();
p.WaitForExit();
}
and in Program B:
public static void Main()
{
if(Environment.GetEnvironmentVariable("CalledFromProgramA") != "true")
return;
}

John Biddle
- 233
- 1
- 10
-
I apparently answered an unanswerable question... Didn't think it was too unclear – John Biddle Nov 30 '16 at 23:47