Sometimes you want to add desktop shortcuts to your programs , But I don't even know the exact path to the desktop , Fortunately, Microsoft API This paper gives some methods to get the path of special folders , recycling python Of win32com modular ( Non standard library ) Can be in python Achieve the same operation in !
# -- coding: cp936 -- from win32com.shell import shell from win32com.shell import shellcon # obtain " start-up " Folder path , The key is the final parameter CSIDL_STARTUP, These parameters can be found in Microsoft's official documentation startup_path = shell.SHGetPathFromIDList(shell.SHGetSpecialFolderLocation(0,shellcon.CSIDL_STARTUP)) # obtain " desktop " Folder path , Replace the last parameter with CSIDL_DESKTOP that will do desktop_path = shell.SHGetPathFromIDList(shell.SHGetSpecialFolderLocation(0,shellcon.CSIDL_DESKTOP)) if __name__ == "__main__": print startup_path print desktop_path </pre>