主页 > 知识库 > Python创建、删除桌面、启动组快捷方式的例子分享

Python创建、删除桌面、启动组快捷方式的例子分享

热门标签:东莞电销机器人价格一览表 百度地图标注图标更换 陕西电销卡外呼系统怎么安装 excel地址地图标注 杭州机器人外呼系统 佛山高德地图标注中心 百度地图的地图标注 旅游地图标注大全 地图标注超出范围怎么办

一、Python创桌面建快捷方式的2个例子

例子一:

复制代码 代码如下:

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 库

复制代码 代码如下:

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模块创建、删除桌面、启动组快捷方式

当写好一个应用并发行的时候,我们希望在用户的桌面上建立快捷方式方便用户操作,winshell模块提供了我们需要的功能

下面这个函数将创建程序自身的快捷方式到桌面:

复制代码 代码如下:

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)

 

 

 

您可能感兴趣的文章:
  • python3应用windows api对后台程序窗口及桌面截图并保存的方法
  • python实现桌面托盘气泡提示
  • python实现桌面气泡提示功能
  • Python 获取windows桌面路径的5种方法小结
  • 如何使用Python自动控制windows桌面
  • python制作一个桌面便签软件
  • Python远程桌面协议RDPY安装使用介绍
  • Python3如何实现Win10桌面自动切换

标签:通辽 随州 青岛 雅安 南充 朝阳 西藏 延边

巨人网络通讯声明:本文标题《Python创建、删除桌面、启动组快捷方式的例子分享》,本文关键词  Python,创建,删除,桌面,启动,;如发现本文内容存在版权问题,烦请提供相关信息告之我们,我们将及时沟通与处理。本站内容系统采集于网络,涉及言论、版权与本站无关。
  • 相关文章
  • 下面列出与本文章《Python创建、删除桌面、启动组快捷方式的例子分享》相关的同类信息!
  • 本页收集关于Python创建、删除桌面、启动组快捷方式的例子分享的相关信息资讯供网民参考!
  • 推荐文章