Unable to uninstall Microsoft apps

Questions about WAPT Packaging / Requests and help regarding Wapt packages.
Forum Rules
Community Forum Rules
* English support on www.reddit.com/r/wapt
* French community support is available on this forum
* Please prefix the topic title with [RESOLVED] if it is resolved.
* Please do not edit a topic that is tagged [RESOLVED]. Open a new topic referencing the old one.
* Specify the installed WAPT version, full version, and build number (2.2.1.11957 / 2.2.2.12337 / etc.) as well as the Enterprise/Discovery edition.
* Versions 1.8.2 and earlier are no longer supported. The only questions accepted regarding version 1.8.2 are related to upgrading to a supported version (2.1, 2.2, etc.).
* Specify the server OS (Linux/Windows) and version (Debian Buster/Bullseye - CentOS 7 - Windows Server 2012/2016/2019).
* Specify the OS of the administration/package creation machine and the machine with the problematic agent, if applicable (Windows 7/10/11/Debian 11/etc.).
* Avoid asking multiple questions when opening a topic, otherwise it may be ignored. If there are multiple topics, open separate topics, preferably one after the other and not all at the same time (i.e., do not spam the forum).
* Include code snippets, screenshots, and other images directly in the post. Links to Pastebin, Bitly, and other third-party sites will be systematically removed.
* As with any community forum, support is provided voluntarily by members. If you require commercial support, you can contact Tranquil IT's sales department at 02.40.97.57.55
Locked
adgm11
Messages: 45
Registration: Apr 12, 2022 - 07:00

August 30, 2022 - 02:10

Good morning
I downloaded the package to uninstall the pre-installed Microsoft applications.
But in the console, a message indicates "unable to remove Microsoft.yourphone" (for example), and this happens for almost all the apps it tries to uninstall
Although the app is properly installed on the machine, the package does not perform the uninstallation.
Here's the package; I've modified it to keep only certain apps

Code: Select all

r"""
Usable WAPT package functions: install(), uninstall(), session_setup(), audit(), update_package()

"""
# Declaring global variables - Warnings: 1) WAPT context is only available in package functions; 2) Global variables are not persistent between calls
apps = [
    ### Windows 10 default apps
    #"Microsoft.3DBuilder",
    #"Microsoft.Print3D",
    #"Microsoft.Microsoft3DViewer",
    #'Microsoft.Appconnector',
    #'Microsoft.MSPaint',
    #'Microsoft.Windows.Photos',
    #'Microsoft.WindowsCalculator',
    #"Microsoft.WindowsCamera",
    #"Microsoft.WindowsMaps",
    #"Microsoft.WindowsSoundRecorder",
    #"Microsoft.WindowsStore",
    "Microsoft.MixedReality.Portal",
    "Microsoft.YourPhone",
    "Microsoft.WindowsFeedbackHub",
    "Microsoft.Windows.Cortana",
    "Microsoft.GetHelp",
    "Microsoft.BingFinance",
    "Microsoft.BingNews",
    "Microsoft.BingSports",
    "Microsoft.BingWeather",
    "Microsoft.FreshPaint",
    "Microsoft.Getstarted",
    "Microsoft.MicrosoftOfficeHub",
    "Microsoft.MicrosoftSolitaireCollection",
    "Microsoft.MicrosoftStickyNotes",
    "Microsoft.Office.OneNote",
    "Microsoft.OneConnect",
    "Microsoft.People",
    "Microsoft.SkypeApp",
    "Microsoft.WindowsAlarms",
    "Microsoft.WindowsPhone",
    "Microsoft.XboxApp",
    "Microsoft.XboxGameOverlay",
    "Microsoft.XboxGameCallableUI",
    "Microsoft.XboxGamingOverlay",
    "Microsoft.XboxIdentityProvider",
    "Microsoft.XboxSpeechToTextOverlay",
    "Microsoft.Xbox.TCUI",
    "Microsoft.ZuneMusic",
    "Microsoft.ZuneVideo",
    "microsoft.windowscommunicationsapps",
    "Microsoft.MinecraftUWP",
    "Microsoft.MixedReality.Portal" "Microsoft.ScreenSketch"
    ### Threshold 2 apps
    "Microsoft.CommsPhone",
    'Microsoft.ConnectivityStore',
    "Microsoft.Messaging",
    'Microsoft.Office.Sway',
    ### Redstone apps
    "Microsoft.BingFoodAndDrink",
    "Microsoft.BingTravel",
    "Microsoft.BingHealthAndFitness",
    "Microsoft.WindowsReadingList",
    ### non-Microsoft
    "9E2F88E3.Twitter",
    "Flipboard.Flipboard",
    "ShazamEntertainmentLtd.Shazam",
    "king.com.*",
    "ClearChannelRadioDigital.iHeartRadio",
    "4DF9E0F8.Netflix",
    "6Wunderkinder.Wunderlist",
    "Drawboard.DrawboardPDF",
    "2FE3CB00.PicsArt-PhotoStudio",
    "D52A8D61.FarmVille2CountryEscape",
    "TuneIn.TuneInRadio",
    "TheNewYorkTimes.NYTCrossword",
    "828B5831.HiddenCityMysteryofShadow",
    "Microsoft.Advertising.Xaml",
    "SpotifyAB.SpotifyMusic",
    ### Apps which cannot be removed using Remove-AppxPackage
    'Microsoft.BioEnrollment',
    "Microsoft.MicrosoftEdge",
    "Microsoft.MicrosoftEdge.Stable",
    "Microsoft.MicrosoftEdgeDevToolsClient",
    "Microsoft.Windows.Cortana",
    "Microsoft.WindowsFeedback",
    "Windows.ContactSupport",
    "Microsoft.Windows.CallingShellApp",
]


