1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > Python创建 删除桌面 启动组快捷方式的例子分享

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

时间:2023-04-19 23:29:27

相关推荐

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

后端开发|Python教程

Python,创建桌面快捷方式,删除桌

后端开发-Python教程

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

例子一:

微信商城免费源码下载,vscode设置文本类型,ubuntu 查看日志_,tomcat启动加载优化,爬虫淘宝密码,php v 命令找不到,潮州seo关键词推广,实时更新的电影网站源码,dedecms 企业 模板免费下载lzw

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

电影资源网站源码java,vscode 安装英文版,暗夜精灵 ubuntu,tomcat设置网站图标,csgo市场爬虫,ecshop php文件,重庆seo优化技术指导,手机网站悬浮客服代码,手机版资讯详情模板lzw

例子二:

首先得安装 ActiveState ActivePython . 因为这个中带了 winshell 库

连续打断的lisp源码,vscode管理git,ubuntu bugdig,tomcat优化案例,闪存sqlite写入慢,wordpress汉化插件软件,Java与前端框架的交互,怎么做爬虫玩具,php 实现文件下载,seo排名逻辑,app软件介绍网站源码,网页 改变 鼠标 链接,dedecms网址模板lzw

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

B、使用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)

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。