winfolders.py 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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 import create_unicode_buffer as _cub
  11. from ctypes.wintypes import HWND as _HWND, HANDLE as _HANDLE,DWORD as _DWORD,LPCWSTR as _LPCWSTR,MAX_PATH as _MAX_PATH
  12. _SHGetFolderPath = _ctypes.windll.shell32.SHGetFolderPathW
  13. #public special folder constants
  14. DESKTOP= 0
  15. PROGRAMS= 2
  16. MYDOCUMENTS= 5
  17. FAVORITES= 6
  18. STARTUP= 7
  19. RECENT= 8
  20. SENDTO= 9
  21. STARTMENU= 11
  22. MYMUSIC= 13
  23. MYVIDEOS= 14
  24. NETHOOD= 19
  25. FONTS= 20
  26. TEMPLATES= 21
  27. ALLUSERSSTARTMENU= 22
  28. ALLUSERSPROGRAMS= 23
  29. ALLUSERSSTARTUP= 24
  30. ALLUSERSDESKTOP= 25
  31. APPLICATIONDATA= 26
  32. PRINTHOOD= 27
  33. LOCALSETTINGSAPPLICATIONDATA= 28
  34. ALLUSERSFAVORITES= 31
  35. LOCALSETTINGSTEMPORARYINTERNETFILES=32
  36. COOKIES= 33
  37. LOCALSETTINGSHISTORY= 34
  38. ALLUSERSAPPLICATIONDATA= 35
  39. def get(intFolder):
  40. _SHGetFolderPath.argtypes = [_HWND, _ctypes.c_int, _HANDLE, _DWORD, _LPCWSTR]
  41. auPathBuffer = _cub(_MAX_PATH)
  42. exit_code=_SHGetFolderPath(0, intFolder, 0, 0, auPathBuffer)
  43. return auPathBuffer.value
  44. if __name__ == "__main__":
  45. import os
  46. print(get(STARTUP))
  47. open(get(STARTUP)+"\\zeronet.cmd", "w").write("cd /D %s\r\nzeronet.py" % os.getcwd())