加载中…
个人资料
  • 博客等级:
  • 博客积分:
  • 博客访问:
  • 关注人气:
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
正文 字体大小:

python 创建快捷方式

(2014-01-05 13:23:26)
标签:

python

快捷方式

winshell

it

分类: python
 
 
winshell.deskTop()   指的是桌面
winshell.startup()    指启动项
target 指快捷方式所指向的文件。即需要调用的文件。
下面这个函数将创建程序自身的快捷方式到桌面:

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) 
 
下面这个函数实现将本程序的快捷方式从桌面删除:
 

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)
 
 下面这个函数实现了建立快捷方式到启动组:
 

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)
 
下面是使用的demo:
  1. -*-code: utf-8 -*-  
  2. import os  
  3. import winshell  
  4.   
  5. def main():  
  6.     destDir winshell.desktop()  
  7.     filename "myShortcut"  
  8.     target r"D:\Python"  
  9.   
  10.     winshell.CreateShortcut(  
  11.         Path os.path.join(destDir, os.path.basename(filename)+".lnk"),  
  12.         Target target,  
  13.         Icon (target, 0),  
  14.         Description "shortcut test" 
  15.   
  16. if __name__ == "__main__" 
  17.     main()  

0

阅读 收藏 喜欢 打印举报/Report
前一篇:pyhook 安装
  

新浪BLOG意见反馈留言板 欢迎批评指正

新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 产品答疑

新浪公司 版权所有