Best way to add- change the current icon a custom icon for a shortcut


  1. Posts : 232
    Win 10 Ver 1903
       #1

    Best way to add- change the current icon a custom icon for a shortcut


    After trying several different variations found posted on the web and not getting what i needed, I hope someone here might know the solution.

    I am working with a long script that in its final steps creates a shortcut to a website which works as needed but the same script (which offers an option to add a custom icon) will no longer do so. The shortcut icon is either a blank white square or at best a "globe". It creates a perfect working Url link to a website while many of the methods I found for creating a URL in a command script failed to work. While this is very simple in GUI, this is the end step of a long process that needs to work as written.

    I can use vbs but would prefer not to use PS if possible. This command is extremely old and may have issues with current Windows 10 x64 . It once worked properly but will no longer add the custom icon.

    Any method I could use to add the icon to the created link would be great as long as I can add it in the final step of the process which creates the link.

    Windows 10 x64 Latest Updates
      My Computer


  2. Posts : 582
    Windows 10 Home
       #2

    If the shortcut being created is an Internet shortcut(.URL), these are text files with a ".URL" extension, easily created by vbscript or even batch files. The displayed icon is specified by an "IconFile" line.

    Code:
    [InternetShortcut] 
    URL=https://www.google.com/?complete=0
    IconIndex=0
    HotKey=0 
    IconFile=C:\Program Files (x86)\Internet Explorer\ieinstal.exe
    If the IconFile has multiple icons, use the "IconIndex" line to specify the icon by its number.

    Ben
    Last edited by Ben Myers; 09 Mar 2020 at 21:02.
      My Computer


  3. Posts : 16,926
    Windows 10 Home x64 Version 22H2 Build 19045.4170
       #3

    How are you creating the link & where are you getting the icon from?

    If you post the relevant script / portion of the script then people can advise you. Without posting your script then you might as well be asking us how long your piece of string is.

    Denis
      My Computer


  4. Posts : 232
    Win 10 Ver 1903
    Thread Starter
       #4

    I hate to say but most methods in batch failed for one reason or another this is the final step in a long script. I wish I could find the right way to create it with a one line script using xxmklink
    My first tries with mklink worked but no icon. My second tries with xxmklink also worked but also added no icon even though xxmklink specifies the proper way to add one in a single line.
    see below
    xxmklink spath opath [ arg [ wdir [ desc [ mode [ icon[:n] ]]]]] [switches...]
    where spath path of the shortcut (.lnk added as needed) opath path of the object represented by the shortcut arg argument string (use quotes with space, see below) wdir path of the working directory (for "Start in") desc description string (shown in Shortcut's Properties) mode display mode (1:Normal [default], 3:Maximized, 7:Minimized) icon[:n] icon file [with optional icon index value n]

    Using mkshortcut which is part of cygutils (which i have installed ) I run into the same issues with adding the the icon

    Using below is mkshortcut /target<path> /shortcut <path> but on mkshortcut I also get a windows error from Wshell.
    mkshortcut.vbs is :
    set WshShell = WScript.CreateObject("WScript.Shell" )set oShellLink = WshShell.CreateShortcut(Wscript.Arguments.Named("shortcut") & ".lnk")oShellLink.TargetPath = Wscript.Arguments.Named("target")oShellLink.WindowStyle = 1oShellLink.Save

    The shortcut work even with the filetype as .lnk and I can change that to .url as well and add the default browser icon such as Chrome. But this takes exiting the script with an incorrect URL that has to be fixed.

    I am considering just adding the necessary text to the .rtf file that the script builds to document other items. It would be clickable from that document if properly written. Having the actual URL icon would also be nice if i can get it to work though. AND If it does, it needs to use the custom favicon for the URL.
    Last edited by questorfla; 10 Mar 2020 at 11:57. Reason: Spelling other
      My Computer


  5. Posts : 16,926
    Windows 10 Home x64 Version 22H2 Build 19045.4170
       #5

    1 About getting copies of the icons for web shortcuts
    Open the .url or .website file in Notepad by opening Notepad then dropping the file into its window
    The icon source is shown
    go to that webpath, right-click on the icon shown, save picture as
    [and this will allow it to be saved as an ICO file]

    2 Generally
    I know nothing about the xxmklink tool you are using. If you decide to split the shortcut creation away from that tool and use a separate tool for the job then you are correct in thinking that this can be done in VBS & in PowerShell. It can also be done in VBA. A batch file can also be used but its role would merely be to act as an intermediary for the necessary actions being run by VBS/PS.
    How to create a desktop shortcut with the Windows Script Host - MSSupport - this is the MS Help page for what you seem to be doing with the vbs you posted
    VBScript – Create a shortcut with parameters – Weird n Wonderful IT
    Create Shortcuts .lnk or .url Files With PowerShell - PowerShell Blogger

    3 Your current icon problem is the subject of this discussion and a suggested syntax correction is made at the end
    Creating shortcut using xxmklink

    Denis
    Last edited by Try3; 10 Mar 2020 at 13:51.
      My Computer


 

  Related Discussions
Our Sites
Site Links
About Us
Windows 10 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 10" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd
All times are GMT -5. The time now is 21:08.
Find Us




Windows 10 Forums