Add a Desktop Icon "Option" to your VB 2008 project
Use this board to post your code snippets - tips and tricks
7 posts
Page 1 of 1
first off goto
Project > Add Reference > COM Tab > scroll down to "Window Script Host Object Model" then click ok
Add this to the top of the form
Form_Load Event
Then the function will look like this
In a Checkbox or Button event add this
If you uncheck the checkbox it will delete the shortcut from your desktop.
Project > Add Reference > COM Tab > scroll down to "Window Script Host Object Model" then click ok
Add this to the top of the form
Code: Select all
Imports IWshRuntimeLibrary
Imports Microsoft.Win32
Form_Load Event
Code: Select all
If DesktopShortcutExist() = True Then
ChkBoxDesktop.Checked = True
ElseIf DesktopShortcutExist() = False Then
ChkBoxDesktop.Checked = False
End If
Then the function will look like this
Code: Select all
Public Function DesktopShortcutExist() As Boolean
Dim deskTopDir As String = My.Computer.FileSystem.SpecialDirectories.Desktop
If IO.File.Exists(deskTopDir + "\" + Application.ProductName + ".lnk") Then
Return True
Else
Return False
End If
End Function
In a Checkbox or Button event add this
Code: Select all
What this does is set an shortcut on your desktop when you check the checkbox. Private Sub ChkBoxDesktop_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ChkBoxDesktop.Click
If ChkBoxDesktop.Checked = True Then
Dim WshShell As WshShellClass = New WshShellClass
Dim MyShortcut As IWshRuntimeLibrary.IWshShortcut
' The shortcut will be created on the desktop
Dim DesktopFolder As String = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory)
MyShortcut = CType(WshShell.CreateShortcut(DesktopFolder & "\" + Application.ProductName + ".lnk"), IWshRuntimeLibrary.IWshShortcut)
MyShortcut.TargetPath = Application.StartupPath + "\" + "Feather Editor v2.0t.exe" 'Specify target file full path
MyShortcut.Save()
Else
Dim Desktop As String = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory)
My.Computer.FileSystem.DeleteFile(Desktop + "\" + Application.ProductName + ".lnk")
End If
End Sub
If you uncheck the checkbox it will delete the shortcut from your desktop.
Nice, Thanks for this
You're crazy!
I'm not crazy, my mother had me tested. ~Sheldon Cooper
I'm not crazy, my mother had me tested. ~Sheldon Cooper
Awesome Scottie
cooll;
cooll;
Nailing my feet to the floor is easier than using my own muscles to balance, but you don't see me doing that
This was one of my favorite apps creating a shortcut in desktop. Thanks for sharing Scottie, very nice. wahooo; clapper; cooll;
7 posts
Page 1 of 1
Copyright Information
Copyright © Codenstuff.com 2020 - 2023