Python Create Shortcut

Source: Internet
Author: User

With Pywin32, can you do whatever you like on Windows?

Yes.

#-*-coding:cp936-*-# import osimport pythoncomfrom Win32com.shell import shellfrom Win32com.shell import shellcondef Set_shortcut (filename,lnkname,iconname): #如无需特别设置图标, you can remove the iconname parameter shortcut = pythoncom. CoCreateInstance (Shell. Clsid_shelllink, None, pythoncom. Clsctx_inproc_server, Shell. Iid_ishelllink) shortcut. SetPath (filename) shortcut.    Seticonlocation (iconname,0) #可有可无, does not use the default file itself icon if Os.path.splitext (lnkname) [-1]! = '. Lnk ': Lnkname + = ". Lnk" Shortcut. QueryInterface (Pythoncom. Iid_ipersistfile). Save (lnkname,0) If __name__ = = "__main__": #获取 "Startup" folder path, the key is the final parameter csidl_startup, these parameters can be found in Microsoft's official API Startup_path = s Hell. SHGetPathFromIDList (shell. SHGetSpecialFolderLocation (0,shellcon. Csidl_startup)) #获取 the "desktop" folder path, change the last parameter to csidl_desktop Desktop_path = Shell. SHGetPathFromIDList (shell. SHGetSpecialFolderLocation (0,shellcon. Csidl_desktop) file_name= "" #要创建快捷方式的文件的完整路径 icon_name= "" #图标文件的完整路径 (not required) lnk_name1= startup_path+ "\ \ My desktop shortcut. lnk" #将要在此路径Create Shortcut lnk_name2= startup_path+ "\ \ My startup group shortcut. Lnk" Set_shortcut (file_name,lnk_name1,icon_name) set_shortcut (file_na Me,lnk_name2,icon_name)


Python Create Shortcut

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.