How to set Windows Shortcut icon to relative path?

Abstract: Resolve broken shortcut icons after moving directories by using VBScript or PowerShell to set dynamic relative icon paths.

Created: 2026-10-21 by
You cannot set a Windows shortcut icon to a relative path directly through the graphical user interface. The standard "Change Icon" dialog requires an absolute file path, meaning it expects a fixed location like C:\Program Files\App\icon.ico. If you move the shortcut or the target application to a different drive or folder, the icon will break because the hardcoded path no longer exists. To achieve a dynamic, relative icon that moves with your application, you must use a small script or a specialized tool that resolves the path at runtime. This limitation exists because the .lnk file format stores the icon index and the absolute path to the DLL or EXE containing the resource. It does not support variables or relative references like .\icons\app.ico. Consequently, users who organize their software in portable folders often face this issue when they want a clean desktop without broken icons after moving directories.

Why Standard Methods Fail

When you right-click a shortcut and select Properties, then click Change Icon..., Windows opens a file browser. This browser forces you to navigate to a specific location on your disk. Once you select an icon, Windows writes the full absolute path into the shortcut's metadata. For example, if you select an icon from D:\Apps\MyApp\icon.ico, the shortcut remembers that exact string. If you later move D:\Apps\MyApp to E:\PortableApps\MyApp, the shortcut still looks for D:\Apps\MyApp\icon.ico. Since that path is now invalid, Windows displays a generic question mark or blank square instead of your custom icon. This behavior is consistent across all versions of Windows, including Windows 10 and Windows 11. There is no built-in checkbox or setting to enable relative paths for shortcut icons.

Solution 1: Using a VBScript to Set Relative Icons

The most reliable method to assign a relative icon is to use a VBScript that calculates the current directory of the shortcut itself and updates the icon path dynamically. This approach ensures that as long as the icon file stays in the same folder as the shortcut (or a subfolder), it will always find the correct resource. Create a new text file and name it SetRelativeIcon.vbs. Paste the following code into it:
Set WshShell = CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")

' Path to the shortcut
strShortcutPath = "C:\Users\YourName\Desktop\MyApp.lnk"

' Get the directory of the shortcut
strDir = objFSO.GetParentFolderName(strShortcutPath)

' Define the relative icon path (e.g., in an 'icons' subfolder)
strIconPath = strDir & "\icons\myapp.ico"

' Apply the icon
Set oShellLink = WshShell.CreateShortcut(strShortcutPath)
oShellLink.IconLocation = strIconPath
oShellLink.Save

MsgBox "Icon updated to relative path: " & strIconPath
Replace C:\Users\YourName\Desktop\MyApp.lnk with the actual path to your shortcut. Replace \icons\myapp.ico with the relative location of your icon file. Run this script once. If you move the shortcut, you may need to re-run the script or modify it to accept command-line arguments for flexibility.

Solution 2: Using PowerShell for Modern Systems

For those who prefer PowerShell, you can achieve similar results using COM objects. This method is useful if you are managing multiple shortcuts or need to integrate the icon change into a larger deployment script. Open PowerShell and run the following command, adjusting the paths as needed:
$shell = New-Object -ComObject WScript.Shell
$shortcut = $shell.CreateShortcut("$env:USERPROFILE\Desktop\MyApp.lnk")
$iconPath = Join-Path (Split-Path $shortcut.FullName) "icons\myapp.ico"
$shortcut.IconLocation = $iconPath
$shortcut.Save()
This script retrieves the parent folder of the shortcut automatically and appends the relative icon path. It is cleaner than the VBScript approach for modern Windows environments and allows for easier integration with other automation tasks. Note that you must have execution permissions to run scripts in your PowerShell environment.

Maintaining Portable Applications

When working with portable applications, keeping icons synchronized with the application structure is crucial. If you distribute a portable app, users expect the icon to work immediately upon extraction. Using a relative path strategy ensures that the visual identity remains intact regardless of where the user places the folder. Consider organizing your portable app structure like this:
  • MyApp.exe
  • data\config.ini
  • icons\app.ico
  • MyApp.lnk (created by the script above)
By placing the icon in a dedicated icons folder and using a script to resolve the path relative to the shortcut's location, you create a robust system that survives directory moves. This is particularly important for users who store their software on external drives or cloud-synced folders like OneDrive. See Resolving Windows 11 Shortcut Error: Creating a Shortcut from OneDrive to Another Folder for more context on handling networked or synced paths.

Alternative Tools and Considerations

