Python Forum
Creating Shortcuts with python
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Creating Shortcuts with python
#1
Is there a way for me to create a shortcut (.lnk) file using python. I searched everywhere, but found no answer that works :(
Reply
#2
Both pywin32 and winshell shortcut can do this.
Can do quick test with to see in work with newest Python 3.10.5 as winshell is old.
import os, sys
import winshell

link_filepath = os.path.join(winshell.desktop(), "python.lnk")
with winshell.shortcut(link_filepath) as link:
  link.path = sys.executable
  link.description = "Shortcut to python" 
Work fine create a working shortcut to Python on the Desktop.
Reply
#3
(Jun-22-2022, 12:13 PM)snippsat Wrote: Both pywin32 and winshell shortcut can do this.
Can do quick test with to see in work with newest Python 3.10.5 as winshell is old.
import os, sys
import winshell

link_filepath = os.path.join(winshell.desktop(), "python.lnk")
with winshell.shortcut(link_filepath) as link:
  link.path = sys.executable
  link.description = "Shortcut to python" 
Work fine create a working shortcut to Python on the Desktop.

Throws this error:
Error:
Traceback (most recent call last): File "d:\1. Oshadha\2. Code\Python\Test.py", line 2, in <module> import winshell File "C:\Users\DELL\AppData\Local\Programs\Python\Python310\lib\site-packages\winshell.py", line 30, in <module> import win32con ModuleNotFoundError: No module named 'win32con'
When I try pip install win32con

It gives another error:
Error:
ERROR: Could not find a version that satisfies the requirement win32con (from versions: none) ERROR: No matching distribution found for win32con
Im using the newest version of python: 3.10.5 64Bit

I found many websites using this winshell module and I gave up because it gave the same error.


EDIT: I solved the error.
pip install pywin32 solves the issue!
Thanks for everyone's help!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Need help with infinite loop & making hotkeys/shortcuts Graxum 1 1,179 Aug-22-2022, 02:57 AM
Last Post: deanhystad
  IDLE keyboard shortcuts tam 2 2,896 May-15-2019, 06:34 AM
Last Post: tam
  Converting an 8-bit binary to decimal WITHOUT the shortcuts EIA 5 7,020 Dec-01-2017, 09:04 AM
Last Post: stranac
  Pycharm shortcuts and operators don't run AzD 6 7,970 Oct-17-2017, 05:46 PM
Last Post: Larz60+
  Automatically read copied text from keyboard shortcuts Ambidexter2017 10 11,219 Mar-10-2017, 01:46 PM
Last Post: wavic

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020