Skip to content

Instantly share code, notes, and snippets.

@winhelponline
Created May 31, 2024 06:31
Show Gist options
  • Select an option

  • Save winhelponline/f441778cfefb0e4a74768a3291b79f3e to your computer and use it in GitHub Desktop.

Select an option

Save winhelponline/f441778cfefb0e4a74768a3291b79f3e to your computer and use it in GitHub Desktop.
Refresh thumbnails of folder shortcuts (.lnk)
'Refreshes the thumbnails of folder shortcuts (.lnk) files
'Written by Ramesh Srinivasan for winhelponline.com
'Created on 30-05-2024
Option Explicit
Dim WshShell, WshShortcut, FSO
Dim sTarget, sDesc, sSrcFldr, sOut, i
Dim objFolder, colFiles, objFile
Set FSO = CreateObject("Scripting.FileSystemObject")
Set WshShell = CreateObject ("WScript.Shell")
If WScript.Arguments.Count = 0 Then
sSrcFldr = WshShell.SpecialFolders("Desktop")
Call RefreshShortcuts
Else
For i = 0 To WScript.Arguments.Count - 1
sSrcFldr = WScript.Arguments(i)
Call RefreshShortcuts
Next
End If
Sub RefreshShortcuts
Set objFolder = FSO.GetFolder(sSrcFldr)
Set colFiles = objFolder.Files
'Iterate through each .lnk file
For Each objFile In colFiles
If LCase(Right(objFile.Name, 4)) = ".lnk" Then
'Get shortcut properties
Set WshShortcut = WshShell.CreateShortcut(objFile)
sTarget = WshShortcut.TargetPath
sDesc = WshShortcut.Description
If (FSO.FolderExists(sTarget)) Then
WshShortcut.Description = sDesc
On Error Resume Next
WshShortcut.Save
On Error GoTo 0
End If
End If
Next
End Sub
Set WshShell = Nothing
Set FSO = Nothing
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment