Murray Gordon

Flash a-ah! Savior of the universe...

  Home  |   Contact  |   Syndication    |   Login
  190 Posts | 2 Stories | 191 Comments | 100 Trackbacks

News

Google My Blog

Tag Cloud


Article Categories

Archives

Post Categories

Image Galleries

Blogs

Here's a great post on how to add a desktop shortcut to ClickOnce Deployed Application. (Scott Schecter's post)
http://blog.scottschecter.net/TheZenOfTheClickOnceDeployedApplicationDesktopShortcut.aspx

Here's the version of this solution in VB. (Julia Lerman's post)
http://blog.ziffdavis.com/devlife/archive/2006/07/28/42695.aspx

If you don't want to follow the link, here's the code:

/// <summary>

/// This will create a Application Reference file on the users desktop

/// if they do not already have one when the program is loaded.

//    If not debugging in visual studio check for Application Reference

//    #if (!debug)

//        CheckForShortcut();

//    #endif

/// </summary

void CheckForShortcut()

{

    ApplicationDeployment ad = ApplicationDeployment.CurrentDeployment;

 

    if (ad.IsFirstRun)

    {

        Assembly code = Assembly.GetExecutingAssembly();

 

        string company = string.Empty;

        string description = string.Empty;

 

        if (Attribute.IsDefined(code, typeof(AssemblyCompanyAttribute)))

        {

            AssemblyCompanyAttribute ascompany = (AssemblyCompanyAttribute)Attribute.GetCustomAttribute(code,

                typeof(AssemblyCompanyAttribute));

            company = ascompany.Company;

        }

 

        if (Attribute.IsDefined(code, typeof(AssemblyDescriptionAttribute)))

        {

            AssemblyDescriptionAttribute asdescription = (AssemblyDescriptionAttribute)Attribute.GetCustomAttribute(code,

                typeof(AssemblyDescriptionAttribute));

            description = asdescription.Description;

        }

 

        if (company != string.Empty && description != string.Empty)

        {

            string desktopPath = string.Empty;

            desktopPath = string.Concat(Environment.GetFolderPath(Environment.SpecialFolder.Desktop),

                "\\", description, ".appref-ms");

 

            string shortcutName = string.Empty;

            shortcutName = string.Concat(Environment.GetFolderPath(Environment.SpecialFolder.Programs),

                "\\", company, "\\", description, ".appref-ms");

 

            System.IO.File.Copy(shortcutName, desktopPath, true);

        }

 

    }

}

Hope it helps out.

Thanks,
Murray

posted on Wednesday, October 04, 2006 7:04 PM

Feedback

# re: How to add Desktop Shortcut to ClickOnce Deployment Application 6/11/2007 6:48 AM vampire
can anybody tell me where to put that code in the project ???
i am having no idea !!!

# re: How to add Desktop Shortcut to ClickOnce Deployment Application 1/4/2008 1:08 PM Brandon
put it in the application event for startup, or anywhere you want it to run

# re: How to add Desktop Shortcut to ClickOnce Deployment Application 1/4/2008 3:25 PM Brandon
Here is the VB, i had to change the company and description part to work properly with the directories of my installation

' <summary>
' This will create a Application Reference file on the users desktop
' if they do not already have one when the program is loaded.
' If not debugging in visual studio check for Application Reference
' #if (!debug)
' CheckForShortcut();
' #endif
' </summary

Private Sub CheckForShortcut()
Dim ad As System.Deployment.Application.ApplicationDeployment
ad = System.Deployment.Application.ApplicationDeployment.CurrentDeployment

If (ad.IsFirstRun) Then
Dim code As System.Reflection.Assembly = System.Reflection.Assembly.GetExecutingAssembly()
Dim company As String = String.Empty
Dim description As String = String.Empty

If (Attribute.IsDefined(code, GetType(System.Reflection.AssemblyCompanyAttribute))) Then
Dim ascompany As System.Reflection.AssemblyCompanyAttribute
ascompany = Attribute.GetCustomAttribute(code, GetType(System.Reflection.AssemblyCompanyAttribute))
company = ascompany.Company
End If

If (Attribute.IsDefined(code, GetType(System.Reflection.AssemblyTitleAttribute))) Then
Dim asdescription As System.Reflection.AssemblyTitleAttribute
asdescription = Attribute.GetCustomAttribute(code, GetType(System.Reflection.AssemblyTitleAttribute))
description = asdescription.Title

End If

If (company <> String.Empty And description <> String.Empty) Then
Dim desktopPath As String = String.Empty
desktopPath = String.Concat(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "\", description, ".appref-ms")

Dim shortcutName As String = String.Empty
shortcutName = String.Concat(Environment.GetFolderPath(Environment.SpecialFolder.Programs), "\", company, "\", description, ".appref-ms")

System.IO.File.Copy(shortcutName, desktopPath, True)
End If

End If

End Sub

# re: How to add Desktop Shortcut to ClickOnce Deployment Application 5/19/2008 9:54 AM Michael Sync
Thanks a lot for your code.....It helps me a lot..

btw, two links in your post are dead..

# re: How to add Desktop Shortcut to ClickOnce Deployment Application 6/2/2008 11:25 AM Andy
Two questions if I may

1) Won't the IsFirstRun test be true every time the application is updated via clickonce, since each update is a new versioned app.

2) Since click once is placed in a version referenced folder then every time you update the app a new icon will apear on the desctiop pointing to this new folder.

