Advertisement
Guest User

Untitled

a guest
May 28th, 2017
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.80 KB | None | 0 0
  1. class Deploy(Thread):
  2.  
  3. def __init__(self, ip, wpkgdir):
  4. Thread.__init__(self)
  5. self.ip = ip
  6. self.wpkgdir = wpkgdir
  7. def run(self):
  8. import traceback
  9. #import win32api
  10. #import win32security
  11. #import win32con
  12. import _winreg
  13.  
  14. from time import strftime
  15. fp=open("logs/" + self.ip + ".txt","a")
  16.  
  17. try:
  18. saveddic={"Common Desktop":"","Common Programs":"","Common Start Menu":"","Common Startup":""}
  19. resetkey_dic={"Common Desktop":u"C:\Documents and Settings\All Users\Bureau","Common Programs":u"C:\Documents and Settings\All Users\Menu Démarrer\Programmes","Common Start Menu":u"C:\Documents and Settings\All Users\Menu Démarrer","Common Startup":u"C:\Documents and Settings\All Users\Menu Démarrer\Programmes\Démarrage"}
  20. KEY_PATH = r"Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders"
  21. HKCU_remote = _winreg.ConnectRegistry (r"\\" + self.ip,_winreg.HKEY_LOCAL_MACHINE)
  22. hKeyRemote = _winreg.OpenKey (HKCU_remote, KEY_PATH, 0, _winreg.KEY_READ)
  23. for cle in saveddic:
  24. value, type = _winreg.QueryValueEx (hKeyRemote, cle)
  25. saveddic[cle] = value
  26. #print cle, value
  27. _winreg.CloseKey(hKeyRemote)
  28.  
  29. for cle in resetkey_dic:
  30. hKeyRemote = _winreg.OpenKey (HKCU_remote, KEY_PATH, 0, _winreg.KEY_SET_VALUE)
  31. _winreg.SetValueEx (hKeyRemote, cle,"",_winreg.REG_EXPAND_SZ,resetkey_dic[cle])
  32. _winreg.CloseKey(hKeyRemote)
  33. except:
  34. traceback.print_exc(file=fp)
  35. fp.write('User Shell Folders pb \n')
  36. try:
  37. pythoncom.CoInitialize()
  38. c = wmi.WMI(self.ip)
  39. try:
  40. wql = "select * from Win32_Product"
  41. for app in c.query(wql):
  42. print app.Name
  43. if app.Name == "WPKG":
  44. print "wpkg trouve"
  45. print app.Uninstall()
  46. except:
  47. fp.write('uninstall pb \n')
  48. c.Win32_Product.Install (PackageLocation=self.wpkgdir + '\\WPKG_Client.msi', Options='SETTINGSFILE=' + self.wpkgdir + '\\settings.xml', AllUsers=True)
  49. fp.write('install ' + self.ip + '\n')
  50. except:
  51. fp.write('error ' + self.ip + '\n')
  52. traceback.print_exc(file=fp)
  53. finally:
  54. for cle in saveddic:
  55. hKeyRemote = _winreg.OpenKey (HKCU_remote, KEY_PATH, 0, _winreg.KEY_SET_VALUE)
  56. _winreg.SetValueEx (hKeyRemote, cle,"",_winreg.REG_EXPAND_SZ,saveddic[cle])
  57. _winreg.CloseKey(hKeyRemote)
  58. fp.close()
  59. pythoncom.CoUninitialize()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement