1
# Copyright (c) 2001-2004 Twisted Matrix Laboratories.
2
# See LICENSE for details.
5
"""Creation of Windows shortcuts.
10
from win32com.shell import shell
16
"""Open an existing shortcut for reading.
18
@return: The shortcut object
27
"""A shortcut on Win32.
28
>>> sc=Shortcut(path, arguments, description, workingdir, iconpath, iconidx)
29
@param path: Location of the target
30
@param arguments: If path points to an executable, optional arguments to
32
@param description: Human-readable decription of target
33
@param workingdir: Directory from which target is launched
34
@param iconpath: Filename that contains an icon for the shortcut
35
@param iconidx: If iconpath is set, optional index of the icon desired
45
self._base = pythoncom.CoCreateInstance(
46
shell.CLSID_ShellLink, None,
47
pythoncom.CLSCTX_INPROC_SERVER, shell.IID_IShellLink
50
['"%s"' % os.path.abspath(path), arguments, description,
51
os.path.abspath(workingdir), os.path.abspath(iconpath)],
52
("SetPath", "SetArguments", "SetDescription",
53
"SetWorkingDirectory") )
54
for value, function in data:
55
if value and function:
56
# call function on each non-null value
57
getattr(self, function)(value)
59
self.SetIconLocation(iconpath, iconidx)
61
def load( self, filename ):
62
"""Read a shortcut file from disk."""
63
self._base.QueryInterface(pythoncom.IID_IPersistFile).Load(filename)
65
def save( self, filename ):
66
"""Write the shortcut to disk.
68
The file should be named something.lnk.
70
self._base.QueryInterface(pythoncom.IID_IPersistFile).Save(filename, 0)
72
def __getattr__( self, name ):
74
return getattr(self._base, name)
75
raise AttributeError, "%s instance has no attribute %s" % \
76
(self.__class__.__name__, name)