pythonwin:从.lnk(快捷方式)中获取文件名及创建桌面快捷方式

import os import pythoncom from win32com.shell import shell from win32com.shell import shellcon def GetpathFromLink(lnkpath): shortcut = pythoncom.CoCreateInstance( shell.CLSID_ShellLink, None, pythoncom.CLSCTX_INPROC_SERVER, shell.IID_IShellLink) shortcut.QueryInterface( pythoncom.IID_IPersistFile ).Load(lnkpath) path = shortcut.GetPath(shell.SLGP_SHORTPATH)[0] return path def CreateURLShortcut(url,name): shortcut = pythoncom.CoCreateInstance( shell.CLSID_InternetShortcut,None, pythoncom.CLSCTX_INPROC_SERVER,shell.IID_IUniformResourceLocator) shortcut.SetURL(url) if os.path.splitext(name)[-1] != '.url': name += '.url' shortcut.QueryInterface(pythoncom.IID_IPersistFile).Save(name,0) def CreateLnkpath(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" shortcut.QueryInterface(pythoncom.IID_IPersistFile).Save(lnkname,0) def GetDesktoppath(): ilist = shell.SHGetSpecialFolderLocation(0,shellcon.CSIDL_DESKTOP) dtpath = shell.SHGetPathFromIDList(ilist) #dtpath = dtpath.decode('gbk') return dtpath  

你可能感兴趣的:(python)