winfolders.py 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. ''' Get windows special folders without pythonwin
  2. Example:
  3. import specialfolders
  4. start_programs = specialfolders.get(specialfolders.PROGRAMS)
  5. Code is public domain, do with it what you will.
  6. Luke Pinner - Environment.gov.au, 2010 February 10
  7. '''
  8. #Imports use _syntax to mask them from autocomplete IDE's
  9. import ctypes as _ctypes
  10. 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
  11. _SHGetFolderPath = _ctypes.windll.shell32.SHGetFolderPathW
  12. #public special folder constants
  13. DESKTOP= 0
  14. PROGRAMS= 2
  15. MYDOCUMENTS= 5
  16. FAVORITES= 6
  17. STARTUP= 7
  18. RECENT= 8
  19. SENDTO= 9
  20. STARTMENU= 11
  21. MYMUSIC= 13
  22. MYVIDEOS= 14
  23. NETHOOD= 19
  24. FONTS= 20
  25. TEMPLATES= 21
  26. ALLUSERSSTARTMENU= 22
  27. ALLUSERSPROGRAMS= 23
  28. ALLUSERSSTARTUP= 24
  29. ALLUSERSDESKTOP= 25
  30. APPLICATIONDATA= 26
  31. PRINTHOOD= 27
  32. LOCALSETTINGSAPPLICATIONDATA= 28
  33. ALLUSERSFAVORITES= 31
  34. LOCALSETTINGSTEMPORARYINTERNETFILES=32
  35. COOKIES= 33
  36. LOCALSETTINGSHISTORY= 34
  37. ALLUSERSAPPLICATIONDATA= 35
  38. def get(intFolder):
  39. _SHGetFolderPath.argtypes = [_HWND, _ctypes.c_int, _HANDLE, _DWORD, _LPCWSTR]
  40. auPathBuffer = _cub(_MAX_PATH)
  41. exit_code=_SHGetFolderPath(0, intFolder, 0, 0, auPathBuffer)
  42. return auPathBuffer.value
  43. if __name__ == "__main__":
  44. import os
  45. print get(STARTUP)
  46. open(get(STARTUP)+"\\zeronet.cmd", "w").write("cd /D %s\r\nzeronet.py" % os.getcwd())