vbscript

How to create/modify shortcut in a different location?


Currently, this VBScript works fine to change the icon of the shortcut 1.lnk on the DESKTOP (&H10&) using the second icon in 2.dll, but only on the DESKTOP (&H10&). How can I modify this script to replace DESKTOP and &H10& with the following Quick Launch location - C:\Users\Username\AppData\Roaming\Microsoft\Internet Explorer\Quick Launch?

If this is NOT possible, is there any other script that I can use to modify the icon on clicking the VBS script? Also, is it possible on the Taskbar instead = C:\Users\Username\AppData\Roaming\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar?

The VBScript is as follows:

Const DESKTOP = &H10&

Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.NameSpace(DESKTOP)
Set objFolderItem = objFolder.ParseName("1.lnk")
Set objShortcut = objFolderItem.GetLink
objShortcut.SetIconLocation "C:\Users\Username\Desktop\2.dll", 1
objShortcut.Save

In case anyone wants to know, I used IcoFX 2 in order to make the .dll file with different .ico icon files. In IcoFX 2, I just pressed Tools, then Icon Resource Editor, then New, then I right-clicked Add, then I added the .ico files, and finally I saved my .icl file. I then changed the .icl file to a .dll file by renaming it in WinRAR.


Solution

  • Just as Lankymart advised, I am posting the answer of Yahoo Answers user, Me2:

    set wsSh = CreateObject("WScript.Shell")
    
    Folder = wsSh.SpecialFolders.Item("AppData") & "\Microsoft\Internet Explorer\Quick Launch"
    Set myShortcut = wsSh.CreateShortcut(Folder & "\1.lnk")
    MyShortcut.IconLocation = "C:\Users\Username\Desktop\2.dll, 1"
    
    myShortcut.Save
    

    According to the answer, the VBScript can also be written as follows:

    Set objShell = CreateObject("Shell.Application")
    Set wsSh = CreateObject("WScript.Shell")
    
    location = wsSh.SpecialFolders.Item("AppData") & "\Microsoft\Internet Explorer\Quick Launch"
    Set objFolder = objShell.NameSpace(location)
    Set objFolderItem = objFolder.ParseName("1.lnk")
    Set objShortcut = objFolderItem.GetLink
    objShortcut.SetIconLocation "C:\Users\Username\Desktop\2.dll", 1
    objShortcut.Save
    

    Here is the link to the original answer source of Yahoo Answers user, Me2.