Guest User

Untitled

a guest
Feb 24th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.57 KB | None | 0 0
  1. import win32gui, time, SendKeys, re, win32clipboard, win32con, string, win32com.client
  2. def WinEnumHandler(hwnd, resultList):
  3. resultList.append((hwnd, win32gui.GetWindowText(hwnd)))
  4.  
  5. topWindows = [] #--> array to store all (hwnd, name) values of all top-windows
  6. win32gui.EnumWindows(WinEnumHandler, topWindows)
  7. #--> will put all (hwnd, name) values of top-windows into topWindows array.
  8. # Find desired window based on <string> within it's name.
  9. count = 0
  10. stuff = ""
  11. for row in topWindows:
  12. x = re.search('Account Window Title', row[1], 2)
  13. if x:
  14. myWindow = [row[0],row[1],win32gui.GetClassName(row[0])]
  15. count = count + 1
  16. stuff = stuff + myWindow[1]
  17. #print myWindow[1]
  18. elif x == False:
  19. print "It appears you do not have admin page loaded in a webbrowser."
  20. break
  21. #print count
  22.  
  23. #print stuff
  24. if count >= 2:
  25. c = input("Which browser do you want me to use? Type 1 for Firefox, 2 for IE: ")
  26.  
  27. if c == 1:
  28. x = win32gui.FindWindow(None, "Certificate Management Center - Mozilla Firefox") #get hwnd given the window title
  29. win32gui.SetForegroundWindow(x) #bring the window with x hwnd to the front
  30. SendKeys.SendKeys('^{u}') #view page source in firefox
  31. #time.sleep(1)
  32. SendKeys.SendKeys('{TAB}')
  33. SendKeys.SendKeys('^{a}') #select all
  34. time.sleep(1)
  35. SendKeys.SendKeys('^{c}') #copy
  36. SendKeys.SendKeys('^{w}') #close page source window
  37.  
  38. else:
  39. x = win32gui.FindWindow(None, "Certificate Management Center - Microsoft Internet Explorer")
  40. win32gui.SetForegroundWindow(x) #bring the window with x hwnd to the front
  41. s = win32gui.GetForegroundWindow()
  42. while x == s:
  43. SendKeys.SendKeys('%v')
  44. time.sleep(.5)
  45. SendKeys.SendKeys('c')
  46. time.sleep(.5)
  47. s = win32gui.GetForegroundWindow()
  48. SendKeys.SendKeys('^{a}') #select all
  49. SendKeys.SendKeys('^{c}') #copy
  50. SendKeys.SendKeys('%{F4}') #MAKE SURE THE SOURCE WINDOW IS CURRENTLY ON TOP
  51.  
  52. elif re.search('.*Firefox.*', stuff):
  53. #print "Firefox"
  54. x = win32gui.FindWindow(None, "Certificate Management Center - Mozilla Firefox") #get hwnd given the window title
  55. j = win32gui.FindWindow(None, "view-source: - Source of: domain.com - Mozilla Firefox")
  56. win32gui.SetForegroundWindow(x) #bring the window with x hwnd to the front
  57. SendKeys.SendKeys('^{u}') #view page source in firefox
  58. #time.sleep(1)
  59. for p in range(5):
  60. if j != 0:
  61. break
  62. else:
  63. time.sleep(.5)
  64. j = win32gui.FindWindow(None, "view-source: - Source of: domain.com- Mozilla Firefox")
  65. SendKeys.SendKeys('{TAB}')
  66. SendKeys.SendKeys('^{a}') #select all
  67. time.sleep(1)
  68. SendKeys.SendKeys('^{c}') #copy
  69. SendKeys.SendKeys('^{w}') #close page source window
  70. elif re.search('.*Internet Explorer.*', stuff):
  71. #print "Internet Explorer"
  72. x = win32gui.FindWindow(None, "Certificate Management Center - Microsoft Internet Explorer")
  73. win32gui.SetForegroundWindow(x) #bring the window with x hwnd to the front
  74. s = win32gui.GetForegroundWindow()
  75. while x == s:
  76. SendKeys.SendKeys('%v')
  77. time.sleep(.5)
  78. SendKeys.SendKeys('c')
  79. time.sleep(.5)
  80. s = win32gui.GetForegroundWindow()
  81. SendKeys.SendKeys('^{a}') #select all
  82. SendKeys.SendKeys('^{c}') #copy
  83. SendKeys.SendKeys('%{F4}') #MAKE SURE THE SOURCE WINDOW IS CURRENTLY ON TOP
  84. win32clipboard.OpenClipboard(0)
  85. junk = win32clipboard.GetClipboardData(win32con.CF_TEXT)
  86. win32clipboard.EmptyClipboard()
  87. win32clipboard.CloseClipboard() #IMPORTANT must close before using again (?)
  88. ####### find and replace extra spaces, Jr/Sr/Mr/Mrs/Ms, I/II/III/etc, "," "."
  89. acct = re.findall('\d{8,}-\d+', junk)
  90. fullx = re.findall('\>NAME\s.+\n.+(?P<name>\;[a-zA-Z -.]+)', junk)
  91. #print fullx[0]
  92. full = re.sub('[;.,]', '', fullx[0])
  93. full = re.compile('[mjs]r', flags=2).sub('', full) #how to ignore case
  94. #full = re.sub('\W+I{2,}', '', full) #get rid of I, II, III
  95. full = re.sub('(\W+I{2,})|(\W+IV)', '', full)
  96. full = string.rstrip(string.lstrip(full))
  97. #full = full.title() # only do title on names w/ all caps or no caps
  98. if full.islower() | full.isupper():
  99. full = full.title()
  100. #emailx = re.findall('E-MAIL.+\n.+(?P<mail>\;.+@.+\.\w{2,})', junk)
  101. emailx = re.findall(';.+@.+\.\w{2,}', junk)
  102. email = re.sub('\;', '', emailx[0])
  103.  
  104. phone = re.findall('\d{3}\W\d{3}\W\d{4}', junk)
  105.  
  106. n = full.split(' ')
  107. last = n[-1]
  108. login = full[0]+n[-1]+'-'+acct[0]
  109. win32clipboard.OpenClipboard(0)
  110. win32clipboard.SetClipboardText(acct[0])
  111.  
  112. for row in topWindows:
  113. y = re.search('Remedy', row[1], 2)
  114. if y:
  115. myWindow = [row[0],row[1],win32gui.GetClassName(row[0])]
  116. y = win32gui.FindWindow(None, myWindow[1]) #get hwnd of Remedy
  117. win32gui.SetForegroundWindow(y) #bring Remedy window to front
  118. ar = win32com.client.Dispatch("Remedy.User")
  119. x = ar.OpenForm(0, 'domain.com', 'HPD:HelpDesk', 1, 1)
  120. x.GetField('Account #').Value = acct[0]
  121. x.GiveFieldFocus('Status')
  122. SendKeys.SendKeys('r')
  123. x.GiveFieldFocus('Account #')
  124. SendKeys.SendKeys('{ENTER}') #search off acct num
  125. #if nothing found off acct num, look for error window
  126. time.sleep(1)
  127. e = win32gui.FindWindow(None, "Remedy User - Error")
  128. time.sleep(.25)
  129. if e > 0:
  130. SendKeys.SendKeys('{ENTER}') #close error window
  131. #x.GetField('Account #').Value = '' #clear out the acct num field
  132. p = ar.OpenForm(0, 'domain.com', 'SHR:People', 1, 1) #to create new profile
  133. p.GetField('Login Name').Value = login
  134. p.GetField('Account #').Value = acct[0]
  135. p.GetField('Last Name').Value = last
  136. p.GetField('First Name').Value = n[0]
  137. p.GetField('Full Name').Value = full
  138. p.GetField('Email').Value = email
  139. p.GetField('Phone').Value = phone[0]
  140. x.GiveFieldFocus('Account #')
  141. #user should review profile data before saving
  142. win32clipboard.EmptyClipboard()
  143. win32clipboard.CloseClipboard()
  144. print e
  145. print login
  146. print acct[0]
  147. print full
  148. print email
  149. print phone[0]
Add Comment
Please, Sign In to add comment