def install():
    print("Removing: Unwanted Windows Store applications...")
    for app in apps:
        try:
            print("If needed, removing: %s" % app)
            remove_appx(app)
        except:
            print("Unable to remove: %s" % app)


def session_setup():
    print("Removing: Unwanted Windows Store applications...")
    for app in apps:
        try:
            print("If needed, removing: %s" % app)
            remove_user_appx(app)
        except:
            print("Unable to remove: %s" % app)


def remove_appx(package, default_user=True):
    r"""Uninstall and remove Windows AppX package from the computer in machine environnement

    Args:
        package (str): Package name, asterisk character (*) can be used as joker
        default_user (bool): Remove from image that will be installed for each new users

    .. versionadded:: 2.2

    """
    if running_as_admin() or running_as_system():
        run_powershell('Get-AppxPackage "%s" -AllUsers | Remove-AppxPackage -AllUsers' % package)
        if default_user:
            run_powershell(
                'Get-AppXProvisionedPackage -Online | Where-Object DisplayName -Like "%s" | Remove-AppxProvisionedPackage -Online -AllUsers' % package
            )
    else:
        run_powershell('Get-AppxPackage "%s" | Remove-AppxPackage' % package)


def remove_user_appx(package):
    r"""Uninstall and remove Windows AppX package from the computer in user environnement

    Args:
        package (str): AppX Package name, asterisk character (*) can be used as wildcard

    .. versionadded:: 2.3

    """
    run_powershell('Get-AppxPackage "%s" | Remove-AppxPackage' % package)
User avatar
dcardon
WAPT Expert
Messages: 1929
Registration: June 18, 2014 - 09:58
Location: Saint Sébastien sur Loire
Contact :

August 30, 2022 - 11:26

Wapt version, etc.?
Denis Cardon - Tranquil IT
Share your experiences on WAPT! Send us your blog and article URLs in the "Your Opinion of the forum, and we'll feature them on the WAPT
adgm11
Messages: 45
Registration: Apr 12, 2022 - 07:00

August 30, 2022 - 2:48 PM

wapt 2.2.1
Actually, it's quite random; it seems you have to force the installation for it to remove more apps the second time.
And I'm not sure if this applies to all users already logged in or not, or if a new domain user logs in for the first time on the machine—does all the pre-installed apps revert to their default settings?
Locked