Install Clickonce Programmatically Import

Posted : admin On 19.01.2020

As you may have gathered from, I’ve been playing around with ClickOnce a bit lately. The latest head-scratcher is how to get a ClickOnce deployed application to run at startup. It should be a no-brainer (just copy a shortcut in the startup folder, right?) but when you add Vista to the mix all hell breaks loose (and when I say “all hell breaks loose” I mean nothing happens at startup.) I finally sat down this weekend and put together a sample application and some documentation to support my findings.

Any help or feedback is greatly appreciated. The main goal is to determine a reliable, reusable way to add AutoStart functionality to any ClickOnce deployed application for any Windows operating system. Again, piece of cake, right? Quick Overview An application shortcut is copied to the Start Menu Programs directory as part of the installation process for a ClickOnce application which is configured to be available offline 1. For example, for me on Vista, the attached sample application’s shortcut is placed in the following location: C: Users Ben Griswold AppData Roaming Microsoft Windows Start Menu Programs Ben Griswold ClickOnceAutoStart.appref-ms. The shortcut location and file name are based on the Publisher name (Ben Griswold) and the Product name (ClickOnceAutoStart) as defined in the project’s Publishing Options 2. It is important to note that the shortcut’s location and file name are NOT based on the executing assembly’s Company and Product values 3, however, the Publishing Options and Assembly Information values are often identical (as is the case in the attached sample application.) Though Visual Studio provides a means to add an application shortcut to the products folder in the Start Menu Programs directory as well as the Desktop 4, there does not appear to be an out-of-the-box means to add a shortcut to Startup Folder.

In other words, there is no configuration setting to enable the ClickOnce application to run at startup. ClickOnce AutoStart Solutions There are two sited ways to implement run at startup functionality. Both options, however, come with drawbacks and issues.

Solution 1 Programmatically copy the application’s Start Menu Program shortcut (the Application Reference file) into the Startup folder. Start Menu Programs Ben Griswold Start Menu Programs Startup Issue 1 – There doesn’t appear to be a reliable way to determine where the ClickOnce installer placed the Start Menu Program.appref-ms shortcut. As stated above, the shortcut location is based on the Publishing Options.

Programmatically

Can one programmatically read the Publisher and Product name? Is this information is available via the AppDomain.ActivationContext Property? The bottom-line is, if the shortcut location can’t be determined then the file can’t be copied. Arguably, this isn’t a serious issue since the shortcut location could be “pre-calculated” and stored elsewhere in the application.

Install Clickonce Programmatically ImportImport

For example, in Application Settings or within AssemblyInfo which seems to be the de facto standard. All the same, since this Publisher and Product are displayed on the Deployment Web Page 5, it is reasonable to assume the values must be exposed. Issue 2 – Copying the Application Reference shortcut into the Startup folder doesn’t work reliably in Windows Vista. This is the case whether UAC is enabled or not. Interestingly, the same shortcut can successfully launch the application if it is manually executed by the user, but under standard OS startup the shortcut is never triggered. Issue 3 – Another issue is tied to the uninstall. Is there a way to hook into the uninstall of a ClickOnce application?

If not, there doesn’t appear to be a way to remove any/all artifacts which may have been programmatically added to the end users system. In other words, after the product uninstall, it would become the end user’s responsibility to remove the shortcut file which was programmatically copied into the Startup folder. Coincidently, the Start Menu Programs shortcut and desktop shortcut are all removed when the ClickOnce application is uninstalled. Solution 2 Programmatically create a URL shortcut file which maps to the ClickOnce application’s update location and place it in the Startup folder. I am happy to say this method does work reliably in Windows Vista.

Issue 1 – Though creating an URL shortcut file which maps to the ApplicationDeployment.CurrentDeployment.UpdateLocation.AbsoluteUri works consistently, an empty browser window is launched when the Uri is being queried. Again, this solution works but it isn’t particularly clean. Issue 2 – Same uninstall issue as outline above. Sample Application The accompanying sample application illustrates how to enable run at startup using either of the two techniques stated above.

One may validated the functionality and issues by launching the application (after installing via ClickOnce) and then enabling the AutoStart options, verifying shortcut are valid and testing the AutoStart functionality per a system restart. Again, any help or feedback is greatly appreciated. The main goal is to determine a reliable, reusable way to add AutoStart functionality to any ClickOnce deployed application for any Windows operating system.

