Reputation: 71
I'd like to launch my application from another utility app and pass a parameter. The simplest solution:
System.Diagnostics.Process.Start(appPath, param);
... is not an option as I'd like to prevent other people from providing the parameter to the app. In other words: I'd like to lauch my application with a param only from my utility app.
How to achieve that?
Thanks, Leszek
Upvotes: 4
Views: 656
Reputation: 71
Another option that came to my mind is to accept the parameter only in the Debug build. I have control over both applications and I'm the only one who needs to lauch the main application with a param. I could strip this functionality off in the release build.
Upvotes: 0
Reputation: 216243
If you (for security reason) don't want to pass meaningful parameters to start your main program then you can use Anonymous Pipes (starting from Net 4)
Basically you follow this pseudocode
Here you can find a detailed example
In this way, there is a parameter passed from the utility to the main program representing the anonymous pipe, but no other program or user can easily fake the main program. If you add to this scenario also some form of secret handshaking between the two programs you will get a robust protection.
Upvotes: 2
Reputation: 8337
If I understand correctly, you're wanting the process to go like this:
And you want to make sure no one else can start YourApplication.exe outside of the UtilityProgram.
I think the simplest way would be to require a parameter in YourApplication.exe that is complex, sort of like a password.
So, in YourApplication.exe, your code could look like this:
static int Main(string[] args){
if (args.Length != 1) {
// We got more than 1 parameter, exiting with a code of -1.
return -1;
}
if (args[0] != "abc123def456ghi") {
// We got 1 parameter, but it wasn't right, exiting with a code of -2.
return -2;
}
// Got 1 matching parameter
// Code goes here
}
And then in UtilityProgram.exe, you can do this:
Process MyApp = new Process();
MyApp.StartInfo.FileName = @"C:\path\to\MyApp\exe";
MyApp.StartInfo.Arguments = "abc123def456ghi";
MyApp.Start();
Upvotes: 1
Reputation: 1957
You can make one of your app's parameters a password that you only know. Then you can pass that parameter from the launching utiliy.
Upvotes: 1