While scripting provides control, some users prefer third-party utilities. Tools like Shortcut Maker or Launchy sometimes offer advanced icon management features. However, most standard shortcut managers still rely on absolute paths due to the underlying limitations of the Windows Shell. Always verify that any third-party tool you use is from a trusted source to avoid malware. Another consideration is the performance impact. Scripts that run frequently to update icons can slow down system startup if not optimized. The methods described above are designed to be executed manually or during setup, not continuously. This keeps your system responsive while ensuring your shortcuts look professional. For related issues with virtual desktops and window switching, check out Windows Shortcut/Utility to switch between application windows in different virtual desktops. Understanding how shortcuts interact with the shell can help you manage complex multi-monitor setups more effectively.

Frequently Asked Questions

Can I edit the .lnk file directly to add a relative path?

No, you cannot simply edit the binary content of a .lnk file with a text editor. The file format is structured and contains absolute paths encoded in a specific way. Modifying it manually will likely corrupt the shortcut, causing it to fail entirely.

Will this method work on Windows 11?

Yes, the VBScript and PowerShell methods work identically on Windows 11. The underlying Shell API used to create and modify shortcuts has remained stable across recent Windows versions, ensuring compatibility.

What happens if I delete the icon file after setting the relative path?

If the icon file is deleted, the shortcut will revert to displaying a generic icon or a broken image placeholder. The relative path reference remains in the shortcut, but since the target resource is missing, Windows cannot render the custom graphic.

Is there a limit to how deep the relative path can go?

There is no strict depth limit imposed by Windows, but very long relative paths can sometimes cause issues with certain applications or shell extensions. Keeping your icon files close to the shortcut, such as in the same folder or one subdirectory deep, is best practice.

How do I update the icon if I change its filename?

You must re-run the script or update the path in the shortcut properties manually. The script does not automatically track filename changes; it only resolves the path based on the current directory structure at the time of execution.

Latest News

How to Display Output of xterm Command in Terminal Screen using Cron

Resolve the inability to display xterm output in a terminal screen from cron by redirecting logs or using wall instead of insecure X11 workarounds.

Read More
Expose Local Server on VPS Preserving Real Client IPs (OS Level)

Resolve VPS logging showing only gateway IPs by configuring reverse proxies to forward real client addresses via X-Forwarded-For headers.

Read More
How to Clear Recent Files History in Linux without Deleting Actual Files?

Clear recent files history in Linux by deleting ~/.local/share/recently-used.xbel without removing the actual files.

Read More
Best HDD Copy Strategy: Manually Syncing and Rewriting Scratch

Resolve data drift between two 4TB hard drives by using rsync with the --delete flag to manually sync and rewrite scratch data for an exact mirror.

Read More
Understanding Bash Prompt Abbreviations: An Overview

Resolve repetitive typing errors by creating and persisting Bash aliases in the .bashrc file for improved command-line efficiency.

Read More
Free Tools and Methods to Log Real-Time Performance Details in Task Manager

Log real-time CPU and memory metrics to CSV files using Windows Performance Monitor Data Collector Sets to troubleshoot system slowness.

Read More
Contact Qatar Airways Customer Service: Phone Number, Help Center, and More

Resolve urgent Qatar Airways reservation issues like flight changes and baggage claims using the US phone number +1801-855-5905 or online self-service tools.

Read More
Windows 11: Alt Codes Displaying Wrong Characters - Solutions

Resolve Windows 11 Alt codes showing wrong characters by verifying the US keyboard layout and enabling Num Lock.

Read More
Run Programs with Elevated Privileges: A Comprehensive Guide

Eliminates the need to type sudo for frequent administrative tasks by configuring .bashrc aliases or functions.

Read More
Dynamically Changing Dates in Excel Formulas Using Cells

Eliminate manual date updates in Excel by using cell references to create dynamic formulas that automatically adjust calculations when input dates change.

Read More
Granting Edit Access to a Specific Excel Sheet in an Office 365 User Email ID-Based Login

Excel Online lacks native sheet-level permissions, so users must split workbooks or use worksheet protection to isolate edit access for specific tabs.

Read More
Creating Network Load on Local Wi-Fi from One PC

Generate sustained Wi-Fi bandwidth load from a single PC using a VM SFTP server to test router stability and throughput.

Read More
Changing the Default Editor for Batch Files in Windows 11's File Explorer

Resolve the issue of batch files opening in Notepad by changing the default editor to a preferred application like VS Code.

Read More
Gain WiFi Connection Minutes Before Losing it by Changing MAC Address

