Creating Application Pins/Adding Folders in Python: A Step-by-Step Guide

Abstract: This article explains how to programmatically create Windows Start menu shortcuts and add folders using Python and the pywin32 library.

Created: 2026-08-08 by

To create application pins and add folders to the Windows Start menu using Python, you must interact with the operating system's shell via the win32com library. This approach allows scripts to generate shortcuts programmatically, placing them in specific directories like the user's startup folder or the public start menu path for immediate accessibility.

Prerequisites and Library Installation

The primary tool for this task is the pywin32 package, which provides Python bindings for the Windows API. Specifically, the win32com.client module gives access to the WScript.Shell object, which handles shortcut creation. Before writing any code, ensure your environment has this library installed. If you are using a virtual environment or a distribution like Anaconda, standard pip commands apply.

You can install the necessary package by running the following command in your terminal:

pip install pywin32

This installation adds the wintools utilities and COM interfaces required to manipulate file system objects that are not directly exposed by Python's standard library. Without this dependency, attempts to create shortcuts will fail because Python does not natively support creating .lnk files on Windows without external help. Note that this method is strictly limited to Windows environments; macOS and Linux use different mechanisms for application launching and menu management.

Identifying Target Directories

Before creating a pin, you need to know where Windows stores Start menu entries. There are two primary locations depending on whether the shortcut should be available to all users or just the current user.

  • User-Specific Start Menu: Located at %APPDATA%\Microsoft\Windows\Start Menu\Programs. Shortcuts here only appear for the logged-in user.
  • Public Start Menu: Located at %PROGRAMDATA%\Microsoft\Windows\Start Menu\Programs. These shortcuts appear for every user on the machine, provided they have permission to read the directory.

You can retrieve these paths dynamically in Python using the os and pathlib modules. It is best practice to use environment variables rather than hardcoding paths, as drive letters and user profiles may vary across systems. For example, accessing os.environ['APPDATA'] reliably points to the roaming profile directory of the current user.

Creating the Shortcut Object

The core logic involves initializing the WScript.Shell COM object and then calling its CreateShortcut method. This method returns a shortcut object that you can configure before saving it to disk.

import win32com.client
import os

shell = win32com.client.Dispatch("WScript.Shell")

# Define the target executable path
target_path = r"C:\Path\To\Your\Application.exe"

# Define the shortcut location
shortcut_path = os.path.join(os.environ['APPDATA'], 
                             'Microsoft', 'Windows', 'Start Menu', 
                             'Programs', 'MyApp.lnk')

# Create the shortcut object
shortcut = shell.CreateShortcut(shortcut_path)

# Configure properties
shortcut.TargetPath = target_path
shortcut.WorkingDirectory = os.path.dirname(target_path)
shortcut.Description = "Launch My Application"
shortcut.IconLocation = target_path + ",0"

# Save the shortcut to the Start Menu
shortcut.Save()

In this snippet, TargetPath specifies the actual executable that runs when the user clicks the icon. The WorkingDirectory is crucial for applications that load resources relative to their execution path; omitting it may cause runtime errors if the app expects to run from its own folder. The Description field populates the tooltip seen when hovering over the pinned item.

Handling Icons and Arguments

Many applications require command-line arguments to start correctly (e.g., opening a specific file or running in headless mode). You can pass these via the Arguments property of the shortcut object. Additionally, setting an IconLocation ensures the Start menu displays a custom image rather than the default white page icon. The format for icons is typically "path/to/icon.ico,index", where the index refers to the resource ID within the file.

Adding Folders to the Start Menu

If your goal is to organize multiple applications into a single category, you can create a subfolder within the Start Menu directory structure. Since the Start Menu is essentially a file system directory, you can use standard Python directory creation functions.

import os

start_menu_dir = os.path.join(os.environ['APPDATA'], 
                              'Microsoft', 'Windows', 'Start Menu', 
                              'Programs')

new_folder_name = "My Custom Group"
new_folder_path = os.path.join(start_menu_dir, new_folder_name)

if not os.path.exists(new_folder_path):
    os.makedirs(new_folder_path)
    print(f"Created folder: {new_folder_path}")

Once the folder exists, you can save your shortcuts inside new_folder_path instead of the root programs directory. This creates a visual grouping in the Start menu interface. Users will see the folder name and can click it to expand the list of contained applications. This technique is particularly useful for software suites or development tools that bundle multiple utilities together.

Best Practices and Error Handling

When automating system configurations, robust error handling is essential. Always check if the target executable exists before creating the shortcut to avoid broken links. Use os.path.exists() to validate paths. Furthermore, consider wrapping the COM interaction in a try-except block to handle cases where the user lacks administrative privileges or where the COM server is unavailable.

Avoid hardcoding absolute paths whenever possible. Instead, resolve paths relative to the script's location or use configuration files. This makes your Python script portable across different machines and installation directories. Regularly cleaning up old shortcuts during updates prevents clutter in the user's Start menu.

Frequently Asked Questions

Why does my shortcut point to python.exe instead of my script?

This happens if you set the TargetPath to the Python interpreter rather than your script file. Ensure you specify the full path to your .py or .exe file as the target. If you want to run a script, you might need to create a batch wrapper or use PyInstaller to compile it into a standalone executable first.

Can I create Start menu items on Linux or macOS with this method?

No, the win32com library relies on Windows COM interfaces which do not exist on other operating systems. On Linux, you would typically create .desktop files in ~/.local/share/applications. On macOS, you would create .app bundles or aliases in ~/Applications.

How do I remove a shortcut I created with Python?

Simply delete the .lnk file from the Start Menu directory using os.remove(shortcut_path). Since the Start Menu is just a folder on the file system, removing the file removes the entry immediately for the current user.

Is it safe to write to the Public Start Menu directory?

Writing to the Public Start Menu (%PROGRAMDATA%) usually requires administrator privileges. If your script runs without elevated rights, it will fail. For user-specific apps, stick to the %APPDATA% path which does not require admin rights.

Can I pin applications to the Taskbar instead of the Start Menu?

Pinning to the Taskbar is more complex and requires interacting with the Shell namespace differently. While possible with advanced COM calls, it is less stable than Start Menu shortcuts. It is generally recommended to stick to Start Menu pins for programmatic automation.

Latest News

How to Display Output of xterm Command in Terminal Screen using Cron

Resolve the inability to display xterm output in a terminal screen from cron by redirecting logs or using wall instead of insecure X11 workarounds.

Read More
Expose Local Server on VPS Preserving Real Client IPs (OS Level)

Resolve VPS logging showing only gateway IPs by configuring reverse proxies to forward real client addresses via X-Forwarded-For headers.

Read More
How to Clear Recent Files History in Linux without Deleting Actual Files?

Clear recent files history in Linux by deleting ~/.local/share/recently-used.xbel without removing the actual files.

Read More
Best HDD Copy Strategy: Manually Syncing and Rewriting Scratch

Resolve data drift between two 4TB hard drives by using rsync with the --delete flag to manually sync and rewrite scratch data for an exact mirror.

Read More
Understanding Bash Prompt Abbreviations: An Overview

Resolve repetitive typing errors by creating and persisting Bash aliases in the .bashrc file for improved command-line efficiency.

Read More
Free Tools and Methods to Log Real-Time Performance Details in Task Manager

Log real-time CPU and memory metrics to CSV files using Windows Performance Monitor Data Collector Sets to troubleshoot system slowness.

Read More
Contact Qatar Airways Customer Service: Phone Number, Help Center, and More

Resolve urgent Qatar Airways reservation issues like flight changes and baggage claims using the US phone number +1801-855-5905 or online self-service tools.

Read More
Windows 11: Alt Codes Displaying Wrong Characters - Solutions

Resolve Windows 11 Alt codes showing wrong characters by verifying the US keyboard layout and enabling Num Lock.

Read More
Run Programs with Elevated Privileges: A Comprehensive Guide

Eliminates the need to type sudo for frequent administrative tasks by configuring .bashrc aliases or functions.

Read More
Dynamically Changing Dates in Excel Formulas Using Cells

Eliminate manual date updates in Excel by using cell references to create dynamic formulas that automatically adjust calculations when input dates change.

Read More
Granting Edit Access to a Specific Excel Sheet in an Office 365 User Email ID-Based Login

Excel Online lacks native sheet-level permissions, so users must split workbooks or use worksheet protection to isolate edit access for specific tabs.

Read More
Creating Network Load on Local Wi-Fi from One PC

Generate sustained Wi-Fi bandwidth load from a single PC using a VM SFTP server to test router stability and throughput.

Read More
Changing the Default Editor for Batch Files in Windows 11's File Explorer

Resolve the issue of batch files opening in Notepad by changing the default editor to a preferred application like VS Code.

Read More
Gain WiFi Connection Minutes Before Losing it by Changing MAC Address

Bypass MAC address filtering to restore WiFi connectivity temporarily when a device is blocked by network administrators.

Read More
Photos Folders Turned Black: Troubleshooting Picture Applications on Windows

Resolve black screens in Windows Photos by resetting the app, updating graphics drivers, and repairing system files.

Read More
Troubleshooting High CPU Temperature Values: A Step-by-Step Guide

Resolve high CPU temperatures and thermal throttling by monitoring with Speedfan, cleaning dust from cooling components, and replacing degraded thermal paste.

Read More
Make cURL establish TLS connection with CA unknown

Resolve cURL TLS connection failures with unknown or self-signed certificates by using the --insecure flag to bypass CA validation.

Read More
Troubleshooting Incorrect Network Metrics Values in Grafana, Prometheus, InfluxDB, and Telegraf

Fix incorrect network metrics in Grafana, Prometheus, InfluxDB, and Telegraf by verifying interface selection, resolving unit mismatches, and handling counter resets.

Read More
Start Another Terminal Window (cmd.exe) Windows Repair/Troubleshoot

Provides step-by-step instructions to access the Windows Command Prompt via bootable media for advanced system repair and troubleshooting.

Read More
Thinkpad P1 Gen 6: Sudden Thunderbolt 3 Dock USB-C Charging Stopped Working

Resolve sudden Thunderbolt 3 dock USB-C charging and internet failure on ThinkPad P1 Gen 6 by updating firmware, resetting the dock, and adjusting power settings.

Read More
ASUS Windows 11 Laptop: Internet Connection Issue with Hotspot

Resolve ASUS Windows 11 laptop spinning wheel issue when connecting to mobile hotspot by resetting network stack, disabling IPv6, and adjusting power settings.

Read More
Developing iOS Project with Firebase: Logging in and Sending Push Notifications

Integrates Firebase to enable secure user authentication and push notifications in iOS applications.

Read More
Troubleshooting Bash Script with Suspected Issues of Spaces, Dashes, Filenames and Quoting

Resolve Bash script failures caused by word splitting, globbing, and special characters in filenames by applying proper quoting techniques.

Read More
Populating OneDrive Folder for Local Backup without Affecting Remote Files

Prevent OneDrive from deleting remote files during Windows reinstallation by unlinking the account or using symbolic links to isolate local data.

Read More
Force First Frame as Keyframe Without Re-encoding: A Quick Solution

Resolve inaccurate seeking and playback glitches by re-encoding video to ensure the first frame is a valid keyframe.

Read More
Find Information in Database Using WSL (Ubuntu) on Windows-10

Resolve database connection issues from WSL Ubuntu on Windows 10 by configuring client tools and network access to query remote or local servers.

Read More
Configuring a New Router with Different Networks: One Family, One Guest

Resolve IP conflicts and isolate guest traffic by configuring a second router with a distinct subnet via its WAN port.

Read More
Quickly Open Multiple Stock Websites with a Single Command

Solve the problem of manually opening multiple stock research websites by creating a single command to launch them simultaneously on Windows, macOS, or Linux.

Read More
Improved Adobe Acrobat Search Experience: Access Advanced Search with Ease

Access advanced search filters like case sensitivity and regex in Adobe Acrobat by clicking More Options in the Find bar.

Read More
Port Forwarding VM via OpenVPN: A Comprehensive Guide

Configure OpenVPN server and iptables to forward specific ports from VPN clients to a virtual machine's internal IP address.

Read More
Understanding Partitions in the 1980s: A Look Back at MS-DOS and Master Boot Record

Explains how the Master Boot Record and partition table enabled MS-DOS to manage multiple disk volumes on a single physical drive.

Read More
Windows 10 Enterprise: Keyboard Not Detected in Managed Organization with Admin Privileges

Resolve Windows 10 Enterprise keyboard detection failures caused by Group Policy restrictions, driver corruption, or USB enumeration errors.

Read More
Can't Find x86_64 Versions of Applications on MacOS arm64 (M1)

Resolve missing x86_64 app issues on M1 Macs by installing Rosetta 2 and reinstalling apps as universal binaries.

Read More
How to Hide Installation Source for an Android App

Manage Android app installation source visibility by using USB transfers or file managers to reduce browser traces and isolate data via work profiles.

Read More
Connecting Momentus 4200.2 ST9808210A Hard Drive via USB Cable

Resolve inability to access Seagate Momentus 4200.2 ST9808210A hard drive by connecting it via USB using a compatible SATA-to-USB adapter and configuring the disk in Windows.

Read More