奇诺冲击2怎么创建桌面快捷方式快捷方式

Python创建、删除桌面、启动组快捷方式的例子分享
字体:[ ] 类型:转载 时间:
这篇文章主要介绍了Python创建、删除桌面、启动组快捷方式的例子分享,需要的朋友可以参考下
一、Python创桌面建快捷方式的2个例子
代码如下:import osimport pythoncomfrom 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) &
您可能感兴趣的文章:
大家感兴趣的内容
12345678910
最近更新的内容
常用在线小工具拒绝访问 |
| 百度云加速
请打开cookies.
此网站 () 的管理员禁止了您的访问。原因是您的访问包含了非浏览器特征(3909bcacd82443a7-ua98).
重新安装浏览器,或使用别的浏览器}

我要回帖

更多关于 桌面无法创建快捷方式 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信