最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

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

 更新時間:2014年04月15日 11:40:17   作者:  
這篇文章主要介紹了Python創(chuà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  . 因?yàn)檫@個中帶了 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)建、刪除桌面、啟動組快捷方式

當(dā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ù)實(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ù)實(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)

 

 

 

相關(guān)文章

最新評論

阿坝县| 竹溪县| 铜鼓县| 大邑县| 偃师市| 庆元县| 格尔木市| 岳池县| 晋城| 西华县| 绿春县| 宝清县| 诸城市| 当雄县| 东兰县| 广安市| 筠连县| 连城县| 临猗县| 泸水县| 尉氏县| 闽清县| 博野县| 荣昌县| 宁德市| 龙海市| 平泉县| 惠东县| 凌源市| 江北区| 许昌市| 崇礼县| 湛江市| 滦南县| 虞城县| 荆州市| 临西县| 建始县| 辛集市| 荣成市| 新闻|