Are the above correct or am I missing the point.

# You need to add two references 6/5/2008 3:39 PM Jerry Odom
For the lazy and the newbies out there don't forget to add references to the appropriate namespaces:
using System.Deployment.Application;
using System.Reflection;

# re: How to add Desktop Shortcut to ClickOnce Deployment Application 10/15/2008 3:15 AM Christian
You must also check if ApplicationDeployment.IsNetworkDeployed is true before running this code. If the application is distributed any other way than ClickOnce this code will fail.

# re: How to add Desktop Shortcut to ClickOnce Deployment Application 1/13/2009 11:54 AM Jack M
Am I missing something? There's a checkbox on the Publish tab -> Options -> Manifest that, if checked, will cause a desktop shortcut to be created.



# re: How to add Desktop Shortcut to ClickOnce Deployment Application 1/27/2009 12:54 PM newbie
Please do not publish redundant code


Publish tab -> Options -> Manifest does the trick.

# re: How to add Desktop Shortcut to ClickOnce Deployment Application 1/28/2009 1:16 PM cmac
I don't have a Publish tab->Options->Manifest using VS2008 on project designer. What check-box is it and where specifically?

# re: How to add Desktop Shortcut to ClickOnce Deployment Application 2/5/2009 6:30 PM azmrtwo
Same here...no Publish tab->Options->Manifest - VS 2005 SP1

# re: How to add Desktop Shortcut to ClickOnce Deployment Application 2/16/2009 3:40 PM Boz
Create Shortcut option appears from VS2008 SP1

# re: How to add Desktop Shortcut to ClickOnce Deployment Application 2/21/2009 4:52 PM Cry
My "create desktop shortcut" is greyed out under Publish > Options > Mainfests *ACK* I am just trying to run some command arguments to my application, and can't seem to make an editable shortcut to the darn thing!

Help?

Thanks!

Cry

# re: How to add Desktop Shortcut to ClickOnce Deployment Application 2/21/2009 6:29 PM Cry
Well.... discovered that the CREATE DESKTOP SHORTCUT is greyed out because the project isn't (wasn't) set to compile in .NET 3.5 (which you can change by going to the project properties page under compile - advanced options)

However, I still can't seem to put any arguments into the shortcut because it is part of a click once assembly rather then a normal application.

The battle continues.

Cry

# re: How to add Desktop Shortcut to ClickOnce Deployment Application 3/1/2009 10:52 AM Chris White
I've posted some information on how to get the desktop shortcut option into your application manifest:

http://devgems.blogspot.com/2009/03/clickonce-createdesktopshortcut-option.html

# re: How to add Desktop Shortcut to ClickOnce Deployment Application 3/12/2009 4:48 PM Nigel Stratton
Thanks for the code!

# re: How to add Desktop Shortcut to ClickOnce Deployment Application 3/19/2009 1:17 PM David Simmonds
I do not see any place in VS 2008 to set the ability to create a desktop shortcut for ClickOnce. I have Target Framework set to .NET Framework 3.5. Where do I find the checkbox?

# re: How to add Desktop Shortcut to ClickOnce Deployment Application 4/6/2009 1:48 PM Katie
I've implemented this code and am now running into a different issue with it. When a user has version 1 of my application and updates to version 2 via ClickOnce, the shortcut is created properly but if the user had moved the icon to a preferred position on their desktop the icon has moved. Do you know of any way that the position of the shortcut on the desktop can be controlled in code?

Any help would be appreciated. Thanks for the great work around!

# re: How to add Desktop Shortcut to ClickOnce Deployment Application 5/6/2009 9:42 AM DevilBoy
David,
Make sure you are using Visual Studio 2008 *SP1* That was my problem.

Katie,
As far as I know (and feel free someone to correct me), that type of information is kept within the registry... you would need to parse that information. I came up with the following places, but have not confirmed it myself:

•HKEY_CURRENT_USER\Software\Microsoft\Windows\ShellNoRoam
•HKEY_CURRENT_USER\Software\Microsoft\Windows\Shell
•HKEY_CURRENT_USER\Software\Classes\Local Settings\Software\Microsoft\Windows\Shell (Only in Windows Vista)

# re: How to add Desktop Shortcut to ClickOnce Deployment Application 5/14/2009 11:35 AM rsyed
Thanks for posting this for those of us who are still using 2.0 Framework.

# Here is where to find the PUBLISH tab! 6/21/2009 5:53 AM Beltshumeltz
Right-click on your solution in the Solution explorer. Go to Properties.

You will find a PUBLISH tab on that page.

Click on OPTIONS followed by MANIFEST and you will find the Create Desktop Shortcut there.

And for this guy: 1/27/2009 12:54 PM newbie who asked the author to "not publish redundant code", you should pay more attention to the date of the post! It was in 2007!

# Here is where to find the PUBLISH tab! 6/21/2009 5:54 AM Beltshumeltz
or even worse, it was from 2006 actually.

Post A Comment
Title:
Name:
Email:
Website:
Comment:
Verification: