Python Create, delete desktop, start Group shortcuts example share _linux shell

Source: Internet
Author: User

One, python create desktop shortcuts 2 examples

Example one:

Copy Code code as follows:

Import OS
Import pythoncom
From Win32com.shell Import shell
From Win32com.shell import Shellcon

Def createdesktoplnk (filename,lnkname):
    shortcut = pythoncom. CoCreateInstance (   
        shell). Clsid_shelllink, none,   
        pythoncom. Clsctx_inproc_server, Shell. Iid_ishelllink)    
    shortcut. SetPath (filename)    
    if Os.path.splitext (lnkname) [-1]!= '. lnk ':    
        Lnkname +. LNK
    # Get Desktop path
& nbsp;   DesktopPath = Shell. SHGetPathFromIDList (shell. SHGetSpecialFolderLocation (0,shellcon. csidl_desktop))
    lnkname = Os.path.join (desktoppath,lnkname)
    shortcut. QueryInterface (Pythoncom. Iid_ipersistfile). Save (lnkname,0)   

if __name__ = = ' __main__ ':
Createdesktoplnk (U "C:\Python27\python.exe", "Mypython")

Example two:
First have to install ActiveState ActivePython. Because it's got a WinShell library.

Copy Code code as follows:

From OS import path
Import WinShell


#----------------------------------------------------------------------
def create_shortcut_to_desktop (Target,title):
"" "Create Shortcut to Desktop" "" "
s = path.basename (target)
FName = Path.splitext (s) [0]
WinShell. CreateShortcut (
Path = Path.join (Winshell.desktop (), fname + '. lnk '),
target = target,
icon= (target, 0),
Description=title)

Note: Win64 is not supported


Second, use WinShell module to create, delete desktop, start group shortcuts

When writing an application and release, we want to create shortcuts on the user's desktop to facilitate user action, WinShell module provides the functions we need

The following function creates a shortcut to the desktop for the program itself:

Copy Code code as follows:

From OS import path
Import WinShell

Def create_shortcut_to_desktop ():
target = argv[0]
title = ' My Shortcuts '
s = path.basename (target)
FName = Path.splitext (s) [0]
WinShell. CreateShortcut (
Path = Path.join (Winshell.desktop (), fname + '. lnk '),
target = target,
icon= (target, 0),
Description=title)

The following function enables you to remove shortcuts for this program from the desktop:

Copy Code code as follows:

Def delete_shortcut_from_startup ():
target = argv[0]
s = path.basename (target)
FName = Path.splitext (s) [0]
Delfile = Path.join (Winshell.startup (), fname + '. Lnk ')
Winshell.delete_file (Delfile)

The following function implements the setting up of shortcuts to the Startup group:

Copy Code code as follows:

From OS import path
Import WinShell

Def create_shortcut_to_startup ():
target = argv[0]
title = ' My Shortcuts '
s = path.basename (target)
FName = Path.splitext (s) [0]
WinShell. CreateShortcut (
Path = Path.join (Winshell.startup (),
FName + '. lnk '),
target = target,
icon= (target, 0),
Description=title)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.