📜 ⬆️ ⬇️

Script to delete universal Windows Store apps

The time has come to lay out the next script for the system administrators from the bins. Blanks for working with service packs and system components were laid out in previous articles. Today I will share a ready-made solution that can be applied in work without any modifications. As you know, Microsoft decided to follow the example of Google and opened its application market, called Windows Store . Starting from Windows 8, new-type applications (distribution file format - AppX ) have appeared in OS distributions, which are universal and should run on all Windows devices. I didn’t find anything useful among the pre-installed universal applications, so I wrote a script that removes them all.

The solution presented here is intended for servicing Windows 8, 8.1, 10 images. It can be applied both to standalone image files in * .wim format and to an deployed (installed) system. As in my previous scripts, I use DISM system tools. However, during the development it turned out that using the dism command, it is not possible to remove universal applications from the installed system (online service) - only using PowerShell . I had to make a choice: either to write the script completely on PS, or use the capabilities of the command interpreter (CMD), to make a call for individual operations from PS. I chose the second option, in this connection, the presented solution consists of two files: the main script (save with any name * .cmd ) and the additional (save with the name RemoveAppxes.ps1 ).

Main script


@echo off title Deleting Appxes in Windows image set _file=install.wim set _img=Online set _mnt=mount dism /English /LogLevel:1 /Get-Help | find "Version: 6.1" > nul && exit :pre_menu cls if not exist %_file% goto :version dism /English /LogLevel:1 /Get-ImageInfo /ImageFile:%_file% echo ------------------------------------------------------------------------------- if %ERRORLEVEL% NEQ 0 pause & exit set /p _ind=Input index or press [Enter] for quit: || exit if %_ind% EQU 0 goto :version if %_ind% GTR 0 if %_ind% LEQ 24 goto :ind_menu goto :pre_menu :ind_menu cls dism /English /LogLevel:1 /Get-ImageInfo /ImageFile:%_file% /Index:%_ind% echo ------------------------------------------------------------------------------- if %ERRORLEVEL% NEQ 0 pause & goto :pre_menu choice /c abcdefghijklmnopqrstuvwxyz /n /m "Mount selected image? [m] " if %ERRORLEVEL% EQU 13 goto :mount goto :pre_menu :version dism /%_img% /English /LogLevel:1 /Get-Help | find "Image Version: 6.1" > nul && goto :unmount goto :remove :remove cls echo Getting list of Appxes. Please wait... dism /%_img% /English /LogLevel:1 /Get-ProvisionedAppxPackages > %TEMP%\appxes.txt echo ------------------------------------------------------------------------------- set _num=1 for /f "skip=8 tokens=3" %%a in (%TEMP%\appxes.txt) do call :filter %%a del %TEMP%\appxes.txt echo Removes default application associations dism /%_img% /English /LogLevel:1 /Remove-DefaultAppAssociations echo ------------------------------------------------------------------------------- if %_img%==Online ( echo Remove current Appxes for AllUsers powershell -Command Start-Process powershell -ArgumentList '-NoProfile -WindowStyle Hidden -ExecutionPolicy Bypass -File RemoveAppxes.ps1' -Verb RunAs ) if not exist %_file% exit goto :unmount :filter echo %1 | findstr /ric:"Microsoft.*" > nul if %ERRORLEVEL% EQU 0 call :action %1 exit /b :action echo %1 | findstr /ric:"Microsoft.*_" > nul if %ERRORLEVEL% NEQ 0 ( set /a _num+=1 echo %_num% Remove: %1 ) else ( dism /%_img% /English /LogLevel:1 /Remove-ProvisionedAppxPackage /PackageName:%1 echo ------------------------------------------------------------------------------- ) exit /b :mount cls md %_mnt% dism /English /LogLevel:1 /Mount-Image /ImageFile:%_file% /Index:%_ind% /MountDir:%_mnt% if %ERRORLEVEL% NEQ 0 rd %_mnt% & pause & exit set _img=Image:%_mnt% goto :version :unmount cls if not %_img%==Online ( dism /English /LogLevel:1 /Unmount-Image /MountDir:%_mnt% /Commit rd %_mnt% ) set _img=Online goto :pre_menu 

Additional script


 Get-AppxPackage -AllUsers | Remove-AppxPackage 

Using


Two files should be located in the same folder. If there is no image file in the launch folder - install.wim , then the scripts perform the work in fully automatic mode. If there is an install file in the startup folder, install.wim , then the script reads information about it from the existing "indexes" and offers to enter a number. After that, extended information about the selected "index" is displayed, a request for mounting is issued. Pressing any key leads to a return, and pressing the [m] key launches the following chain of actions: mounting the image, checking the OS version, deleting the application distributions (by loop), deleting all associations, uninstalling installed applications (when starting online), unmounting the image, returning in the "index" selection menu. After that, you can select another "index" of the image to remove applications. Selecting “index” at number 0 starts the online service.

Parsing code


At first, the set command sets the variables. You can change the estimated name of the install.wim image file (for example, to install.esd ). You can change the name of the mount folder (by default, mount ) or set the path if the mount folder should be outside of the launch folder.

: pre_menu


Preliminary menu. Getting basic information about a wim file with error checking. If there is no image file, then run in online mode.

: ind_menu


Index menu. Get extended information about the selected "index" in a wim file with error control. Offer to mount the "index".

: version


Check the version of the target system. If it turns out that the script is trying to apply to the image of Windows 7, then unmount occurs. Otherwise, it moves to the next label.
')

: remove (: filter,: action)


The main unit of the script. First, a list of integrated universal applications is requested with saving to the temporary file appxes.txt . Then, in the for loop, the rows are sequentially selected from the resulting list and passed to the pseudo-function : filter . Strings are filtered by the regular expression “Microsoft. *” - if it is found, then they are passed to the following pseudo-function : action . Here, the regular expression "Microsoft. * _" Filters the names of universal applications, which are then passed to the dism utility for deletion. To better understand the logic of the work you need to look at the contents of the file appxes.txt . Since the file is deleted upon completion of the cycle, then in order to familiarize yourself with it, you must first manually receive it and save it.

One command deletes all associations for opening individual files by universal applications. For common file types, associations with standard classic Windows applications remain.

Removal (uninstallation) of universal applications on the installed system occurs by calling the compound command in the PowerShell scripting language. The file of additional script RemoveAppxes.ps1 first performs a request for a list of all universal applications for all users, and then “by pipeline” sends them to the command for deletion. It seems to be nothing complicated, however, to perform this operation, the PS script must be run with elevated permissions, and working on behalf of the Administrator is not enough. For a successful launch, you need to insert that complex code in the powershell command in order to get elevation rights. Protection that is easy to manage! It is for this “idiocy” that I didn’t like PowerShell.

: mount


Mounting image Pre-created mount folder. Error control. The variable defining the specification of the image changes, now points to the path to the autonomous image.

: unmount


Unmounting an image. If online maintenance was performed (/ Online), then it is not necessary to unmount it. Return of variables to initial values.

Conclusion


I showed a simple and fast way to uninstall Windows Store apps. I believe that the same application can not be equally convenient for use on a mobile device and on a PC. First of all, the named platforms have different functional purposes, and therefore the applications required by users must provide different functionalities. After the script has been worked out, several universal applications still remain, first of all, it is the Windows Store itself, with which you can install what has been removed or something else.

Source: https://habr.com/ru/post/347558/


All Articles