Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sys
- import ctypes
- user32 = ctypes.windll.user32
- def getClassName(hwnd):
- resultString = ctypes.create_string_buffer("\000" * 32)
- user32.GetClassNameA(hwnd, resultString, len(resultString))
- return resultString.value
- def text(hwnd):
- length = user32.GetWindowTextLengthA(hwnd)
- if length:
- buffer = ctypes.create_string_buffer("",length + 1)
- if user32.GetWindowTextA(hwnd, buffer, length +1):
- return buffer.value
- def proc(hwnd, user):
- if write_file == True:
- value = hwnd, text(hwnd), getClassName(hwnd)
- fo.write(str(value) + "?n")
- else:
- #if getClassName(hwnd) == "Chrome_WidgetWin_1": #search by WindowsClass name
- if text(hwnd) != None and text(hwnd)[-8:] == "- Chrome": #search by titlebar text
- print hwnd, type(text(hwnd)), text(hwnd), getClassName(hwnd)
- user32.SetWindowTextA(hwnd,ctypes.c_char_p("hoeg")) #change titlebar text
- return 1
- def run():
- WNDENUMPROC = ctypes.WINFUNCTYPE(ctypes.c_int, ctypes.c_void_p, ctypes.c_long)
- user32.EnumWindows(WNDENUMPROC(proc), 0)
- return 1
- if __name__ == '__main__':
- if len(sys.argv) == 2:
- write_file = True
- fo = file(sys.argv[1]+".txt", "w")
- run()
- fo.close()
- else:
- write_file = False
- run()
Add Comment
Please, Sign In to add comment