This GoldMail shows how to create a desktop shortcut for your ClickOnce application. The code can be used for any ClickOnce application, assuming you set your attributes accordingly.
This download contains the sample code (VS2008, C#). If you are a VB developer and can’t figure out how to translate this to VB, post a query and I’ll see what I can do for you.
ClickOnce_DesktopShortcut.zip
ClickOnce_DesktopShortcut.zip
July 19, 2009 edit: Here is a link to the follow-up post that provides the code and implementation details for doing same in VB.
ClickOnce Desktop Shortcut Using VB
[edit 7/7/2011 Move zip file to Azure blob storage]
[edit 3/8/2014 Move to different Azure blob storage]
July 14, 2009 at 10:23 am |
Hi,
I am a VB.Net programmer and have never even examined C#. I’ve been trying to find a resolution to this shortcut issue for some time.
I would REALLY appreciate any assistance you could afford in implementing this in VB.Net 2008. My application is distributed using the Dot.Net 2 Framework.
I thank you very much in advance for any help you can offer.
Sincerely,
Robert Cezar
July 14, 2009 at 4:32 pm |
Robert, Thanks for your feedback. I will convert the shortcut code to VB and post it, and let you know when it’s ready.
Robin
July 16, 2009 at 8:34 am |
Thank you very much. I really appreciate it.
Robert
July 20, 2009 at 12:15 am |
I have posted a follow-up with the code for the desktop shortcut in VB, and how to implement it. There is a link to the followup on the original article. Please let me know if you have any questions.
July 20, 2009 at 12:08 am |
[…] Desktop Shortcut using VB By robindotnet This is a follow-up post to the article How to Create a Desktop Shortcut for a ClickOnce Application, providing the VB version of the code, as requested by one of the readers of this […]
July 21, 2009 at 10:41 am |
Hello Robin,
Well, it worked PERFECTLY! Thank you so very much for your help… I was pulling my hair out (not much left) with this problem.
As a small note of appreciation, we’ve posted our thanks in the Kudos section of our Web site.
http://www.ItsYourPlane.com/kudos.asp
PS. If you’re into flight simulation, you’re welcome to a FREE registration!
Thanks again.
Robert
July 21, 2009 at 3:56 pm |
Hello Robert,
I’m glad it was helpful to you. I hope the implementation info was, too. It’s been awhile since I did VB (we use mostly C# at GoldMail, except the Office Add-ins, which are in VB), so I had to think about how to implement it; I didn’t want to assume that people would know. It’s actually a joy to do VB again, and it’s nice to hear of a development shop using it. One of my friends at MSFT tells me there are more VB devs than C#. š And thanks for the kudos on your website; I appreciate it!
Also, thanks for the free offer, but unfortunately I already know that I am terrible at flying. Remember the Microsoft Flight Simulator that came out in the 80’s? I used to try to play that, and I always crashed. But I’ll keep your offer in mind in case I want to try again! I think they recently discontinued theirs, so it’s nice to know there’s another version available on the market.
If you have any further problems with ClickOnce, please feel free to post your question to the MSDN ClickOnce and Setup & Deployment forum, and I’ll help you out. You can ping me here if you do that, to make sure I see it, although I try to respond to most of the postings.
Robin
July 23, 2009 at 2:58 pm |
Thank you very much, Ive been trying to figure out how to do this with vb.net for the past week. Very simple and easy to follow.
July 23, 2009 at 8:49 pm |
You’re welcome; I’m glad it’s helpful. I can translate any of my posts into VB, so if you need anything else, just let me know!
Robin
August 10, 2009 at 2:02 pm |
Thanks! This was very helpful and easy to follow.
August 11, 2009 at 6:23 pm |
I’m glad it was helpful to you!
August 17, 2009 at 1:29 pm |
Maybe I am just missing the point.?. We have all asked how to create a desktop icon when you publish an application. Although this is nice code and does work, it does not address the issue. If I have a user that needs to run the application from the desktop and it goes missing, they call me for support. Once we run the application from whereever, it creates the desktop icon but they still call me next week when it dissappears again. So is there a way (in .NET 2.0) to create this as you install or auto run another application that creates the shortcut for you?
August 20, 2009 at 12:29 am |
Why is your user’s desktop shortcut disappearing? Are you using the code I’ve posted here? It creates the shortcut whenever the user gets an update or when he installs the application for the first time. That is what IsFirstRun tells you.
I wrote it like that because it seems to me like the shortcut disappears and must be recreated whenever the user gets an update. I suspect that when Microsoft added the autocreation of the shortcut in .Net 3.5, in order to save themselves the trouble of figuring out if something about it changed, they just remove it when the application starts to install, and then if you have set that property in the deployment, it recreates it. We aren’t using the auto-creation because we are still targeting the .NET 2.0 Framework, so my code recreates the shortcut.
August 19, 2009 at 3:52 pm |
Seems like this wouldn’t work in Visual C# Express Edition because I can’t find those options.
August 19, 2009 at 10:32 pm |
Are you talking about the checkbox for creating the shortcut panel in the Options dialog? If so, this should be available in the 2008 edition of Visual C# Express. To use it, you must be targeting the .NET 3.5 Framework. Otherwise, you must use the programmatic method. If I’ve misunderstood your question, please clarify.
Thanks,
RobinDotNet
August 20, 2009 at 9:13 am |
My Publish Options dialog box looks entirely different. It looks like this: http://learnwpf.com/Data/Images/LearnWPF.XBAP.PublishOptionsDialog2.jpg (not my image or site)
August 20, 2009 at 11:36 am |
I think you’re running VS2005; they changed the dialogs in VS2008, and the new features are only available there. In Visual Studio, click on Help and then About — what does it say there?
August 20, 2009 at 11:38 am
Microsoft Visual Studio 2008
Version 9.0.21022.8 RTM
© Microsoft Corporation.
All rights reserved.
Microsoft .NET Framework
Version 3.5 SP1
© Microsoft Corporation
All rights reserved.
August 27, 2009 at 11:07 am
Hi Chris,
Sorry for the delay. I was having problems getting VMWare to work on my new Windows 7 build. I installed Visual C# Express in a VM running WinXP. It installed .Net 3.5 SP-1 of course. Mine says:
Microsoft Visual Studio 2008
Version 9.0.30729.1 SP
and it shows the right version of the dialogs. The dialog you are seeing is not the one for VS2008 SP-1. My guess is you did not install SP-1 for Visual Studio 2008. This is different than SP-1 for .Net 3.5. Here’s the link:
http://www.microsoft.com/downloads/details.aspx?familyid=FBEE1648-7106-44A7-9649-6D9F6D58056E&displaylang=en
Please try this and let me know how you get on.
April 27, 2010 at 8:44 pm
Verrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrry tank you.
August 27, 2009 at 2:56 am |
Great explanations ! Thanks for the sharing.
September 11, 2009 at 5:25 am |
Sorry if I’m posting this twice . . but the other place I posted it doesn’t have any other comments…
I am trying to use the VB version of the code and when installing the click once deployment on our machines, we are getting the following error:
*** System.IO.FileNotFoundException: Could not find file āC:\Documents and Settings\jrose\Start Menu\Programs\Generation Mortgage Company\Generation Equity Mortgage System.appref-msā.
File name: āC:\Documents and Settings\jrose\Start Menu\Programs\Generation Mortgage Company\Generation Equity Mortgage System.appref-msā
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.File.InternalCopy(String sourceFileName, String destFileName, Boolean overwrite)
at System.IO.File.Copy(String sourceFileName, String destFileName, Boolean overwrite)
at Gfm.Gems.UI.My.MyApplication.CheckForShortcut()
at Gfm.Gems.UI.My.MyApplication.MyApplication_Startup(Object sender, StartupEventArgs e)
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnStartup(StartupEventArgs eventArgs)
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
ANY help would be greatly appreciated!
September 13, 2009 at 10:56 am |
This might benefit someone NOT using the VB version, so I’m going to answer this question here as well.
The code basically looks for the shortcut on the start menu and copies it to the desktop. To locate the entry on the start menu, it has to have the name of the folder and the name of the shortcut itself.
In a ClickOnce deployment, the Publisher Name is used for the name of the folder, and the Product Name is used for the name of the actual shortcut.
Rather than hardcoding those values, the code for the shortcut uses Reflection to retrieve the corresponding information from the Assembly. It assumes the Assembly Company matches the Publisher Name, and the Assembly Description matches the Product Name.
From the error you are showing here, that’s not the case. It looks like it can’t find the shortcut it wants to copy. So check your Assembly information against your Publish Options and make those two values match, and it should work.
September 14, 2009 at 9:14 am |
Thank you so much for your help! It is greatly appreciated. That worked. You were correct . . the Description didn’t quite match my product name.
September 16, 2009 at 3:18 pm |
Thanks; I’m glad I was able to help you!
September 16, 2009 at 4:33 pm
Hi Robin!
ItĀ“s necessary the code line “ConfigManager.LoadConfigSettings();”, right?
Cause my ClickOnce app donĀ“t let me use it. Says ConfigManager doesnĀ“t exists in the context.
I use System.Deployment.Application and System.Reflection.
Please, help me.
September 16, 2009 at 5:45 pm
No, that must be a remnant from the code I copied it from. Is that in the code I posted?? I’ll remove it. Thanks for letting me know!
February 3, 2010 at 11:05 pm |
HI,
Thanq for ur help,But one more thing how to remove desktop icon when we uninstall that appliction.
February 9, 2010 at 11:10 am |
Hi Sasi,
ClickOnce should remove the desktop icon when it uninstalls the application. That’s the behavior we are seeing, and we target .NET 2.0.
Robin
June 30, 2010 at 5:32 am |
Hi Robin,
Thanks for your helpful article. I have another Problem; I have an application that many users are working with that. I recently changed it so it can publish and install with click once. Your Article resolved one of my big troubles (About putting shortcut on the desktop). But I want to auto start and perform Installing click once progress. (Ideal scenario is a silent installation that user never sense anything).
Can you help me about it?
Regards
July 1, 2010 at 11:52 pm |
There is a way to have a ClickOnce app start when the computer starts up. However, you might have problems getting your updates if the internet connection doesn’t come up faster than the ClickOnce app. What type of application is it and what does it do that you need it to run at startup?
September 3, 2010 at 9:42 am |
Hey Robin,
Thanks for the article great stuff! But I am having one issue. The icon is created on the first run but whenever I update the app using clickonce the desktop icon is removed and it is not created again since it is not it’s first run. Is there a work around this?
September 3, 2010 at 10:24 am |
Hi. When Microsoft added the auto-desktop-shortcut-create function in .NET 3.5, they also changed the ClickOnce engine to remove the desktop shortcut every time there was an update, probably so they could just create a new one without worrying about it already being there. So just take out the check for IsFirstRun and let the code create the desktop shortcut every time the app runs.
September 3, 2010 at 10:28 am |
I am running visual studio 2005, 2.0 framework. Is there anyway I can do this ?
September 3, 2010 at 10:43 am |
I wrote the code with VS2005 and .NET 2.0, so it should work with those. (As noted above, MSFT changed it to remove the shortcut with .NET 3.5, so you just need to take out the check for IsFirstRun and let it create the shortcut each time it runs).
September 3, 2010 at 10:48 am
Yeah I the icon is created at first run but when I update the application, it is removed and then not created again..Anyways, thanks for your time.
September 20, 2010 at 3:05 am |
I am using Visual studio 2008 in Windows 7. I dont get an option to check create desktop shortcut and even i dont have that manifest tab itself. And when i run the same Visual Studio in Windows xp i get the option. Please let me know is there an option to include as i am using framwork 3.5 only.
September 20, 2010 at 2:04 pm |
Be sure you have Sp-1 for VS2008 installed. You can see this in Help/About. I suspect you don’t, and that’s why you’re not seeing the option.
RobinDotNet
January 28, 2011 at 12:22 pm |
Thanks Robin! I’m targeting NET 2.0 so this comes really helpful.
January 30, 2011 at 1:20 am |
You’re welcome. Even though we target .NET 3.5 now, I still use this code. Another interesting option — this code basically puts the shortcut back on the desktop every time they run the application. By programming this rather than using the Visual Studio option in later versions of .NET, you can give the user an option to say “I don’t want a desktop shortcut”, and NOT create it when he runs it.
April 20, 2011 at 12:12 am |
Hello sir,
I am getting error bellow with your code:
The name ‘ConfigManager’ does not exist in the current context
[Code]
Thread.CurrentThread.CurrentUICulture = new CultureInfo(“fr”);
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
ConfigManager.LoadConfigSettings();
CheckForShortcut();
Application.Run(new ANAHRDB.Forms.Login());
[/code]
April 21, 2011 at 9:28 am |
That was a remnant of code from my own project. I rolled my own configuration manager because i don’t like the way ClickOnce handles it. Just take it out.
Robin
May 10, 2011 at 2:20 pm |
Robin –
Very nice article. You addressed sp1 for 2008 in a reply above to someone named chris. I am having the same problem he mentioned (2005 version of the options window). I installed sp1 (from your link) and am still dealing with the same window.
Do you have a suggestion? I am on Windows 7-64.
thanks ahead of time!
– kyle
May 31, 2011 at 2:08 am |
Hi, as noted in my response to Chris, you have to have VS2008 SP-1 to access those fatures. They are not available in VS2005. Can you upgrade all the way up to VS2010 and use the Express version? What version of .NET does your application target?
Robin
June 11, 2011 at 11:41 am |
[…] […]
November 8, 2011 at 9:21 am |
This code is not working. I think AssemblyProductAttribute should be used instead of AssemblyDescriptionAttribute.
November 11, 2011 at 2:52 pm |
The code is right and matches the description. Basically, whatever field you use in the Assembly information is the field you have to look for. I’m putting the match in the Assembly Description, so I’m looking at the AssemblyDescriptionAttribute. If you put the name in the Assembly Product information, you would need to look at the Assembly Product Attribute.
-Robin
April 5, 2012 at 10:57 am |
Reblogged this on Harsh Baid and commented:
Nice video on Creating a desktop shortcut for a Click OnceĀ application
April 22, 2013 at 12:54 pm |
Hi robindotnet. I got a different situation. I have a vb.net application which I used the auto-desktop-shortcut-create function in the clickonce, my porblem is how can I rename the shortcut through code or prgrammatically. I have an application that i change the shortcut name based on user’s permission or type of user. do you have any idea how i can rename the shortcut and keep the name or rename it very update?