Results 1 to 40 of 40

Thread: Change Shortcut Properties/Icon

Threaded View

  1. #1

    Thread Starter
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,710

    Change Shortcut Properties/Icon

    I put this example together to demonstrate how to programmatically access a shortcut in
    the Program Files Start Menu. With variations of this code you can gain access to any property of a
    shortcut. I hope members enjoy this code and post replies of what you think of it.

    This demo will change the properties for Internet Explorer in your Start Menu > Program Files.
    Comments: the tooltip and comment description for the link.
    Arguments: it wil add an argument to the shortcut target.
    ShowCommand: it will set the window show state to Maximized
    SetIconLocation: it will change the location of the icon to use and designate the icon index to use.
    Save: Saves the changes to the shortcut.
    InvokeVerb: runs the open command (optionally by uncomenting the line of code)





    VB Code:
    1. Option Explicit
    2. 'References:
    3. 'Microsoft Shell Controls And Automation '(C:\Windows\System32\Shell32.dll)
    4.  
    5. 'ShowCommand Constants
    6. '1 Activates and restores it to its original size and position.
    7. '2 Activates the window and displays it as a minimized window.
    8. '3 Activates the window and displays it as a maximized window.
    9. Private Const ssfSYSTEM = 37             'System32 directory
    10. Private Const ssfPROGRAMS = 2            'Program Files
    11. Private Const ssfDESKTOP = 0
    12. Private Const ssfDESKTOPDIRECTORY = 16
    13. Private Const ssfDRIVES = 17
    14. Private Const ssfPERSONAL = 5            'My Documents folder
    15. Private Const ssfCOMMONDESKTOPDIR = 25
    16. Private Const ssfWINDOWS = 36            'Windows or Winnt directory
    17.  
    18. Private Sub Command1_Click()
    19. 'Original Comment: Finds and displays information and Web sites on the Internet.
    20. 'Original Argument: "" 'Uses your default home page setting. Replace arg with where you want IE to go to when opened
    21. 'Original ShowCommand: 1
    22. 'Original Icon Path: "C:\Program Files\Internet Explorer\IEXPLORE.EXE" - For my system, yours would be where ever you have IE installed to.
    23. 'Original Icon Index:
    24. 'Test Icon Path: "C:\Windows\System32\SHELL32.dll"
    25. 'Test Icon Index: 46 - Windows Update Icon
    26.     Dim oShell  As Shell32.Shell
    27.     Dim oFolder As Shell32.Folder
    28.    
    29.     Set oShell = New Shell32.Shell
    30.     Set oFolder = oShell.NameSpace(ssfPROGRAMS)
    31.         If (Not oFolder Is Nothing) Then
    32.             Dim oFolderItem As Shell32.FolderItem
    33.             Set oFolderItem = oFolder.ParseName("Internet Explorer.lnk")
    34.             If (Not oFolderItem Is Nothing) Then
    35.                 Dim oShellLink As ShellLinkObject
    36.                 Set oShellLink = oFolderItem.GetLink
    37.                 If (Not oShellLink Is Nothing) Then
    38.                     'Set the arguments for the ShellLinkObject
    39.                     oShellLink.Arguments = "http://www.vbforums.com"
    40.                     oShellLink.Description = "This text is added to the comments of the link programmatically."
    41.                     oShellLink.ShowCommand = 3
    42.                     oShellLink.SetIconLocation "C:\Windows\System32\SHELL32.dll", 46 'Windows Update Icon
    43.                     oShellLink.Save
    44.                     'oFolderItem.InvokeVerb "open" 'Opens IE and navigates to VBF !
    45.                 End If
    46.                 Set oShellLink = Nothing
    47.             End If
    48.             Set oFolderItem = Nothing
    49.         End If
    50.     Set oFolder = Nothing
    51.     Set oShell = Nothing
    52.    
    53. End Sub
    Attached Images Attached Images   
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width