Hi, Just thought I’d leave a quick post in case youve not already resolved the issue yourself. I have a similar issue trying to resolve the ‘publisher/suiteName/product’ information – these values are required if you need to launch a click once application programmatically, the information in the assembly does not reliably describe the ‘start menu’ path to the click once app.

The information you need is in the.application deployment manifest which is located at the URI where the application is installed from. I have written some c# code to extract this information into a ‘DeploymentDescription’ class which has ‘Publisher’,’SuiteName’ & ‘Product’ properties. The code employs the services of an InPlaceHostingManager to asynchronously aquire the manifest from the application host URI. It is then possible to use an XmlReader to extract the required info. Post back if you would like the source code. Cheers, Andy. Here is what I’m using, I’m pretty sure it is going to work but I haven’t fully tested it.

I’ve got a lot more hard coding in here than you would want but that can be gathered easily if necessary. Lo specchio di beatrice pdf download. Here is a simplified version with a few bug fixes from above, only think that would make this a little better would be pulling the app info and publisher info, this just uses the Assembly info. Dim key As RegistryKey = Registry.CurrentUser.OpenSubKey(“Software”) key = key.OpenSubKey(“Microsoft”) key = key.OpenSubKey(“Windows”) key = key.OpenSubKey(“CurrentVersion”) key = key.OpenSubKey(“Run”, True) Dim rootdir = “” If System.IO.Directory.Exists(“C: Users”) Then rootdir = “C: Users ” Else rootdir = “C: Documents and Settings ” key.SetValue(“QBCommenter”, rootdir + Environment.UserName + “ AppData Roaming Microsoft Windows Start Menu Programs ” + My.Application.Info.CompanyName + “ ” + My.Application.Info.ProductName + “.appref-ms”). Just thought I’d throw this out there to the interwebs incase someone else googles this.

Copies the appref-ms to all users startup. MUST BE ADMIN after that gravy for other users. It works on XP and I’ll probly test something similar out on Win7 a bit later as for Vista, L to the O to the L, why bother. Dim userName As String userName = Environment.UserName If My.Computer.FileSystem.FileExists(“C: Documents and Settings All Users Start Menu Programs Startup YOURAPP.appref-ms”) Then Else My.Computer.FileSystem.CopyFile(“C: Documents and Settings ” & userName & “ Start Menu Programs YOURAPP YOURAPP.appref-ms”, “C: Documents and Settings All Users Start Menu Programs Startup YOURAPP.appref-ms”, overwrite:=True) End If. Hi Ben, I’m researching an idea that also requires clickonce. It should run on startup and be able to uninstall itself cleanly.

Clickonce Download

I was thinking if it would be possible to install another executable (possibly deployed as a prerequisite) that runs at startup and would be responsible for locating and starting the clickonce app, but wouldn’t be a clickonce app itself. It could uninstall itself when the clickonce app is no longer installed or, in my case, the clickonce app could uninstall it before it uninstalls itself.

I read that with script installers like NSIS it’s possible to do installs without user interaction, so that might still make it a clickonce experience, even though 2 apps are installed. It sounds a bit like a security issue to me so it might not be possible to install such an executable at all with clickonce, but perhaps it isn’t. What’s your opinion, would it work in one way or another? Just wrote a batch script that works by means of solution 2 but is cleaner (minimizes internet explorer so its never seen) and also handles the possibility of clearing the batch file from the startup menu in the first reboot after the click once app is uninstalled.

The.bat code: IF EXIST “%userprofile% desktop Application Name.appref-ms” ( start /min iexplore “ URL shortcut file to update location” ) ELSE (del%0) This code checks first on the desktop for application being present but it can be pointed to the AppData directory if desktop icon is not needed. It then improves upon the internet explorer cleanliness by loading the application through IE in minimized mode.

It loads up and closes IE out before the user has a chance to even open IE. Not perfect but the best I’ve found so far. Finally, I figured out the removal of the batch script from startup after a uninstalling the ClickOnce App. With an Else statement if file does not exist(which it won’t upon the uninstall), the function del%0 deletes the batch file itself and so clears the startup menu of this batch file.

All that is required is a reboot following the uninstall and the batch file will delete itself. All I have to do to make this work is add this batch file to resources in my application(startup.bat or some such file name) and use File.WriteAllText to write it to the start up menu upon loading the app. Every time the application loads, I can check that this startup batch file is still present and rewrite it there if needed. Hope this helps and let me know your feedback!