Click here to Skip to main content
15,896,063 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hellow guys,

does anyone help me, cause i want to have a shortcut of my application to desktop without using the right click command to send to Desktop(create shortcut). I want to code it in my application so that after installing it, it will automatically create shortcut to desktop....
I have done nothing yet...so please help me....

Thanks in advance...
Posted
Comments
Dr.Walt Fair, PE 26-Nov-10 22:27pm    
Does it have to be part of the program? If so, why?

That is usually done in the installation program. If you use a VS Setup project, you can have a shortcut created when the program in installed without really coding anything.
 
Share this answer
 
Comments
jleonorlane 27-Nov-10 0:01am    
..can you please tell me how to done that thing...please..
Dr.Walt Fair, PE 27-Nov-10 0:57am    
See, for example, http://www.dreamincode.net/forums/topic/58021-deploying-a-c%23-application-visual-studio-setup-project/ for information on how to create a Setup Project.
jleonorlane 27-Nov-10 4:26am    
..thanks for this effort...
Check out this link. It seems to be a reasonable solution. I have not tested it, but it looked pretty good just scanning over the code.
Try This.
 
Share this answer
 
Comments
jleonorlane 27-Nov-10 4:26am    
..thanks also helpful...
If you use an icon file in your project, you can use this or any other pic in your setup project. You have an option to use an image as a shortcut in you setup project.
Hope this helps

regards Zeldacat
 
Share this answer
 
If you use ClickOnce to deploy the project, you do not have the option to automatically setup a desktop icon. If that is the case, here is the code I found somewhere and use to create the shortcut in code:

VB
'Get the company and description from the deployment (they correspond to the folder the shorcut
                'is located in within the start menu and the name of the shortcut)
                Dim ad As System.Deployment.Application.ApplicationDeployment
                ad = System.Deployment.Application.ApplicationDeployment.CurrentDeployment

                Dim code As System.Reflection.Assembly = System.Reflection.Assembly.GetExecutingAssembly()
                Dim company As String = String.Empty
                Dim description As String = String.Empty

                'Get the company
                'NOTE: For this to work, the Assembly Company Attribute must equal the Publisher Name in Publish Options
                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

                'Get the description
                'NOTE: For this to work, the Assembly Title Attribute must equal the Product Name in Publish Options
                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 the company is blank, then set it to the description
                If company = String.Empty Then company = description
                Dim desktopPath As String = String.Empty, shortcutName As String = String.Empty
                If (company <> String.Empty And description <> String.Empty) Then
                    'Determine what name the desktop shortcut will have
                    desktopPath = String.Concat(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "\", description, ".appref-ms")

                    'Determine the location of the current start menu shortcut
                    shortcutName = String.Concat(Environment.GetFolderPath(Environment.SpecialFolder.Programs), "\", company, "\", description, ".appref-ms")

                    'Copy the start menu shortcut to the desktop
                    If System.IO.File.Exists(shortcutName) Then
                        Try
                            System.IO.File.Copy(shortcutName, desktopPath, True)
                        Catch ex As Exception
                            'Don't report any errors.  If it doesn't work too bad
                        End Try
                    End If
                End If 'Company and description are filled
 
Share this answer
 
Comments
jleonorlane 29-Nov-10 20:40pm    
...where should put this code?in a main form of my app...?
Kschuler 30-Nov-10 9:32am    
I guess it depends on when you want the shortcut made. I put the code on the load even of my main form. Also, I forgot that this block of code is enclosed in an If statement to make sure it is a click once deployement:
'Check to make sure the application has been deployed via ClickOnce
If System.Deployment.Application.ApplicationDeployment.IsNetworkDeployed Then

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900