Reputation: 14233
I have an AutoUpdater application that launches another application. Is there anyway to force that second application to ONLY run if it was started by the AutoUpdater?
The problem is, some end-users will create a shortcut to the main app file on their desktop. This becomes a problem because it's supposed to check for updates to the app before it launches, and they don't receive our updates.
One thought I had was to create an IPC channel via WCF and issue a very simple command from the AutoUpdater to the other application. If the other app doesn't receive that command within 2 or 3 seconds it would close itself.
This seems like more code/overhead than what should be needed though. Is there an easier way?
Thanks!
Upvotes: 4
Views: 86
Reputation: 9399
Windows forms applications also have a main method, which can take parameters. You could read some parameter, and if it doesn't conform to your rules, you can either keep the form from opening (therefore the user wouldn't see a thing), or you can chastise the user, I mean, give a message that they shouldn't open your app that way. I think this is simpler than using WCF.
Upvotes: 6
Reputation: 399
You can run your App by using
System.Diagnostics.Process.Start("", "TestString");
The first string is the path of App you want to start, something like "C:/AppName.exe" and the second string is any text you want but it must be the same string that you check in the 'if' below. In the App you need to check the text given trough the second string.
static void Main(string[] args)
{
if(!args.Length == 1 || !args[0]=="TestString") Environment.Exit(0);
//↑ lenght check to avoid exception, then check for the string itself
//the OS gives the string to args, you don't need to take care about that
//rest of your code
}
I hope I helped to solve it.
Upvotes: 2