mohammed mokhtar mohammed mokhtar - 2 days ago 5
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

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;
} 
Comments