I've been using the utility Relative to create my relative shortcuts a bit faster since I know it. The problem is my drive is plenty of old shortcuts I would like to convert without re-making them one by one. Is there any utility allowing for this? If there's a solution that requires me to select them one by one will be fine. This will also solve the problem with Windows that sometimes destroys the once programmed path in normal shortcuts, before asking you to look for mistakes in the path...
1 Answers
I came up with a quick VBScript to bulk change shortcut targets. It invokes Relative.exe and overwrites the existing shortcuts, changing the target to relative paths.
Note: Before proceeding, please back up your original shortcuts. Always test with sample files first.
(Please update the Relative.exe path in Line#9 of the script if the program is installed on a different location.)
Option Explicit
If WScript.Arguments.Count = 0 Then WScript.Quit
Dim WshShell, WshShortcut, sAppPath, oFSO, sCmd
Dim sSrcFile, sTarget, sArgs, sWStyle, sHotkey, sSkipped, i
Set WshShell = CreateObject ("WScript.Shell")
Set oFSO = CreateObject ("Scripting.FileSystemObject")
sSkipped = "List of shortcuts skipped:" & vbCrLf & vbCrLf
sAppPath = """" & "C:\Program Files (x86)\Relative\Relative.exe" & """"
For i = 0 To WScript.Arguments.Count - 1
sSrcFile = WScript.Arguments(i)
If LCase(Right(sSrcFile, 4)) <> ".lnk" Then Exit For
'Get shortcut properties
Set WshShortcut = WshShell.CreateShortcut(sSrcFile)
sTarget = WshShortcut.TargetPath
sWStyle = WshShortcut.WindowStyle
sArgs = WshShortcut.Arguments
sHotkey = WshShortcut.Hotkey
'Skip if target has the .exe suffix, or the target is a File
If InStr(sTarget, ".exe") > 0 Or oFSO.FileExists (sTarget) Then
sTarget = ""
End If
'Skip if target is already in relative path format
If InStr(sTarget, ".") = 0 And Trim(sTarget) <> "" Then
'Run Relative.exe and overwrite existing shortcut
sCmd = sAppPath & " " & sTarget & " " & """" & _
Replace(sSrcFile, ".lnk", "") & """"
WshShell.Run sCmd,1, 1
'Restore shortcut Hotkey and Window style setting
WScript.Sleep 500
Set WshShortcut = WshShell.CreateShortcut(sSrcFile)
WshShortcut.WindowStyle = sWStyle
If sHotkey <> "" Then WshShortcut.Hotkey = sHotkey
WshShortcut.Save
Else
sSkipped = sSkipped & sSrcFile & vbCrLf
End If
Next
If Len (sSkipped) > 32 Then WScript.Echo sSkipped
Instructions
- Copy the above code to Notepad and save it as
ToRelative.vbs. - Open your
Sendtofolder (Hint: runshell:sendtoin Start/Run.) - Place the script's shortcut in the SendTo folder.
- Right-click a set of .lnk files, click Send To, and select
ToRelativein the Send to menu.
- 12,379