Skip to content

Instantly share code, notes, and snippets.

@vyach-vasiliev
Last active April 25, 2017 19:11
Show Gist options
  • Save vyach-vasiliev/93e85a4c02e0b1b69e6d0dfc74d2d827 to your computer and use it in GitHub Desktop.
Save vyach-vasiliev/93e85a4c02e0b1b69e6d0dfc74d2d827 to your computer and use it in GitHub Desktop.
Useful pieces of code
from win32com.shell import shell, shellcon
def get_startup_directory(common):
"""
Copyright Tim Golden <winshell@timgolden.me.uk> 25th November 2003 - 2012
Licensed under the (GPL-compatible) MIT License:
http://www.opensource.org/licenses/mit-license.php
"""
return shell.SHGetFolderPath(0, (shellcon.CSIDL_STARTUP, shellcon.CSIDL_COMMON_STARTUP)[common], None, 0)
get_startup_directory(0) # 'C:\\Users\\<USERNAME>\\AppData\\Roaming\\Microsoft\\Windows\\Start Menu\\Programs\\Startup'
get_startup_directory(1) # 'C:\\ProgramData\\Microsoft\\Windows\\Start Menu\\Programs\\Startup'
import pythoncom
def get_shortcut_target (self, shortcutfile):
link = pythoncom.CoCreateInstance(shell.CLSID_ShellLink, None, pythoncom.CLSCTX_INPROC_SERVER, shell.IID_IShellLink)
link.QueryInterface (pythoncom.IID_IPersistFile).Load(shortcutfile)
target_path, _ = link.GetPath(shell.SLGP_UNCPRIORITY)
return target_path
get_shortcut_target('*.lnk') # '*.exe'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment