如何获得开始菜单程序目录的path?

…为当前用户? 为所有用户?

我正在开发一个小程序,需要在开始菜单中创build链接。 目前我像下面一样硬编码,但它只能在英文区域使用,例如在德语中应该是“Startmenü”。 什么是更清洁,更便携的方法?

OUR_STARTMENU = os.environ['ALLUSERSPROFILE'] + '\Start Menu\Programs\Our Stuff' 

谢谢

Solutions Collecting From Web of "如何获得开始菜单程序目录的path?"

我听说有两种方法。 第一:

 from win32com.shell import shell shell.SHGetSpecialFolderPath(0,shellcon.CSIDL_COMMON_STARTMENU) 

其次,使用WScript.Shell对象(来源: http : //www.mail-archive.com/python-win32@python.org/msg00992.html ):

 import win32com.client objShell = win32com.client.Dispatch("WScript.Shell") allUserProgramsMenu = objShell.SpecialFolders("AllUsersPrograms") userMenu = objShell.SpecialFolders("StartMenu") 

另一个来源: http : //blogs.msdn.com/saveenr/archive/2005/12/28/creating-a-start-menu-shortcut-with-powershell-and-python.aspx

此外,CSIDL_COMMON_STARTMENU适用于所有用户启动,CSIDL_STARTMENU适用于当前用户启动。

Environment.gov.au的朋友Luke Pinner通过电子邮件给出了一个使用核心模块(python 2.5+)的解决方案。 相信是多语言的,因为来自API调用的返回是unicode。 在Win7上使用日语语言环境进行测试,并在另一台美国英语机器上通过手动更改“开始”菜单指向%USERPROFILE%\Startmenü

 ''' Get windows special folders without pythonwin Example: import specialfolders start_programs = specialfolders.get(specialfolders.PROGRAMS) Code is public domain, do with it what you will. Luke Pinner - Environment.gov.au, 2010 February 10 ''' #Imports use _syntax to mask them from autocomplete IDE's import ctypes as _ctypes from ctypes.wintypes import HWND as _HWND, HANDLE as _HANDLE,DWORD as _DWORD,LPCWSTR as _LPCWSTR,MAX_PATH as _MAX_PATH, create_unicode_buffer as _cub _SHGetFolderPath = _ctypes.windll.shell32.SHGetFolderPathW #public special folder constants DESKTOP= 0 PROGRAMS= 2 MYDOCUMENTS= 5 FAVORITES= 6 STARTUP= 7 RECENT= 8 SENDTO= 9 STARTMENU= 11 MYMUSIC= 13 MYVIDEOS= 14 NETHOOD= 19 FONTS= 20 TEMPLATES= 21 ALLUSERSSTARTMENU= 22 ALLUSERSPROGRAMS= 23 ALLUSERSSTARTUP= 24 ALLUSERSDESKTOP= 25 APPLICATIONDATA= 26 PRINTHOOD= 27 LOCALSETTINGSAPPLICATIONDATA= 28 ALLUSERSFAVORITES= 31 LOCALSETTINGSTEMPORARYINTERNETFILES=32 COOKIES= 33 LOCALSETTINGSHISTORY= 34 ALLUSERSAPPLICATIONDATA= 35 def get(intFolder): _SHGetFolderPath.argtypes = [_HWND, _ctypes.c_int, _HANDLE, _DWORD, _LPCWSTR] auPathBuffer = _cub(_MAX_PATH) exit_code=_SHGetFolderPath(0, intFolder, 0, 0, auPathBuffer) return auPathBuffer.value