77 lines
3.8 KiB
Python
77 lines
3.8 KiB
Python
# -*- coding: utf-8 -*-
|
|
from setuphelpers import *
|
|
import platform
|
|
|
|
uninstallkey = []
|
|
|
|
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 = []
|
|
if windows_version() == Version('10.0'):
|
|
print('enable smb1protocol')
|
|
result = run_powershell('Enable-WindowsOptionalFeature -Online -FeatureName smb1protocol -NoRestart')
|
|
if result.get('RestartNeeded',False):
|
|
restart_needed_by.append('Enable Windows 10 optional feature smb1protocol')
|
|
elif windows_version() == Version('6.2'):
|
|
print('add SMB1-FS')
|
|
result = run_powershell('Add-WindowsFeature -Name SMB1-FS -NoRestart')
|
|
if result.get('RestartNeeded',False):
|
|
restart_needed_by.append('Enable windows 12 feature smb1protocol')
|
|
elif (service_installed('mrxsmb10') and not service_is_running('mrxsmb10')):
|
|
print('Enable SMB1 client')
|
|
# see https://support.microsoft.com/fr-fr/help/2696547/how-to-enable-and-disable-smbv1,-smbv2,-and-smbv3-in-windows-vista,-windows-server-2008,-windows-7,-windows-server-2008-r2,-windows-8,-and-windows-server-2012
|
|
run('sc.exe config lanmanworkstation depend= bowser/mrxsmb10/mrxsmb20/nsi')
|
|
run('sc.exe config mrxsmb10 start= auto')
|
|
try:
|
|
to_restart = []
|
|
svcdepends = run('sc enumdepend lanmanworkstation').splitlines()
|
|
# ['SessionEnv', 'Netlogon', 'Browser']
|
|
depends = [s.split(': ')[1] for s in svcdepends if s.startswith('SERVICE_NAME: ')]
|
|
for svc in depends:
|
|
if service_is_running(svc):
|
|
print('Stopping %s'%svc)
|
|
service_stop(svc)
|
|
to_restart.append(svc)
|
|
print('Restarting lanmanworkstation...')
|
|
if service_is_running('lanmanworkstation'):
|
|
service_restart('lanmanworkstation')
|
|
else:
|
|
service_start('lanmanworkstation')
|
|
print('Done.')
|
|
|
|
print('lanmanworkstation redemarre avec SMB1')
|
|
except Exception as e:
|
|
print('Error trying to stop depends or start lanmanworkstation: %s' % repr(e))
|
|
restart_needed_by.append('Enable SMB1 client service')
|
|
if not service_is_running('lanmanworkstation'):
|
|
service_start('lanmanworkstation')
|
|
finally:
|
|
for svc in to_restart:
|
|
if not service_is_running(svc):
|
|
print('Starting %s'%svc)
|
|
service_start(svc)
|
|
else:
|
|
print('OK: SMB1 client running or not installed or windows system not supported (version %s)' % windows_version())
|
|
|
|
#restart_needed_by.extend(pending_reboot_reasons())
|
|
if (service_installed('mrxsmb10') and not service_is_running('mrxsmb10')) or restart_needed_by:
|
|
with disable_file_system_redirection():
|
|
run_notfatal('msg * /time:360 Merci de redemarrer votre ordinateur pour terminer la l''activation du service client SMB1. Tranquil IT Systems.')
|
|
error('Redemarrage necessaire pour : %s ' % restart_needed_by)
|
|
else:
|
|
print('No reboot required')
|
|
|
|
|