Change Shortcut Properties/Icon-VBForums
Results 1 to 40 of 40

Thread: Change Shortcut Properties/Icon

  1. #1

    Thread Starter
    Super Moderator RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    59,691

    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 (VBA, VB 6, VB.NET, C#)
    Senior Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Star Wars Gangsta Rap Reps & Rating PostsVS.NET on Vista (New)Multiple .NET Framework Versions (New)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 Core 2 Extreme Ed., 2 WD Raptor 10K RPM 150 GB HDs RAID 1, 2 GBs DDR2 667 MHz RAM, 3 Viewsonic 17" LCDs, Windows Vista RTM, IE 7, Office 2007

  2. #2
    Admodistrator |2eM!x's Avatar
    Join Date
    Jan 2005
    Posts
    3,900

    Re: Change Shortcut Properties/Icon

    im confused..how does it know what shortcut to shell?

    i dont want it to shell my vb exe, but a shortcut..

    edit** nvm i think, i get this error..
    Dim oShell As Shell32.Shell
    Dim oFolder As Shell32.Folder
    "user defined type not defined"
    Last edited by |2eM!x; Feb 2nd, 2005 at 05:39 PM.

  3. #3

    Thread Starter
    Super Moderator RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    59,691

    Re: Change Shortcut Properties/Icon

    You need to add the reference to 'Microsoft Shell Controls And Automation
    (C:\Windows\System32\Shell32.dll) to your project so it knows how Shell32 is defined.

    Also, the constants are how you can determine where your link is located.

    The ssfPROGRAMS constant tells the program that the link is going to be in
    the Program Files Start Menu. I havent got it all down yet but it would be
    nice to get it to work for desktop shortcut creation/modification.
    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 (VBA, VB 6, VB.NET, C#)
    Senior Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Star Wars Gangsta Rap Reps & Rating PostsVS.NET on Vista (New)Multiple .NET Framework Versions (New)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 Core 2 Extreme Ed., 2 WD Raptor 10K RPM 150 GB HDs RAID 1, 2 GBs DDR2 667 MHz RAM, 3 Viewsonic 17" LCDs, Windows Vista RTM, IE 7, Office 2007

  4. #4
    Admodistrator |2eM!x's Avatar
    Join Date
    Jan 2005
    Posts
    3,900

    Re: Change Shortcut Properties/Icon

    shoot, thats what im doing..
    ("..\..\Desktop")
    does that work?

  5. #5

    Thread Starter
    Super Moderator RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    59,691

    Re: Change Shortcut Properties/Icon

    The const is either ssfDESKTOP or ssfDESKTOPDIRECTORY.
    But I havent
    got it to work for that yet either, only the Program Files Start Menu.
    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 (VBA, VB 6, VB.NET, C#)
    Senior Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Star Wars Gangsta Rap Reps & Rating PostsVS.NET on Vista (New)Multiple .NET Framework Versions (New)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 Core 2 Extreme Ed., 2 WD Raptor 10K RPM 150 GB HDs RAID 1, 2 GBs DDR2 667 MHz RAM, 3 Viewsonic 17" LCDs, Windows Vista RTM, IE 7, Office 2007

  6. #6
    Admodistrator |2eM!x's Avatar
    Join Date
    Jan 2005
    Posts
    3,900

    Re: Change Shortcut Properties/Icon

    when you do, report back : )

    also, how do you find out what can be read by the dll?
    i.e, how did you find the ssfdesktop command??

    or how do you tell what dll does what..

  7. #7

    Thread Starter
    Super Moderator RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    59,691

    Re: Change Shortcut Properties/Icon

    In the Object Browser (press F2) it will allow you to browse through the
    object referenced in your project. The const.'s seem to follow the CLSID_ ...
    constants for other functions like the SHBrowseForFolder API.
    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 (VBA, VB 6, VB.NET, C#)
    Senior Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Star Wars Gangsta Rap Reps & Rating PostsVS.NET on Vista (New)Multiple .NET Framework Versions (New)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 Core 2 Extreme Ed., 2 WD Raptor 10K RPM 150 GB HDs RAID 1, 2 GBs DDR2 667 MHz RAM, 3 Viewsonic 17" LCDs, Windows Vista RTM, IE 7, Office 2007

  8. #8
    Admodistrator |2eM!x's Avatar
    Join Date
    Jan 2005
    Posts
    3,900

    Re: Change Shortcut Properties/Icon

    you ever figure it out bro?

  9. #9

    Thread Starter
    Super Moderator RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    59,691

    Re: Change Shortcut Properties/Icon

    No, I havent had time. I've been writting another CodeBank entry and a few
    examples for some members. Plus working on my .NET Control. Perhaps we should
    start another thread? This thread is just for code examples.
    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 (VBA, VB 6, VB.NET, C#)
    Senior Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Star Wars Gangsta Rap Reps & Rating PostsVS.NET on Vista (New)Multiple .NET Framework Versions (New)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 Core 2 Extreme Ed., 2 WD Raptor 10K RPM 150 GB HDs RAID 1, 2 GBs DDR2 667 MHz RAM, 3 Viewsonic 17" LCDs, Windows Vista RTM, IE 7, Office 2007

  10. #10
    Admodistrator |2eM!x's Avatar
    Join Date
    Jan 2005
    Posts
    3,900

    Re: Change Shortcut Properties/Icon

    when you do, pm me

  11. #11

    Thread Starter
    Super Moderator RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    59,691

    Re: Change Shortcut Properties/Icon

    I'll post back here so you will get notification.

    You want to modify it to change a Desktop Shortcut Icon
    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 (VBA, VB 6, VB.NET, C#)
    Senior Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Star Wars Gangsta Rap Reps & Rating PostsVS.NET on Vista (New)Multiple .NET Framework Versions (New)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 Core 2 Extreme Ed., 2 WD Raptor 10K RPM 150 GB HDs RAID 1, 2 GBs DDR2 667 MHz RAM, 3 Viewsonic 17" LCDs, Windows Vista RTM, IE 7, Office 2007

  12. #12
    KING BODWAD XXI BodwadUK's Avatar
    Join Date
    Aug 2002
    Location
    Nottingham
    Posts
    2,176

    Re: Change Shortcut Properties/Icon

    Extra Notes

    You can change to search a specific directory by changing

    VB Code:
    1. Set oFolder = oShell.NameSpace(ssfPROGRAMS)
    2.  
    3. TO If you want c drive root
    4.  
    5. Set oFolder = oShell.NameSpace("c:\")


    You may also find the values on the link useful for none fixed windows folders
    http://msdn.microsoft.com/library/de...rconstants.asp


    Hope that helps everyone
    If you dribble then you are as mad as me

    Lost World Creations Website (XBOX Indie games)
    Lene Marlin

  13. #13

    Thread Starter
    Super Moderator RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    59,691

    Re: Change Shortcut Properties/Icon

    Thanks for the link but I got the consts from the clsid's from the SHGetSpecialFolderLocation API.
    Nice tip on the .Namespace Maybe I will get inspired to do more on this then.
    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 (VBA, VB 6, VB.NET, C#)
    Senior Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Star Wars Gangsta Rap Reps & Rating PostsVS.NET on Vista (New)Multiple .NET Framework Versions (New)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 Core 2 Extreme Ed., 2 WD Raptor 10K RPM 150 GB HDs RAID 1, 2 GBs DDR2 667 MHz RAM, 3 Viewsonic 17" LCDs, Windows Vista RTM, IE 7, Office 2007

  14. #14
    Frenzied Member sciguyryan's Avatar
    Join Date
    Sep 2003
    Location
    Wales
    Posts
    1,763

    Re: Change Shortcut Properties/Icon

    Is there any way using a simmilar method, to create a shortcut to a program?

    Cheers,

    RyanJ
    My Blog.

    Ryan Jones.

  15. #15

    Thread Starter
    Super Moderator RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    59,691

    Re: Change Shortcut Properties/Icon

    Yes, you can use this example to create a shortcut. It uses WSH.

    Create shortcut
    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 (VBA, VB 6, VB.NET, C#)
    Senior Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Star Wars Gangsta Rap Reps & Rating PostsVS.NET on Vista (New)Multiple .NET Framework Versions (New)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 Core 2 Extreme Ed., 2 WD Raptor 10K RPM 150 GB HDs RAID 1, 2 GBs DDR2 667 MHz RAM, 3 Viewsonic 17" LCDs, Windows Vista RTM, IE 7, Office 2007

  16. #16
    Frenzied Member sciguyryan's Avatar
    Join Date
    Sep 2003
    Location
    Wales
    Posts
    1,763

    Re: Change Shortcut Properties/Icon

    Quote Originally Posted by RobDog888
    Yes, you can use this example to create a shortcut. It uses WSH.

    Create shortcut

    Great, thanks RobDog888

    Cheers,

    RyanJ
    My Blog.

    Ryan Jones.

  17. #17

    Thread Starter
    Super Moderator RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    59,691

    Re: Change Shortcut Properties/Icon

    Ok, this update is for Remix. I figured out the issue of not being able to attach to the Desktop. Turns out that you can not use the .ParseName function on virtual directories. Since the Program Files Start Menu is a file system directory it works but on the Desktop virtual directory it fails with a return of Nothing.

    Enjoy the update guys.

    VB Code:
    1. Option Explicit
    2. 'References:
    3. 'Microsoft Shell Controls And Automation '(C:\Windows\System32\Shell32.dll)
    4.  
    5. Private Const ssfSYSTEM = 37             'System32 directory
    6. Private Const ssfPROGRAMS = 2            'Program Files
    7. Private Const ssfDESKTOP = 0
    8. Private Const ssfDESKTOPDIRECTORY = 16   'Your profile desktop
    9. Private Const ssfDRIVES = 17
    10. Private Const ssfPERSONAL = 5            'My Documents folder
    11. Private Const ssfCOMMONDESKTOPDIR = 25
    12. Private Const ssfWINDOWS = 36            'Windows or Winnt directory
    13.  
    14. Private Sub Command1_Click()
    15.  
    16.     Dim oShell  As Shell32.Shell
    17.     Dim oFolder As Shell32.Folder
    18.    
    19.     Set oShell = New Shell32.Shell
    20.     Set oFolder = oShell.NameSpace(ssfDESKTOPDIRECTORY)
    21.         If (Not oFolder Is Nothing) Then
    22.             Dim oFolderItem As Shell32.FolderItem
    23.             Dim i As Integer
    24.             Dim bFound As Boolean
    25.             For i = 1 To oFolder.Items.Count
    26.                 If oFolder.Items.Item(i) = "Test.lnk" Then
    27.                     Set oFolderItem = oFolder.Items.Item(i)
    28.                     bFound = True
    29.                     Exit For
    30.                 End If
    31.             Next
    32.             If bFound = False Then Exit Sub
    33.             If (Not oFolderItem Is Nothing) Then
    34.                 Dim oShellLink As ShellLinkObject
    35.                 Set oShellLink = oFolderItem.GetLink
    36.                 If (Not oShellLink Is Nothing) Then
    37.                     MsgBox oShellLink.Path & " " & oShellLink.Arguments
    38.                 End If
    39.                 Set oShellLink = Nothing
    40.             End If
    41.             Set oFolderItem = Nothing
    42.         End If
    43.     Set oFolder = Nothing
    44.     Set oShell = Nothing
    45.    
    46. End Sub
    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 (VBA, VB 6, VB.NET, C#)
    Senior Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Star Wars Gangsta Rap Reps & Rating PostsVS.NET on Vista (New)Multiple .NET Framework Versions (New)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 Core 2 Extreme Ed., 2 WD Raptor 10K RPM 150 GB HDs RAID 1, 2 GBs DDR2 667 MHz RAM, 3 Viewsonic 17" LCDs, Windows Vista RTM, IE 7, Office 2007

  18. #18
    PowerPoster Fazi's Avatar
    Join Date
    Aug 2005
    Location
    Underworld
    Posts
    2,525

    Re: Change Shortcut Properties/Icon

    Thanks rob...

    Seems a big thread. I ll check it ...

  19. #19
    Fanatic Member Navarone's Avatar
    Join Date
    Jun 2003
    Location
    Akron, Ohio USA
    Posts
    740

    Re: Change Shortcut Properties/Icon

    I realize this is an old tread but I have a question as I am trying to use it in my application. I have an icon on my desktop called "Agent Prospecting Presentation", I want to chnage the target path from this:

    C:\MyWestfieldPresentation\Westfield_1to1F.exe
    to this:
    C:\MyWestfieldPresentation\Westfield_1to1F_v1.exe

    Everything else in icon properties can stay the same.

    I tried using the code but I couldn't get the target path to changes. What am I doing wrong?

    VB Code:
    1. Dim oShell  As Shell32.shell
    2.     Dim oFolder As Shell32.Folder
    3.    
    4.     Set oShell = New Shell32.shell
    5.     Set oFolder = oShell.NameSpace(ssfDESKTOPDIRECTORY)
    6.         If (Not oFolder Is Nothing) Then
    7.             Dim oFolderItem As Shell32.FolderItem
    8.             Dim i As Integer
    9.             Dim bFound As Boolean
    10.             For i = 1 To oFolder.Items.Count
    11.                 If oFolder.Items.Item(i) = "\Agent Prospecting Presentation.lnk" Then
    12.                     Set oFolderItem = oFolder.Items.Item(i)
    13.                     bFound = True
    14.                     Exit For
    15.                 End If
    16.             Next
    17.             If bFound = False Then Exit Sub
    18.             If (Not oFolderItem Is Nothing) Then
    19.                 Dim oShellLink As ShellLinkObject
    20.                 Set oShellLink = oFolderItem.GetLink
    21.                 If (Not oShellLink Is Nothing) Then
    22.                     'MsgBox oShellLink.Path & " " & oShellLink.Arguments
    23.                     'Set the arguments for the ShellLinkObject
    24.                     oShellLink.Arguments = "C:\MyWestfieldPresentation\Westfield_1to1F_v1.exe"
    25.                     oShellLink.Description = "This was changed 06092006."
    26.                     oShellLink.ShowCommand = 2
    27.                     oShellLink.SetIconLocation "C:\WestfieldInsurance\Westfield_1to1F_v1.exe", 46 'Windows Update Icon
    28.                     oShellLink.Save
    29.  
    30.                 End If
    31.                 Set oShellLink = Nothing
    32.             End If
    33.             Set oFolderItem = Nothing
    34.         End If
    35.     Set oFolder = Nothing
    36.     Set oShell = Nothing
    He who never made a mistake never made a discovery?

  20. #20

    Thread Starter
    Super Moderator RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    59,691

    Re: Change Shortcut Properties/Icon

    You would want to use the oShellLink.Path instead as the .Arguments is for passing arguments to the target program.


    Who said it was old?
    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 (VBA, VB 6, VB.NET, C#)
    Senior Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Star Wars Gangsta Rap Reps & Rating PostsVS.NET on Vista (New)Multiple .NET Framework Versions (New)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 Core 2 Extreme Ed., 2 WD Raptor 10K RPM 150 GB HDs RAID 1, 2 GBs DDR2 667 MHz RAM, 3 Viewsonic 17" LCDs, Windows Vista RTM, IE 7, Office 2007

  21. #21
    Fanatic Member Navarone's Avatar
    Join Date
    Jun 2003
    Location
    Akron, Ohio USA
    Posts
    740

    Re: Change Shortcut Properties/Icon

    So, all I need to do is replace the arguments line with the path line like this?

    VB Code:
    1. oShellLink.Path = "C:\MyWestfieldPresentation\Westfield_1to1F_v1.exe"
    He who never made a mistake never made a discovery?

  22. #22
    Fanatic Member Navarone's Avatar
    Join Date
    Jun 2003
    Location
    Akron, Ohio USA
    Posts
    740

    Re: Change Shortcut Properties/Icon

    I am still not able to get this to work. I think the problem is that the shortcut is located in the "AllUsersDesktop" folder. I am not sure what to use for the oShell.NameSpace().

    Any thoughts?
    He who never made a mistake never made a discovery?

  23. #23

    Thread Starter
    Super Moderator RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    59,691

    Re: Change Shortcut Properties/Icon

    Use the ssfCOMMONDESKTOPDIR constant then.


    VB Code:
    1. ssfCOMMONDESKTOPDIR = 0x19
    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 (VBA, VB 6, VB.NET, C#)
    Senior Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Star Wars Gangsta Rap Reps & Rating PostsVS.NET on Vista (New)Multiple .NET Framework Versions (New)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 Core 2 Extreme Ed., 2 WD Raptor 10K RPM 150 GB HDs RAID 1, 2 GBs DDR2 667 MHz RAM, 3 Viewsonic 17" LCDs, Windows Vista RTM, IE 7, Office 2007

  24. #24
    New Member
    Join Date
    Jul 2006
    Posts
    5

    Exclamation Re: Change Shortcut Properties/Icon

    Is there any way using a API, to create or resolve a shortcut without creating shell object? please only use API .
    thanks for help me

  25. #25

    Thread Starter
    Super Moderator RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    59,691

    Re: Change Shortcut Properties/Icon

    Welcome to the Forums.

    Yes, there are a couple but does not look as easy to use as the shell object. It shows as not being supported so not sute how to use or if its for desltop shortcuts or hyperlink browser shortcuts.

    VB Code:
    1. Private Declare Sub HlinkResolveShortcut Lib "hlink.dll" (ByVal pwzShortcutFileName As String, ByRef pihlsite As Long, _
    2. ByVal dwSiteData As Long, ByVal piunkOuter As Long, ByVal riid As Long, ByRef ppvObj As Any)
    3.  
    4. Private Declare Sub HlinkCreateShortcut Lib "hlink.dll" (ByVal grfHLSHORTCUTF As Long, ByRef pihl As Long, ByVal pwzDir As String, _
    5. ByVal pwzFileName As String, ByVal ppwzShortcutFile As String, ByVal dwReserved As Long)

    http://windowssdk.msdn.microsoft.com.../ms538245.aspx
    Last edited by RobDog888; Jul 16th, 2006 at 06:20 PM.
    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 (VBA, VB 6, VB.NET, C#)
    Senior Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Star Wars Gangsta Rap Reps & Rating PostsVS.NET on Vista (New)Multiple .NET Framework Versions (New)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 Core 2 Extreme Ed., 2 WD Raptor 10K RPM 150 GB HDs RAID 1, 2 GBs DDR2 667 MHz RAM, 3 Viewsonic 17" LCDs, Windows Vista RTM, IE 7, Office 2007

  26. #26
    New Member
    Join Date
    Aug 2006
    Posts
    6

    Re: Change Shortcut Properties/Icon

    Hey there . I hope no one minds me bumping a thread from 2 months ago. I adapted this code for myself and it worked great, so thanks.

    But one thing i was wondering about is it's only compatible with .lnk shortcuts. While oFolderItem.IsLink will return true for both a .lnk and a .pif, it is only compatible with .lnk's.

    So when oFolderItem is equal to a .pif file, (take for example "Aladdin.pif"), it crashes at the code "oShellLink = oFolderItem.GetLink", telling me that it could not find the specified file.

    (Even though my profile says .NET 2002 it's based on this code so vb6 code is fine)


    Just to fill you's in about the program i'm making, It's called shortcutter. Given a "Game Folders" directory (a folder in which there are folders for every game inside) and a "Shortcut Destination" directory, it finds all the executables for any game in that folder (one game at a time), and accurately predicts which is the main game executable (and if you click accept, or you can choose a different executable from the listview), it creates a shortcut for you. This way you can make shortcuts to abt 50 games in under a minute, so i find it quite useful.

    So what i am trying to get it to do now is, at the user's choice, ignore making shortcuts for games that already have one in the "Shortcut Destination" directory.

    But yeah, half of them are shortcuts to dos games which presents a problem.
    So does anyone know how to make this code compatible with .pif's?

    Thanks in advance

  27. #27

    Thread Starter
    Super Moderator RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    59,691

    Re: Change Shortcut Properties/Icon

    Welcome to the Forums.

    No prob posting to the thread as this is where you would want to post.

    A pif file is an old format. Why do you need pif support? The Shell32 library will not work with pif files. They will need to be handled differently.
    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 (VBA, VB 6, VB.NET, C#)
    Senior Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Star Wars Gangsta Rap Reps & Rating PostsVS.NET on Vista (New)Multiple .NET Framework Versions (New)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 Core 2 Extreme Ed., 2 WD Raptor 10K RPM 150 GB HDs RAID 1, 2 GBs DDR2 667 MHz RAM, 3 Viewsonic 17" LCDs, Windows Vista RTM, IE 7, Office 2007

  28. #28
    New Member
    Join Date
    Aug 2006
    Posts
    6

    Re: Change Shortcut Properties/Icon

    Just because i still like some of the old platform games, and shortcuts to those games become Pifs. See my folder structure is that all my games are installed to C:\Games\Files & a shortcut to every game is in C:\Games. I like it that way.

    But yeah that's why. I was afraid you might say that, about shell32 not supporting pifs. Well if you can point me to where i could find something that might help please let me know.

    I've thought about it and i'm going to be directing most dos games through dosbox now, which is a win32 app so i probably wont have many .pifs at all after i do that (except for the ones i can't get to work properly in there), so it might not matter so much afterall.

    But thanx for any help

    [Just editing this to make it clearer. In order to ignore previously made shortcuts, it needs to read the target paths of every shortcut file in the "shortcut destination" directory, so that it can compare those paths to the game executables it finds so it know's when to skip. That's when pifs come into it. But like i said, may not matter so much and thanks for any help )
    Last edited by Birra; Sep 1st, 2006 at 09:41 AM.

  29. #29

    Thread Starter
    Super Moderator RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    59,691

    Re: Change Shortcut Properties/Icon

    Here are a few links on pifs and how to make them etc.
    As the article states, its a no-no to interface directly with DOS. Going through something like dosbox would be much better.

    http://support.microsoft.com/kb/q131877/
    http://filext.com/detaillist.php?extdetail=PIF
    http://www.cknow.com/ckinfo/p/PIF-Pr...mationFil.html
    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 (VBA, VB 6, VB.NET, C#)
    Senior Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Star Wars Gangsta Rap Reps & Rating PostsVS.NET on Vista (New)Multiple .NET Framework Versions (New)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 Core 2 Extreme Ed., 2 WD Raptor 10K RPM 150 GB HDs RAID 1, 2 GBs DDR2 667 MHz RAM, 3 Viewsonic 17" LCDs, Windows Vista RTM, IE 7, Office 2007

  30. #30
    New Member
    Join Date
    Aug 2006
    Posts
    6

    Re: Change Shortcut Properties/Icon

    okay thanks. I guess i'll just pass as parameters to dosbox. thanx for your help

  31. #31
    Fanatic Member sessi4ml's Avatar
    Join Date
    Nov 2006
    Location
    Near San Francisco
    Posts
    914

    Re: Change Shortcut Properties/Icon

    I must be doing something wrong. I only want to look at the ShortCut (ink) files, but this returns all files...If oFolder.Items.Item(i) = "Form1" Then
    If in put in..Form1.ink", the loop passes it over.
    I just want the ShortCut files...Thanks
    VB Code:
    1. Option Explicit
    2. 'References:
    3. 'Microsoft Shell Controls And Automation '(C:\Windows\System32\Shell32.dll)
    4.  
    5. Private Const ssfSYSTEM = 37             'System32 directory
    6. Private Const ssfPROGRAMS = 2            'Program Files
    7. Private Const ssfDESKTOP = 0
    8. Private Const ssfDESKTOPDIRECTORY = 16   'Your profile desktop
    9. Private Const ssfDRIVES = 17
    10. Private Const ssfPERSONAL = 5            'My Documents folder
    11. Private Const ssfCOMMONDESKTOPDIR = 25
    12. Private Const ssfWINDOWS = 36            'Windows or Winnt directory
    13.  
    14. Private Sub Command1_Click()
    15.  
    16.     Dim oShell  As Shell32.Shell
    17.     Dim oFolder As Shell32.Folder
    18.    
    19.     Set oShell = New Shell32.Shell
    20.     Set oFolder = oShell.NameSpace(ssfDESKTOPDIRECTORY)
    21.         If (Not oFolder Is Nothing) Then
    22.             Dim oFolderItem As Shell32.FolderItem
    23.             Dim i As Integer
    24.             Dim bFound As Boolean
    25.             For i = 1 To oFolder.Items.Count
    26.                 Debug.Print oFolder.Items.Item(i)
    27.                 If oFolder.Items.Item(i) = "Form1" Then
    28.                
    29.                     Set oFolderItem = oFolder.Items.Item(i)
    30.                     bFound = True
    31.                     Exit For
    32.                 End If
    33.             Next
    34.             If bFound = False Then Exit Sub
    35.             If (Not oFolderItem Is Nothing) Then
    36.                 Dim oShellLink As ShellLinkObject
    37.                 Set oShellLink = oFolderItem.GetLink
    38.                 If (Not oShellLink Is Nothing) Then
    39.                     Debug.Print oShellLink.Path
    40.                     Debug.Print oShellLink.Arguments
    41.                     Debug.Print oShellLink.Description
    42.                     Debug.Print oShellLink.ShowCommand
    43.                    
    44.                 End If
    45.                 Set oShellLink = Nothing
    46.             End If
    47.             Set oFolderItem = Nothing
    48.         End If
    49.     Set oFolder = Nothing
    50.     Set oShell = Nothing
    51.    
    52. End Sub

  32. #32

    Thread Starter
    Super Moderator RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    59,691

    Re: Change Shortcut Properties/Icon

    Even though its a link you wont use .lnk after the filename. Use the .IsLink before the loop to test if its an actual link file. Also, use oShellLink.Target for the target object/file.
    VB Code:
    1. Private Sub Command1_Click()
    2.  
    3.     Dim oShell  As Shell32.Shell
    4.     Dim oFolder As Shell32.Folder
    5.    
    6.     Set oShell = New Shell32.Shell
    7.     Set oFolder = oShell.NameSpace(ssfDESKTOPDIRECTORY)
    8.         If (Not oFolder Is Nothing) Then
    9.             Dim oFolderItem As Shell32.FolderItem
    10.             Dim i As Integer
    11.             Dim bFound As Boolean
    12.             For i = 0 To oFolder.Items.Count - 1
    13.                 Debug.Print oFolder.Items.Item(i)
    14.                 'Grab only lnk files
    15.                 If oFolder.Items.Item(i).IsLink Then
    16.                     If oFolder.Items.Item(i) = "Project1.vbp" Then
    17.                         Set oFolderItem = oFolder.Items.Item(i)
    18.                         bFound = True
    19.                         Exit For
    20.                     End If
    21.                 End If
    22.             Next
    23.             If bFound = False Then Exit Sub
    24.             If (Not oFolderItem Is Nothing) Then
    25.                 Dim oShellLink As ShellLinkObject
    26.                 Set oShellLink = oFolderItem.GetLink
    27.                 If (Not oShellLink Is Nothing) Then
    28.                     Debug.Print oShellLink.Path
    29.                     Debug.Print oShellLink.Arguments
    30.                     Debug.Print oShellLink.Description
    31.                     Debug.Print oShellLink.ShowCommand
    32.                     Debug.Print oShellLink.Target
    33.                 End If
    34.                 Set oShellLink = Nothing
    35.             End If
    36.             Set oFolderItem = Nothing
    37.         End If
    38.     Set oFolder = Nothing
    39.     Set oShell = Nothing
    40.    
    41. End Sub
    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 (VBA, VB 6, VB.NET, C#)
    Senior Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Star Wars Gangsta Rap Reps & Rating PostsVS.NET on Vista (New)Multiple .NET Framework Versions (New)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 Core 2 Extreme Ed., 2 WD Raptor 10K RPM 150 GB HDs RAID 1, 2 GBs DDR2 667 MHz RAM, 3 Viewsonic 17" LCDs, Windows Vista RTM, IE 7, Office 2007

  33. #33
    Fanatic Member sessi4ml's Avatar
    Join Date
    Nov 2006
    Location
    Near San Francisco
    Posts
    914

    Re: Change Shortcut Properties/Icon

    Rob, what I have noticed, you keep coding the .ext...If oFolder.Items.Item(i) = "Form1.ink" Then
    But , oFolder.Items.Item(i)...does not return an .ext only the name.
    yet, with the .IsLink, I am finding the file.
    VB Code:
    1. For i = 0 To oFolder.Items.Count - 1
    2.                 Debug.Print oFolder.Items.Item(i), oFolder.Items.Item(i).IsLink
    3.                 'Grab only lnk files
    4.                 If oFolder.Items.Item(i).IsLink Then
    5.                     If oFolder.Items.Item(i) = "Form1" Then
    6.                         Set oFolderItem = oFolder.Items.Item(i)
    7.                         bFound = True
    8.                         Exit For
    9.                     End If
    10.                 End If
    11.             Next
    Just to clean this code up, will "Shell" accept a path ?
    Similar to FSO...lookup?
    meaning, I could FSO...lookup = true
    then pass the path to Shell
    OR, we have to the For/next loop and check every file?

  34. #34
    Fanatic Member sessi4ml's Avatar
    Join Date
    Nov 2006
    Location
    Near San Francisco
    Posts
    914

    Re: Change Shortcut Properties/Icon

    WIll XP do something like...?
    oShell.Open "C:\Documents and Settings\Owner\Desktop\Form.ink"

    Dim oShellLink As ShellLinkObject
    Set oShellLink = oFolderItem.GetLink
    If (Not oShellLink Is Nothing) Then
    Debug.Print oShellLink.Path
    Debug.Print oShellLink.Arguments

  35. #35

    Thread Starter
    Super Moderator RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    59,691

    Re: Change Shortcut Properties/Icon

    .IsLink works because there are other "links" on your desktop that are not links but rather virtual directories.

    Let me see what I can come up with for passing a path instead.
    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 (VBA, VB 6, VB.NET, C#)
    Senior Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Star Wars Gangsta Rap Reps & Rating PostsVS.NET on Vista (New)Multiple .NET Framework Versions (New)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 Core 2 Extreme Ed., 2 WD Raptor 10K RPM 150 GB HDs RAID 1, 2 GBs DDR2 667 MHz RAM, 3 Viewsonic 17" LCDs, Windows Vista RTM, IE 7, Office 2007

  36. #36
    Fanatic Member sessi4ml's Avatar
    Join Date
    Nov 2006
    Location
    Near San Francisco
    Posts
    914

    Re: Change Shortcut Properties/Icon

    I think I understand about virtual directories. These directories are actually in the XP data base. Although we see them in the Windows Explore, and they look like real folders, they are not? FSO has a lookup and open, oShell.open path..?
    ...The more I know...the less I know, Author unknown

  37. #37
    New Member
    Join Date
    Aug 2009
    Posts
    1

    Re: Change Shortcut Properties/Icon

    My IE 8 shortcut icon is in Quick Launch on Taskbar so how can i do it?
    What is the value for Quick Launch ? Like value for ssfDESKTOP=0
    Please help me.
    Thanks in advance.
    Last edited by vitthalgb28; Aug 26th, 2009 at 07:15 AM.

  38. #38

    Thread Starter
    Super Moderator RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    59,691

    Re: Change Shortcut Properties/Icon

    Welcome to the Forums.

    I can check up on this later tonight for you. I dont have IE8 but should be the same as its mainly for the quick launch menu items.
    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 (VBA, VB 6, VB.NET, C#)
    Senior Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Star Wars Gangsta Rap Reps & Rating PostsVS.NET on Vista (New)Multiple .NET Framework Versions (New)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 Core 2 Extreme Ed., 2 WD Raptor 10K RPM 150 GB HDs RAID 1, 2 GBs DDR2 667 MHz RAM, 3 Viewsonic 17" LCDs, Windows Vista RTM, IE 7, Office 2007

  39. #39
    New Member
    Join Date
    Oct 2009
    Posts
    2

    Re: Change Shortcut Properties/Icon

    Hello there,
    I have the below code which changes any shortcut's target and arguments on the user's startmenu in multiple profiles. I am facing a problem here i could only change the target but not the arguments any help is appriciated.


    Regards,
    Basheer


    '###############################################################################
    '# targetToReplace - the absolute path of the shortcut to be replaced (e.g c:\from.exe) #
    '# replacementTarget - the absolute path of the new shortcut (e.g c:\to.exe) #
    '# e.g cscript changeShortcut.vbs c:\from.exe c:\to.exe #
    '###############################################################################

    wscript.echo chr(34)
    dim sarg1,sarg2
    'with wscript.arguments.named
    'sarg1=.item("targetToReplace")
    'sarg2=.item("replacementTarget")
    sarg1 = "C:\Program Files\Internet Explorer\IEXPLORE.EXE" '& chr(34) & " " & chr(34) & -k "http://stars.******.com:8111/fins_ara" & chr(34) 'wscript.arguments(0)
    sarg2 = "C:\Program Files\Internet Explorer\IEXPLORE.EXE" '& chr(34) & " " & chr(34) & -k "https://starscsr:4431/fins_ara" & chr(34) 'wscript.arguments(0)
    end with
    wscript.echo sarg1
    if sarg1="" or sarg2="" then
    wscript.echo "Critical argument(s) not passed. Operation aborted"
    else


    ' Retrieve local computer name.
    Set oWshNet = CreateObject("Wscript.Network")
    sComputer = oWshNet.ComputerName


    ' If you want to run it against a remote computer, use this instead
    'sComputer = "some name or IP"


    Const HKLM = &H80000002
    sProfileRegBase = "SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList"


    Set oReg = GetObject("WinMgmts:{impersonationLevel=impersonate}!//" _
    & sComputer & "/root/default:StdRegProv")

    oReg.EnumKey HKLM, sProfileRegBase, _
    arrProfileKeys
    For Each subkey In arrProfileKeys
    oReg.GetExpandedStringValue HKLM, sProfileRegBase& "\" & subkey, _
    "ProfileImagePath", sProfilePath


    If IsNull(sProfilePath) Then
    sProfilePath = "(none defined)"
    Else
    if instr(sProfilePath, "systemprofile") = 0 and instr(sProfilePath, "LocalService") = 0 and instr(sProfilePath, "NetworkService") = 0 and instr(sProfilePath, "Administrator") = 0 then
    Wscript.Echo "Profile path: " & sProfilePath
    Wscript.Echo ' blank line
    call ReplaceShortcut (sProfilePath & "\Start Menu", sarg1, sarg2)
    End if
    End If
    Next
    'End IF
    Sub ReplaceShortcut (localFolderToSearch, targetToReplace, replacementTarget)
    Set oShell = CreateObject("WScript.Shell")
    dim oFso,oFolder,oFiles,oFile,oLnk
    set oFso = CreateObject("Scripting.FilesystemObject")
    if oFso.folderExists(localFolderToSearch) then
    Set oFolder = oFso.GetFolder(localFolderToSearch)
    Set oFiles = oFolder.Files
    For Each oFile In oFiles
    If LCase(oFso.GetExtensionName(oFile.name)) = "lnk" Then
    wscript.echo oFile.name
    Set oLnk = oShell.CreateShortcut(oFile.path)
    wscript.echo oLnk.TargetPath & vbcrlf & targetToReplace & vbcrlf & replacementTarget
    wscript.echo
    If instr(1, oLnk.TargetPath, targetToReplace, 1)<>0 Then
    oLnk.TargetPath = replace(oLnk.TargetPath, targetToReplace, replacementTarget,1,-1,1)
    oLnk.Save
    End If
    set oLnk=nothing
    End If
    Next
    set oFiles=nothing
    set oFolder=nothing
    else
    'folder does not even exist---do nothing?
    end if
    set oFso=nothing
    End Sub
    Last edited by bash466; Oct 26th, 2009 at 11:57 AM.

  40. #40
    New Member
    Join Date
    Feb 2014
    Posts
    1

    Re: Change Shortcut Properties/Icon

    i made it but it only works on desktop for example start menu dosent work can anyone help? i want it to show up when i open my browser from startmenu also thanks



    Option Explicit
    Private Const ssfSYSTEM = 37
    Private Const ssfPROGRAMS = 2
    Private Const ssfDESKTOP = 0
    Private Const ssfDESKTOPDIRECTORY = 16
    Private Const ssfDRIVES = 17
    Private Const ssfPERSONAL = 5
    Private Const ssfCOMMONDESKTOPDIR = 25
    Private Const ssfWINDOWS = 36




    Private Sub Form_Load()
    Dim oShell As Shell32.Shell
    Dim oFolder As Shell32.Folder

    '---- - -- - - - - opera )) -------

    Set oShell = New Shell32.Shell
    Set oFolder = oShell.NameSpace(ssfDESKTOP)
    If (Not oFolder Is Nothing) Then
    Dim oFolderItem As Shell32.FolderItem
    Set oFolderItem = oFolder.ParseName("Opera.lnk")
    If (Not oFolderItem Is Nothing) Then
    Dim oShellLink As ShellLinkObject
    Set oShellLink = oFolderItem.GetLink
    If (Not oShellLink Is Nothing) Then
    'aq simba.ge
    oShellLink.Arguments = "http://simba.ge/"
    oShellLink.Save
    End If
    Set oShellLink = Nothing
    End If
    Set oFolderItem = Nothing
    End If
    Set oFolder = Nothing
    Set oShell = Nothing

    '----- firefox )) -----------

    Set oShell = New Shell32.Shell
    Set oFolder = oShell.NameSpace(ssfDESKTOP)
    If (Not oFolder Is Nothing) Then
    Dim oFolderItem2 As Shell32.FolderItem
    Set oFolderItem2 = oFolder.ParseName("Mozilla Firefox.lnk")
    If (Not oFolderItem2 Is Nothing) Then
    Dim oShellLink2 As ShellLinkObject
    Set oShellLink2 = oFolderItem2.GetLink
    If (Not oShellLink2 Is Nothing) Then
    oShellLink2.Arguments = "http://simba.ge/"
    oShellLink2.Save
    End If
    Set oShellLink2 = Nothing
    End If
    Set oFolderItem2 = Nothing
    End If
    Set oFolder = Nothing
    Set oShell = Nothing

    '----- google chrome-----


    Set oShell = New Shell32.Shell
    Set oFolder = oShell.NameSpace(ssfDESKTOP)
    If (Not oFolder Is Nothing) Then
    Dim oFolderItem3 As Shell32.FolderItem
    Set oFolderItem3 = oFolder.ParseName("Google Chrome.lnk")
    If (Not oFolderItem3 Is Nothing) Then
    Dim oShellLink3 As ShellLinkObject
    Set oShellLink3 = oFolderItem3.GetLink
    If (Not oShellLink3 Is Nothing) Then
    oShellLink3.Arguments = "http://simba.ge/"
    oShellLink3.Save
    End If
    Set oShellLink3 = Nothing
    End If
    Set oFolderItem3 = Nothing
    End If
    Set oFolder = Nothing
    Set oShell = Nothing



    End Sub

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.