国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發(fā) > Linux Shell > 正文

Python創(chuàng)建、刪除桌面、啟動組快捷方式的例子分享

2020-07-27 19:17:09
字體:
供稿:網(wǎng)友

一、Python創(chuàng)桌面建快捷方式的2個例子

例子一:

復(fù)制代碼 代碼如下:

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
    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")

例子二:
首先得安裝 ActiveState ActivePython  . 因為這個中帶了 winshell 庫

復(fù)制代碼 代碼如下:

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) 

注:不支持win64


二、使用winshell模塊創(chuàng)建、刪除桌面、啟動組快捷方式

當寫好一個應(yīng)用并發(fā)行的時候,我們希望在用戶的桌面上建立快捷方式方便用戶操作,winshell模塊提供了我們需要的功能

下面這個函數(shù)將創(chuàng)建程序自身的快捷方式到桌面:

復(fù)制代碼 代碼如下:

from os import path 
import winshell 

def create_shortcut_to_desktop(): 
    target = argv[0] 
    title = '我的快捷方式'
    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) 

下面這個函數(shù)實現(xiàn)將本程序的快捷方式從桌面刪除:

復(fù)制代碼 代碼如下:

 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)
 

下面這個函數(shù)實現(xiàn)了建立快捷方式到啟動組:

復(fù)制代碼 代碼如下:

from os import path 
import winshell 

def create_shortcut_to_startup(): 
      target = argv[0] 
      title = '我的快捷方式'
      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)

 

 

 

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 中卫市| 德阳市| 集安市| 新宁县| 泽普县| 嘉祥县| 孝义市| 龙井市| 沾益县| 舟曲县| 伽师县| 姚安县| 六枝特区| 保亭| 任丘市| 江达县| 南康市| 张家口市| 鄂尔多斯市| 靖宇县| 乐山市| 长丰县| 托里县| 京山县| 鲁甸县| 高淳县| 铅山县| 商洛市| 连山| 泗水县| 黄浦区| 江津市| 措美县| 分宜县| 泌阳县| 依安县| 中超| 呼玛县| 桂东县| 新和县| 新营市|