# -*- coding: utf-8 -*-
from setuphelpers import *
import platform
uninstallkey = []
#error with wusa.exe number 2359302 means KB already install
def is_kb_installed(hotfixid):
installed_update = installed_windows_updates()
if [kb for kb in installed_update if kb['HotFixID' ].upper() == hotfixid.upper()]:
return True
return False
def pending_reboot_reasons():
result = []
reboot_required = registry_readstring(HKEY_LOCAL_MACHINE,r'SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update','RebootRequired',0)
if reboot_required:
result.append('Windows Update: %s' % reboot_required)
reboot_pending = registry_readstring(HKEY_LOCAL_MACHINE,r'SOFTWARE\Microsoft\Windows\CurrentVersion\Component Based Servicing','RebootPending',0)
if reboot_pending:
result.append('CBS Updates: %s' % reboot_pending)
renames_pending = registry_readstring(HKEY_LOCAL_MACHINE,r'SYSTEM\CurrentControlSet\Control\Session Manager','PendingFileRenameOperations',None)
if renames_pending:
result.append('File renames: %s' % renames_pending)
return result
def install():
restart_needed_by = []
#For Wapt Windows Update, we have to enable WUAU service
with EnsureWUAUServRunning():
if windows_version() < Version('6.0'):
# http://www.catalog.update.microsoft.com/search.aspx?q=4012598
#XP and 2003
if not is_kb_installed('kb4500331'):
if platform.win32_ver()[0]=='XP':
product = registry_readstring(HKEY_LOCAL_MACHINE,r'SYSTEM\CurrentControlSet\Control\ProductOptions\ProductSuite',None)
if product == 'EmbeddedNT':
print('installing patch for RDP for Windows XP Embedded')
install_exe_if_needed("windowsxp-kb4500331-x86-embedded-fra_36439fc4347a9f45119e200cb3a6536bdc90532b.exe",'/quiet /norestart',key='',min_version='1')
else:
print('installing patch for RDP for winxp')
install_exe_if_needed("windowsxp-kb4500331-x86-custom-fra_39cefedfb0a2a989dcca10c15b8d1f1f770d0768.exe",'/quiet /norestart',key='',min_version='1')
elif platform.win32_ver()[0]=='2003Server':
print('installing patch for RDP for win2k3')
if iswin64():
install_exe_if_needed('windowsserver2003-kb4500331-x64-custom-fra_a5afaa0326ba67d3660b832959f73706e2123b68.exe','/quiet /norestart',key='',min_version='1')
else:
install_exe_if_needed("windowsserver2003-kb4500331-x86-custom-fra_49bda7303bdfaf98f81d5440c7875ef19b7c0777.exe",'/quiet /norestart',key='',min_version='1')
else:
print('kb4500331 already installed')
elif windows_version() < Version('6.1'):
# 2008 and vista
if not is_kb_installed('kb4500331'):
print('installing patch for RDP for 2008 server')
if iswin64():
run('wusa.exe "windows6.0-kb4499180-x64_3d7a9cec11c06caf7a280745eccfa99c2048c4d2.msu" /quiet /norestart',accept_returncodes=[0,3010,2359302,-2145124329],timeout=3600)
else:
run('wusa.exe "windows6.0-kb4499180-x86_058da885ced3478b996f12d1fc40640c3796bdf3.msu" /quiet /norestart',accept_returncodes=[0,3010,2359302,-2145124329],timeout=3600)
else:
print('kb4500331 already installed')
elif windows_version() < Version('6.2'):
# 7 and 2008R2
if not is_kb_installed('kb4500331'):
print('installing patch for RDP for 2008R2 server and 7')
if iswin64():
run('wusa.exe "windows6.1-kb4499175-x64_3704acfff45ddf163d8049683d5a3b75e49b58cb.msu" /quiet /norestart',accept_returncodes=[0,3010,2359302,-2145124329],timeout=3600)
else:
run('wusa.exe "windows6.1-kb4499175-x86_6f1319c32d5bc4caf2058ae8ff40789ab10bf41b.msu" /quiet /norestart',accept_returncodes=[0,3010,2359302,-2145124329],timeout=3600)
else:
print('kb4500331 already installed')
else:
print ("this package is for winxp, win2k3, 2008(R2) and 7 only")
restart_needed_by.extend(pending_reboot_reasons())
if restart_needed_by:
with disable_file_system_redirection():
run_notfatal('msg * /time:360 Merci de redemarrer votre ordinateur pour terminer les mises a jour. Tranquil IT Systems.')
error('Redemarrage necessaire pour : %s ' % restart_needed_by)
else:
print('No reboot required')