Skip to content

Instantly share code, notes, and snippets.

@CaddyDz
Created April 12, 2017 16:17
Show Gist options
  • Save CaddyDz/986cba0b043bc126805fe6d6baeb2fdb to your computer and use it in GitHub Desktop.
Save CaddyDz/986cba0b043bc126805fe6d6baeb2fdb to your computer and use it in GitHub Desktop.
Get the target of a shortcut on Windows desktop
import os
from win32com.shell import shell
import pythoncom
# Create an instance of the shell
zsh = pythoncom.CoCreateInstance(shell.CLSID_ShellLink, None, pythoncom.CLSCTX_INPROC_SERVER, shell.IID_IShellLink)
# Query an interface of the persistent file
persist = zsh.QueryInterface(pythoncom.IID_IPersistFile)
targetOfLink = os.path.abspath('target.doc')
linkName = 'shortcut_to_target.doc.lnk'
zsh.SetPath(targetOfLink)
persist.Save(linkName, 1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment