faqts : Computers : Programming : Languages : Python : Snippets

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

23 of 73 people (32%) answered Yes
Recently 6 of 10 people (60%) answered Yes

Entry

Reading and writing .lnk files

Jul 5th, 2000 10:02
Nathan Wallace, Hans Nowak, Snippet 268, Mark Hammond


"""
Packages: operating_systems.windows
"""
# DumpShortcut.py
# A demo of how to dump a shortcut using Python.
# This code dumps the shortcut specificed as sys.argv[1]
from win32com.shell import shell
import pythoncom
def DumpIt(fileName):
# Get the shell interface.
    sh = pythoncom.CoCreateInstance(shell.CLSID_ShellLink, None, \
      pythoncom.CLSCTX_INPROC_SERVER, shell.IID_IShellLink)
    # Get an IPersist interface
    persist = sh.QueryInterface(pythoncom.IID_IPersistFile)
    persist.Load(fileName)
    # Get the data
    print "Path name:", sh.GetPath(shell.SLGP_SHORTPATH)[0]
    print "Args:", sh.GetArguments()
    print "Description:", sh.GetDescription()
    print "Working directory:", sh.GetWorkingDirectory()
if __name__=='__main__':
    import sys
    DumpIt(sys.argv[1])
# demo of usage:
# C:\>DumpShortcut.py IDLE.lnk
# Path name: L:\src\PYTHON~1.2\PCbuild\pythonw.exe
# Args: l:\src\python-cvs\tools\idle\idle.pyw
# Description:
# Working directory: L:\src\python-cvs\tools\idle