Answered ClickOnce + Windows StartUp Registry

  • Tuesday, July 18, 2006 2:22 AM
     
     

    Hi, i have a click-once application that should run as the user logs in the machine.

    No problem. The application just adds an entry at the windows registry.

    But every time that my clickonce application its updated the registry entry is no longer valid because the application version has already changed.

    Any work-arounds?

    How can I set up my click-once app to starts automatically when the users log-in the machine?

    tks

Answers

  • Friday, July 28, 2006 1:50 PM
     
     Answered

    Hi Marcos,

    You can do this with some custom initialization code that runs when your application is first installed:

    public static class ClickOnceHelper

    {

       public static void AddShortcutToStartupGroup(string publisherName, string productName)

       {

          if (ApplicationDeployment.IsNetworkDeployed &&

          ApplicationDeployment.CurrentDeployment.IsFirstRun)

          {

             string startupPath = Environment.GetFolderPath(Environment.SpecialFolder.Startup);

             startupPath = Path.Combine(startupPath, productName) + ".appref-ms";

             if (!File.Exists(startupPath))

             {

                string allProgramsPath = Environment.GetFolderPath(Environment.SpecialFolder.Programs);

                string shortcutPath = Path.Combine(allProgramsPath, publisherName);

                shortcutPath = Path.Combine(shortcutPath, productName) + ".appref-ms";

                File.Copy(shortcutPath, startupPath);

             }

          }

       }

    }

     

    Hope that helps,

    Brian Noyes

    Author of Smart Client Deployment with ClickOnce, Data Binding with Windows Forms 2.0

All Replies

  • Friday, July 28, 2006 1:50 PM
     
     Answered

    Hi Marcos,

    You can do this with some custom initialization code that runs when your application is first installed:

    public static class ClickOnceHelper

    {

       public static void AddShortcutToStartupGroup(string publisherName, string productName)

       {

          if (ApplicationDeployment.IsNetworkDeployed &&

          ApplicationDeployment.CurrentDeployment.IsFirstRun)

          {

             string startupPath = Environment.GetFolderPath(Environment.SpecialFolder.Startup);

             startupPath = Path.Combine(startupPath, productName) + ".appref-ms";

             if (!File.Exists(startupPath))

             {

                string allProgramsPath = Environment.GetFolderPath(Environment.SpecialFolder.Programs);

                string shortcutPath = Path.Combine(allProgramsPath, publisherName);

                shortcutPath = Path.Combine(shortcutPath, productName) + ".appref-ms";

                File.Copy(shortcutPath, startupPath);

             }

          }

       }

    }

     

    Hope that helps,

    Brian Noyes

    Author of Smart Client Deployment with ClickOnce, Data Binding with Windows Forms 2.0

  • Friday, July 28, 2006 2:04 PM
     
     

    Thanks Brian!!

    The whole deal was to refer the "appref-ms" file and not the executable like i was doing.

    Thanks for the reply!!

    Cheers!

     

     

     

  • Wednesday, September 19, 2007 10:51 AM
     
     
     

    public static class ClickOnceHelper

    {

       public static void AddShortcutToStartupGroup(string publisherName, string productName)

       {

          if (ApplicationDeployment.IsNetworkDeployed &&

          ApplicationDeployment.CurrentDeployment.IsFirstRun)

          {

             string startupPath = Environment.GetFolderPath(Environment.SpecialFolder.Startup);

             startupPath = Path.Combine(startupPath, productName) + ".appref-ms";

             if (!File.Exists(startupPath))

             {

                string allProgramsPath = Environment.GetFolderPath(Environment.SpecialFolder.Programs);

                string shortcutPath = Path.Combine(allProgramsPath, publisherName);

                shortcutPath = Path.Combine(shortcutPath, productName) + ".appref-ms";

                File.Copy(shortcutPath, startupPath);

             }

          }

       }

    }

     

    CurrentDeployment is null, if it isnt network deployed. FYI.

    This will throw an exception during debug, or other times not network deployed.

  • Thursday, July 10, 2008 4:47 PM
     
     
    Hi,

    Where do i put/call the above code in my app? in Form_Load()?

    Thanks
    dan
  • Tuesday, July 22, 2008 12:09 AM
     
     
    This is very strange for me, I put a .appref-ms in the Startup folder for Vista (current user), and it just doesn't launch on startup, no error, nothing.  I even tried doing the CURRENT_USER/Run startup, and even then, nothing.

    Any suggestions?  It is killing me, we have an application requirement that the users can specify to login to this application on startup, but right now, i can't even get the application to load on startup.
  • Thursday, August 21, 2008 7:48 AM
     
     
    Tom,

    I have the very exact problem. It works on Windows XP but not on Vista...
  • Wednesday, October 01, 2008 12:32 AM
     
     
    After a LOT of searching, I have found that basically, Vista blocks appref in startup. It wasn't always this way, but somewhere along the way they got blocked.  I have tried several manifest settings, as well as internal security reliefs (apps that use code requiring zero security) and still have not found a work around from a code method.

    Instead, I have created a stub that launches the applications and notify the user that when they request the application to load on startup, that a file will be placed in the location of thier choosing.  The file is auto-updated from the ClickOnce deployment via xcopy.
  • Friday, April 17, 2009 6:13 PM
     
     
    has anyone solved the vista problem?

    I have an application that asks the user if they want to auto startup. i was using the product.exe but i need access to the .appref.ms so it does the auto update where required.

    On startup this doesnt seem to do anything.

    As a side note, i took the registry approach.

     

    RegistryKey key = Registry.CurrentUser.CreateSubKey(RUN_LOCATION);

     

    string allProgramsPath = Environment.GetFolderPath(Environment.SpecialFolder.Programs);

     

    string shortcutPath = Path.Combine(allProgramsPath, "MyApp");

    shortcutPath =

    Path.Combine(shortcutPath, "MyApp") + ".appref-ms";

    key.SetValue(VALUE_NAME, shortcutPath);

    Can someone provide me with an explanation as to why my application does not auto run on startup? :)

  • Friday, April 17, 2009 6:41 PM
     
     
    Just as a heads up, Click Once has their own forum:

    http://social.msdn.microsoft.com/Forums/en-US/winformssetup/threads
    John Grove - TFD Group, Senior Software Engineer, EI Division, http://www.tfdg.com
  • Saturday, April 18, 2009 3:24 AM
     
     
    i just did a search on their entire forums and across google, and cant find any explanation about this problem.

    Now i find this odd, because the workaround is to use a clickonce deployment to run another clickonce deployment, which in my opinion is so frustrating, or to use iexplore to run a url, that wont always work (if no internet connection).


    Considering clickonce runs in a secure zone, i find it hugely frustrating that i have to hack around creating links in startup paths for my own application, when my exe works but an .appref-ms doesnt.. AND it used to.  so this behavior has changed, and clickonce was designed to handle it originally. Whats the new way to handle this... the "Microsoft" way?

    Sure i can go and hack my own code together in a few hours to get this working, but i still want to understand why it changed.
  • Saturday, April 18, 2009 10:08 AM
     
     

    I completed the task creating a "InternetShortcut" (ini file) pointing to the appref-ms file, see example below how to create a "InternetShortcut"

    [InternetShortcut]
    URL=file://c:\windows\notepad.exe

    The complete solution can be found if searching the internet, can't remeber where i read it...

  • Friday, May 08, 2009 6:14 AM
     
     
    Have we got a proper solution yet? I am still stuck with this problem!
    Software Developer - Web/Mobile Applications
  • Friday, May 08, 2009 6:00 PM
     
     
    Can a moderator please move this to:
    http://social.msdn.microsoft.com/Forums/en-US/winformssetup/threads
    John Grove - TFD Group, Senior Software Engineer, EI Division, http://www.tfdg.com
  • Wednesday, June 10, 2009 3:46 PM
     
     
    >Have we got a proper solution yet? I am still stuck with this problem!

    I wonder the same thing...
    Is the ini file the best solution to this so far?

    J
  • Thursday, June 11, 2009 3:45 AM
     
     Proposed Answer
    Yes, please see my blog below. It explains all known solutions with my solution which works where others failed.

    http://integrationexperts.wordpress.com/2009/05/12/clickonce-and-startup-on-windows-logon-vista/


    Software Developer - Web/Mobile Applications
    • Proposed As Answer by Dipesh A Thursday, June 11, 2009 3:45 AM
    •