FAQ
Hi All--
Is there a function in the Win32 stuff to read .lnk files? I'm looking
for a *minimal* script to do nothing but read a .lnk given on the
command line and spit the contents out on stdout.

Thanks,
Ivan
----------------------------------------------
Ivan Van Laningham
Callware Technologies, Inc.
ivanlan at callware.com
ivanlan at home.com
http://www.pauahtun.org
See also:
http://www.foretec.com/python/workshops/1998-11/proceedings.html
Army Signal Corps: Cu Chi, Class of '70
----------------------------------------------

Search Discussions

  • Mark Hammond at Nov 2, 1999 at 10:43 pm
    Sure is. For more details, see the COM help file on PyIShellLink.

    Mark.

    # 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
  • Mark Hammond at Nov 3, 1999 at 12:07 am
    Ivan has mailed me that this does not work for him (dies with a big
    crash!). If anyone else has a spare moment, could you please try this
    code and see if it works? Whether it does or not, please also include
    info on the OS you tried it on. Please mail me personally with this
    info, and I will summarize back to the list.

    Thanks,

    Mark.
    -----Original Message-----
    From: python-list-admin at python.org
    [mailto:python-list-admin at python.org]On Behalf Of Mark Hammond
    Sent: Wednesday, 3 November 1999 9:44
    To: 'Ivan Van Laningham'; 'Python Mailing List'
    Subject: RE: Reading .lnk files


    Sure is. For more details, see the COM help file on PyIShellLink.

    Mark.

    # 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


    --
    http://www.python.org/mailman/listinfo/python-list
  • Mark Hammond at Nov 3, 1999 at 2:31 am
    OK - thanks everyone - it seems certain that the code does indeed
    work, and that the problem was something specific to Ivan - quite
    possibly his use of the MKS shell. Ive had positive responses from
    NT, 98 and 95 now.

    Thanks,

    Mark.

    [I wrote]
    Ivan has mailed me that this does not work for him (dies with a big
    crash!). If anyone else has a spare moment, could you please try this
    code and see if it works? Whether it does or not, please also include
    info on the OS you tried it on. Please mail me personally with this
    info, and I will summarize back to the list.

    Thanks,

    Mark.
    -----Original Message-----
    From: python-list-admin at python.org
    [mailto:python-list-admin at python.org]On Behalf Of Mark Hammond
    Sent: Wednesday, 3 November 1999 9:44
    To: 'Ivan Van Laningham'; 'Python Mailing List'
    Subject: RE: Reading .lnk files


    Sure is. For more details, see the COM help file on PyIShellLink.

    Mark.

    # 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


    --
    http://www.python.org/mailman/listinfo/python-list

    --
    http://www.python.org/mailman/listinfo/python-list

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppython-list @
categoriespython
postedNov 2, '99 at 9:51p
activeNov 3, '99 at 2:31a
posts4
users2
websitepython.org

People

Translate

site design / logo © 2022 Grokbase