Created
April 12, 2017 16:17
-
-
Save CaddyDz/986cba0b043bc126805fe6d6baeb2fdb to your computer and use it in GitHub Desktop.
Get the target of a shortcut on Windows desktop
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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