mohammed mokhtar mohammed mokhtar - 1 year ago 69
C# Question

Run program B from program A only?

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??

Answer Source

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";


and in Program B:

public static void Main()
   if(Environment.GetEnvironmentVariable("CalledFromProgramA") != "true")
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download