Auto start now properlly working with ClickOnce.
authorsl
Sun, 18 Jan 2015 14:18:28 +0100
changeset 93f0015e909f41
parent 92 787dee27fc0a
child 94 fe939a729030
Auto start now properlly working with ClickOnce.
Server/SharpDisplayManager.csproj
Server/StartupManager.cs
     1.1 --- a/Server/SharpDisplayManager.csproj	Sun Jan 18 12:35:22 2015 +0100
     1.2 +++ b/Server/SharpDisplayManager.csproj	Sun Jan 18 14:18:28 2015 +0100
     1.3 @@ -27,10 +27,11 @@
     1.4      <SupportUrl>http://publish.slions.net/SharpDisplayManager/</SupportUrl>
     1.5      <ProductName>Sharp Display Manager</ProductName>
     1.6      <PublisherName>Slions</PublisherName>
     1.7 +    <SuiteName>Sharp Display Manager</SuiteName>
     1.8      <CreateWebPageOnPublish>true</CreateWebPageOnPublish>
     1.9      <WebPage>index.htm</WebPage>
    1.10      <OpenBrowserOnPublish>false</OpenBrowserOnPublish>
    1.11 -    <ApplicationRevision>15</ApplicationRevision>
    1.12 +    <ApplicationRevision>20</ApplicationRevision>
    1.13      <ApplicationVersion>0.1.0.%2a</ApplicationVersion>
    1.14      <UseApplicationTrust>false</UseApplicationTrust>
    1.15      <CreateDesktopShortcut>true</CreateDesktopShortcut>
     2.1 --- a/Server/StartupManager.cs	Sun Jan 18 12:35:22 2015 +0100
     2.2 +++ b/Server/StartupManager.cs	Sun Jan 18 14:18:28 2015 +0100
     2.3 @@ -16,6 +16,7 @@
     2.4  using System.Security;
     2.5  using System.Security.Principal;
     2.6  using System.Windows.Forms;
     2.7 +using System.Deployment.Application;
     2.8  
     2.9  namespace SharpDisplayManager
    2.10  {
    2.11 @@ -115,7 +116,7 @@
    2.12  						{
    2.13  							string value = (string)key.GetValue("SharpDisplayManager");
    2.14  							if (value != null)
    2.15 -								startup = value == Application.ExecutablePath;
    2.16 +								startup = value == LaunchCommand;
    2.17  						}
    2.18  					}
    2.19  					isAvailable = true;
    2.20 @@ -182,10 +183,23 @@
    2.21  			catch (IOException) { }
    2.22  		}
    2.23  
    2.24 +		string LaunchCommand
    2.25 +		{
    2.26 +			get
    2.27 +			{	
    2.28 +				//Executable path won't launch ClickOnce Application with deployment enabled.
    2.29 +				//return Application.ExecutablePath;
    2.30 +				//Instead we need to launch the application using the .appref-ms shortcut.
    2.31 +				//That shortcut is located at <programs>\<publisher>\<suite>\<product>.appref-ms
    2.32 +				return string.Concat(Environment.GetFolderPath(Environment.SpecialFolder.Programs), "\\", "Slions", "\\", "Sharp Display Manager" , "\\" ,"Sharp Display Manager", ".appref-ms");
    2.33 +			}
    2.34 +		}
    2.35 +
    2.36  		private void CreateRegistryRun()
    2.37  		{
    2.38  			RegistryKey key = Registry.CurrentUser.CreateSubKey(REGISTRY_RUN);
    2.39 -			key.SetValue("SharpDisplayManager", Application.ExecutablePath);
    2.40 +			//Rather than the executable name we pass in the ClickOnce shortcut to make sure we launch with deployment support
    2.41 +			key.SetValue("SharpDisplayManager", LaunchCommand);
    2.42  		}
    2.43  
    2.44  		private void DeleteRegistryRun()