I have a Windows Forms application (C#, NET 3.5) installed using an MSI installer. In this application I have a button that when pressed opens a browser with a specific URL. I use
Process.Start(url);
to open the browser. This works fine when debugging, but after the installation it has less than optimal results. For example.
As far as I can tell this issue is caused by the user associated with the application when installing.
Taking into account that may users require proxies and personal browser settings and that the Just Me, Everyone choice should remain up to the user. What is the best course o action?
I tried calling Process.Start(url) with the current logged in user using
ProcessStartInfo.UserName = Environment.UserName
But it also requires a password and asking for credentials is not an option.
Do you have any other suggestions, am I using Process.Start() incorrectly, are there settings I need to make during installation, is there anything I missed?
UPDATE: Using Process Explorer as data_smith suggested I noticed the following:
Is there a way, without asking for credentials, to make the application start (at windows boot) under the current user even though it is installed for everyone?
UPDATE: Following a suggestion by data_smith to use ShellExecute and the suggestions here and here I was able to solve the problem and get the desired behavior.
The main issue was that when the installer finished the application was started with Process.Start(); This started the application as the NT AUTHORITY\SYSTEM user (the users installers run under) therefore all browsers opened by this application would also be under SYSTEM user. By using the suggestion from data_smith and the suggestions linked above I was able to start the process under the current user.
After the computer is rebooted the application starts under the correct user as this is configured through registry entries.
I recommend accessing the registry to determine the default browser.
//Create a registry key to read the default browser variable
RegistryKey reader = Registry.ClassesRoot.OpenSubKey(@"http\shell\open\command");
//Determine the default browser
string DefaultBrowser = (string)reader.GetValue("");
I tried using this code, and discovered that my registry key ended with "-- \"%1\"".
I don't know why it was there, but I recommend using the following loop to ensure that the key ends in the right place.
//If the path starts with a ", it will end with a "
if (DefaultBrowser[0] == '"')
{
for (int count = 1; count < DefaultBrowser.Length; count++)
{
if (DefaultBrowser[count] == '"')
{
DefaultBrowser = DefaultBrowser.Remove(count + 1);
count = DefaultBrowser.Length + 22;
}
}
}
//Otherwise, the path will end with a ' '
else
{
for (int count = 0; count < DefaultBrowser.Length; count++)
{
if (DefaultBrowser[count] == ' ')
{
DefaultBrowser = DefaultBrowser.Remove(count + 1);
count = DefaultBrowser.Length + 22;
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With