tis-enable-smb1-client 11

  • package : tis-enable-smb1-client
  • version : 11
  • description : Enable SMB1 Client on Windows > Vista
  • maintainer : Hubert TOUVET
  • date : 2018-02-27 18:59:14

setup.py

# -*- 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')



    

Changelog

No changelog
    

manifest.sha256

[["setup.py", "1979e98fd406487a37762cb51ba6dc21079b2cf4711971595fdf6febe87ff384"], ["WAPT/certificate.crt", "79e5388683c0b6cb03f4f81e4e58e3a11463b2b6cf169dd9c453098027dcfaa4"], ["WAPT/wapt.psproj", "795d36d10109ca85357285f79090fac2be856e5830ea31fa913cc55cb825807b"], ["WAPT/control", "75bc706a61e33565103b670f9fd6c164200d32cb216352f2d79ea59e8fc0c367"]]