tis-disable-cortana 3

  • package : tis-disable-cortana
  • version : 3
  • architecture : all
  • locale :
  • description : Disable and uninstall Cortana on Windows10
  • maintainer : TIS <technique@tranquil-it-systems.fr>
  • date : 2018-02-27 18:58:39
  • min_wapt_version :
  • min_os_version : 6.2.0
  • max_os_version :
  • impacted_process :

setup.py

# -*- coding: utf-8 -*-
from setuphelpers import *
import subprocess
import json

uninstallkey = []

def run_powershell(cmd,output_format='json',**kwargs):
    """Run a command/script (possibly multiline) using powershell, return output in text format
        If format is 'json', the result is piped to ConvertTo-Json and converted back to a python dict for convenient use
    """
    cmd = ensure_unicode(cmd)
    if output_format == 'json':
        output_format_ps = 'text'
        cmd = '(%s) | ConvertTo-Json' % cmd
    else:
        output_format_ps = output_format
    # command is a utf16 without bom encoded with base54 without \n
    # we should not get stderr so that ouput can be decoded as json. stderr get progress report...
    if not 'return_stderr' in kwargs or not isinstance(return_stderr,list):
        return_stderr = []
    else:
        kwargs.pop('return_stderr')
    try:
        with disable_file_system_redirection():
            result = ensure_unicode(subprocess.check_output(u'powershell -ExecutionPolicy Unrestricted -OutputFormat %s -encodedCommand %s' %
                    (output_format_ps,
                     cmd.encode('utf-16le').encode('base64').replace('\n','')),
                    **kwargs))
    except subprocess.CalledProcessError as e:
        raise subprocess.CalledProcessError(e.returncode,cmd,e.output)

    #remove comments...
    if output_format.lower() == 'xml':
        lines = [l for l in result.splitlines() if not l.strip().startswith('#')]
        import xml.etree.ElementTree as ET
        return ET.fromstringlist(lines)
    elif output_format.lower() == 'json':
        import json
        if not result:
            return None
        else:
            try:
                ### there are  ''[ and ]'' around.
                return json.loads(result)
            except ValueError as e:
                raise ValueError(u'%s returned non json data:\n%s' % (cmd,result))
    else:
        return result




def install():
    registry_set(HKEY_LOCAL_MACHINE, r'SOFTWARE\Policies\Microsoft\Windows\Windows Search', r'AllowCortana', 0, REG_DWORD)
    run_powershell('Get-AppxPackage -Name Microsoft.Windows.Cortana -AllUsers | Remove-AppxPackage')

def uninstall():
    registry_set(HKEY_LOCAL_MACHINE, r'SOFTWARE\Policies\Microsoft\Windows\Windows Search', r'AllowCortana', 1, REG_DWORD)
    run_powershell('Get-AppxPackage -Name Microsoft.Windows.Cortana -AllUsers | Foreach {Add-AppxPackage -DisableDevelopmentMode -Register "$($_.InstallLocation)\AppXManifest.xml"}')

    

Changelog

No changelog
    

manifest.sha256

setup.py 4be57fae5805d682a467b6ee191fcd0b4f028a71823e87448300735687671c15
WAPT/certificate.crt 79e5388683c0b6cb03f4f81e4e58e3a11463b2b6cf169dd9c453098027dcfaa4
WAPT/wapt.psproj df0b280a4dff05ccc3b6185cf1dd39ac9a0aeca883450cc1836a4004baee2567
WAPT/control c4e3c0dc2ad2ad8c0f8c51d2c6475d3502c52d56ab4db0436372dd7160d39bee