The steps of my application are:
- Go to the setting page first, and the setting page will register the Registry Log (as 'regedit' in command line) in the background (people may seldom go to the setting page).
- When users clicks the URL in a web page, it will trigger the registry and open my application.
- The appplication reads the parameter that it gets and does things depending on the parameter value.
- User may click on different links to send different parameters to my application
- That is, if the application is not opened, it should be launched it and reads the parameter. If the application is already opened, it should just read the parameter.
The problem is: how could find out the different situations of my application - whether it is opened or not - and then use the parameter correctly?
The part of registry( in setting page):
Registry.ClassesRoot.CreateSubKey("MyApp").SetValue("", "URL:MyApp Protocol");
Registry.ClassesRoot.CreateSubKey("MyApp").SetValue("URL Protocol", "");
Registry.ClassesRoot.CreateSubKey("MyApp\\DefaultIcon").SetValue("", "\"" + Path.GetDirectoryName(Process.GetCurrentProcess().MainModule.FileName) + "\\" + "MyApp.exe" + ",1\"");
Registry.ClassesRoot.CreateSubKey("MyApp\\shell\\open\\command").SetValue("", "\"" + Path.GetDirectoryName(Process.GetCurrentProcess().MainModule.FileName) + "\\" + "MyApp.exe" + "\" \"%1\"");
%1 is the parameter I will get( from url to my application).
And the web link may be:
<a href="MyApp://function1">Call for Function 1</a>
<a href="MyApp://function2">Call for Function 2</a>
So there are many links in the web page to call same application.
But I cannot let my application be opened every time (that is, there should be only one application opened, and other clicks on links will only send parameters to the app).
I know how to find out whether the application is opened or not by the code:
Mutex mul = null;
bool is_createdNew;
try
{
string mutexName = Process.GetCurrentProcess().MainModule.FileName.Replace(Path.DirectorySeparatorChar, '_');
mul = new Mutex(true, "Global\\" + mutexName, out is_createdNew);
if (!is_createdNew)
{
// application be opened already, I close the application originally
Environment.Exit(Environment.ExitCode);
}
else
{
// the application is first run, open my MainWindow
}
}
catch (Exception ex)
{
throw ex;
}
finally
{
}
Is it possible to send the parameter as a method of registry when the application is opened?
I even think about reading registry by Registry.GetValue
, when my application starts up,
to use timer to read registry value per second......
This is my first time face this situation of user's request,
hope someone can give me any direction!
Thanks in advance.