# HG changeset patch
# User sl
# Date 1421587108 -3600
# Node ID f0015e909f41183cdbe3ffc5059638ed8b32dadb
# Parent  787dee27fc0a9c18a47b52df6d4eb5ad722b7161
Auto start now properlly working with ClickOnce.

diff -r 787dee27fc0a -r f0015e909f41 Server/SharpDisplayManager.csproj
--- a/Server/SharpDisplayManager.csproj	Sun Jan 18 12:35:22 2015 +0100
+++ b/Server/SharpDisplayManager.csproj	Sun Jan 18 14:18:28 2015 +0100
@@ -27,10 +27,11 @@
     <SupportUrl>http://publish.slions.net/SharpDisplayManager/</SupportUrl>
     <ProductName>Sharp Display Manager</ProductName>
     <PublisherName>Slions</PublisherName>
+    <SuiteName>Sharp Display Manager</SuiteName>
     <CreateWebPageOnPublish>true</CreateWebPageOnPublish>
     <WebPage>index.htm</WebPage>
     <OpenBrowserOnPublish>false</OpenBrowserOnPublish>
-    <ApplicationRevision>15</ApplicationRevision>
+    <ApplicationRevision>20</ApplicationRevision>
     <ApplicationVersion>0.1.0.%2a</ApplicationVersion>
     <UseApplicationTrust>false</UseApplicationTrust>
     <CreateDesktopShortcut>true</CreateDesktopShortcut>
diff -r 787dee27fc0a -r f0015e909f41 Server/StartupManager.cs
--- a/Server/StartupManager.cs	Sun Jan 18 12:35:22 2015 +0100
+++ b/Server/StartupManager.cs	Sun Jan 18 14:18:28 2015 +0100
@@ -16,6 +16,7 @@
 using System.Security;
 using System.Security.Principal;
 using System.Windows.Forms;
+using System.Deployment.Application;
 
 namespace SharpDisplayManager
 {
@@ -115,7 +116,7 @@
 						{
 							string value = (string)key.GetValue("SharpDisplayManager");
 							if (value != null)
-								startup = value == Application.ExecutablePath;
+								startup = value == LaunchCommand;
 						}
 					}
 					isAvailable = true;
@@ -182,10 +183,23 @@
 			catch (IOException) { }
 		}
 
+		string LaunchCommand
+		{
+			get
+			{	
+				//Executable path won't launch ClickOnce Application with deployment enabled.
+				//return Application.ExecutablePath;
+				//Instead we need to launch the application using the .appref-ms shortcut.
+				//That shortcut is located at <programs>\<publisher>\<suite>\<product>.appref-ms
+				return string.Concat(Environment.GetFolderPath(Environment.SpecialFolder.Programs), "\\", "Slions", "\\", "Sharp Display Manager" , "\\" ,"Sharp Display Manager", ".appref-ms");
+			}
+		}
+
 		private void CreateRegistryRun()
 		{
 			RegistryKey key = Registry.CurrentUser.CreateSubKey(REGISTRY_RUN);
-			key.SetValue("SharpDisplayManager", Application.ExecutablePath);
+			//Rather than the executable name we pass in the ClickOnce shortcut to make sure we launch with deployment support
+			key.SetValue("SharpDisplayManager", LaunchCommand);
 		}
 
 		private void DeleteRegistryRun()