G
G
Grandma Luda2021-10-13 11:53:04
Python
Grandma Luda, 2021-10-13 11:53:04

How to create a shortcut for an application?

I need to create a shortcut for the selected file to the selected location

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vasily Bannikov, 2021-10-13
@vabka

On Windows, you can create a shortcut using the pywin32 library:

import pythoncom
import os
# pythoncom.CoInitialize() # remove the '#' at the beginning of the line if running in a thread.
desktop = r'C:\Users\Public\Desktop' # path to where you want to put the .lnk
path = os.path.join(desktop, 'NameOfShortcut.lnk')
target = r'C:\path\to\target\file.exe'
icon = r'C:\path\to\icon\resource.ico' # not needed, but nice

shell = win32com.client.Dispatch("WScript.Shell")
shortcut = shell.CreateShortCut(path)
shortcut.Targetpath = target
shortcut.IconLocation = icon
shortcut.WindowStyle = 7 # 7 - Minimized, 3 - Maximized, 1 - Normal
shortcut.save()

https://pypi.org/project/pywin32/
https://stackoverflow.com/a/46081847
Or using the swinlink library:
from swinlnk.swinlnk import SWinLnk
swl = SWinLnk()
swl.create_lnk('W:\Foo\Bar', '/mnt/win_share/playground/Bar_winlink.lnk')

https://github.com/bristi/swinlnk
Or write the code for this from scratch, according to the specification:
https://docs.microsoft.com/en-us/openspecs/windows...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question