Guest User

Untitled

a guest
Oct 18th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. import sys
  2. import ctypes
  3.  
  4. user32 = ctypes.windll.user32
  5.  
  6. def getClassName(hwnd):
  7. resultString = ctypes.create_string_buffer("\000" * 32)
  8. user32.GetClassNameA(hwnd, resultString, len(resultString))
  9. return resultString.value
  10.  
  11. def text(hwnd):
  12. length = user32.GetWindowTextLengthA(hwnd)
  13. if length:
  14. buffer = ctypes.create_string_buffer("",length + 1)
  15. if user32.GetWindowTextA(hwnd, buffer, length +1):
  16. return buffer.value
  17.  
  18. def proc(hwnd, user):
  19. if write_file == True:
  20. value = hwnd, text(hwnd), getClassName(hwnd)
  21. fo.write(str(value) + "?n")
  22. else:
  23. #if getClassName(hwnd) == "Chrome_WidgetWin_1": #search by WindowsClass name
  24. if text(hwnd) != None and text(hwnd)[-8:] == "- Chrome": #search by titlebar text
  25. print hwnd, type(text(hwnd)), text(hwnd), getClassName(hwnd)
  26. user32.SetWindowTextA(hwnd,ctypes.c_char_p("hoeg")) #change titlebar text
  27. return 1
  28.  
  29. def run():
  30. WNDENUMPROC = ctypes.WINFUNCTYPE(ctypes.c_int, ctypes.c_void_p, ctypes.c_long)
  31. user32.EnumWindows(WNDENUMPROC(proc), 0)
  32. return 1
  33.  
  34. if __name__ == '__main__':
  35. if len(sys.argv) == 2:
  36. write_file = True
  37. fo = file(sys.argv[1]+".txt", "w")
  38. run()
  39. fo.close()
  40. else:
  41. write_file = False
  42. run()
Add Comment
Please, Sign In to add comment