Bypass MAC address filtering to restore WiFi connectivity temporarily when a device is blocked by network administrators.

Read More
Photos Folders Turned Black: Troubleshooting Picture Applications on Windows

Resolve black screens in Windows Photos by resetting the app, updating graphics drivers, and repairing system files.

Read More
Troubleshooting High CPU Temperature Values: A Step-by-Step Guide

Resolve high CPU temperatures and thermal throttling by monitoring with Speedfan, cleaning dust from cooling components, and replacing degraded thermal paste.

Read More
Make cURL establish TLS connection with CA unknown

Resolve cURL TLS connection failures with unknown or self-signed certificates by using the --insecure flag to bypass CA validation.

Read More
Troubleshooting Incorrect Network Metrics Values in Grafana, Prometheus, InfluxDB, and Telegraf

Fix incorrect network metrics in Grafana, Prometheus, InfluxDB, and Telegraf by verifying interface selection, resolving unit mismatches, and handling counter resets.

Read More
Start Another Terminal Window (cmd.exe) Windows Repair/Troubleshoot

Provides step-by-step instructions to access the Windows Command Prompt via bootable media for advanced system repair and troubleshooting.

Read More
Thinkpad P1 Gen 6: Sudden Thunderbolt 3 Dock USB-C Charging Stopped Working

Resolve sudden Thunderbolt 3 dock USB-C charging and internet failure on ThinkPad P1 Gen 6 by updating firmware, resetting the dock, and adjusting power settings.

Read More
ASUS Windows 11 Laptop: Internet Connection Issue with Hotspot

Resolve ASUS Windows 11 laptop spinning wheel issue when connecting to mobile hotspot by resetting network stack, disabling IPv6, and adjusting power settings.

Read More
Developing iOS Project with Firebase: Logging in and Sending Push Notifications

Integrates Firebase to enable secure user authentication and push notifications in iOS applications.

Read More
Troubleshooting Bash Script with Suspected Issues of Spaces, Dashes, Filenames and Quoting

Resolve Bash script failures caused by word splitting, globbing, and special characters in filenames by applying proper quoting techniques.

Read More
Populating OneDrive Folder for Local Backup without Affecting Remote Files

Prevent OneDrive from deleting remote files during Windows reinstallation by unlinking the account or using symbolic links to isolate local data.

Read More
Force First Frame as Keyframe Without Re-encoding: A Quick Solution

Resolve inaccurate seeking and playback glitches by re-encoding video to ensure the first frame is a valid keyframe.

Read More
Find Information in Database Using WSL (Ubuntu) on Windows-10

Resolve database connection issues from WSL Ubuntu on Windows 10 by configuring client tools and network access to query remote or local servers.

Read More
Configuring a New Router with Different Networks: One Family, One Guest

Resolve IP conflicts and isolate guest traffic by configuring a second router with a distinct subnet via its WAN port.

Read More
Quickly Open Multiple Stock Websites with a Single Command

Solve the problem of manually opening multiple stock research websites by creating a single command to launch them simultaneously on Windows, macOS, or Linux.

Read More
Improved Adobe Acrobat Search Experience: Access Advanced Search with Ease

Access advanced search filters like case sensitivity and regex in Adobe Acrobat by clicking More Options in the Find bar.

Read More
Port Forwarding VM via OpenVPN: A Comprehensive Guide

Configure OpenVPN server and iptables to forward specific ports from VPN clients to a virtual machine's internal IP address.

Read More
Understanding Partitions in the 1980s: A Look Back at MS-DOS and Master Boot Record

Explains how the Master Boot Record and partition table enabled MS-DOS to manage multiple disk volumes on a single physical drive.

Read More
Windows 10 Enterprise: Keyboard Not Detected in Managed Organization with Admin Privileges

Resolve Windows 10 Enterprise keyboard detection failures caused by Group Policy restrictions, driver corruption, or USB enumeration errors.

Read More
Can't Find x86_64 Versions of Applications on MacOS arm64 (M1)

Resolve missing x86_64 app issues on M1 Macs by installing Rosetta 2 and reinstalling apps as universal binaries.

Read More
How to Hide Installation Source for an Android App

Manage Android app installation source visibility by using USB transfers or file managers to reduce browser traces and isolate data via work profiles.

Read More
Connecting Momentus 4200.2 ST9808210A Hard Drive via USB Cable

Resolve inability to access Seagate Momentus 4200.2 ST9808210A hard drive by connecting it via USB using a compatible SATA-to-USB adapter and configuring the disk in Windows.

Read More