Works fine woho!. Code: C:\windows\system32>echo en-us en-us C:\windows\system32>echo sv-se sv-se C:\windows\system32>echo zh-tw zh-tw But the code to remove language still doesnt work.. Code: @echo off setlocal enabledelayedexpansion for /f "tokens=2 delims==" %%A in ('wmic os get oslanguage /format:list') do ( call :dec2hex %%A ) for /f %%A in ('reg query "HKLM\SYSTEM\CurrentControlSet\Control\MUI\UILanguages"') do ( for /f "tokens=3" %%a in ('reg query "%%A" /v LCID') do ( if %%a==%lcid% ( for /f "tokens=7 delims=\" %%b in ("%%A") do ( set locale=%%b ) ) ) ) for /f "tokens=2,* delims=:" %%A in ('"dism /Online /Get-Packages|find "LanguagePack""') do ( for /f "tokens=4 delims=~" %%a in ("%%A") do ( if NOT %locale%==%%a ( set /p confirm=Do you want to remove %%a? if /i %confirm%==y ( set pkg=%%A set pkg=!pkg: =! dism /online /Remove-Package /PackageName:!pkg! ) ELSE ( echo %%a will not be removed ) ) ) ) pause exit :dec2hex setlocal enabledelayedexpansion set /a num=%1 set digits=0123456789ABCDEF set ans= :loop set /a rmd=%num% %% 16 set /a num /= 16 set ans=!digits:~%rmd%,1!%ans% if NOT %num%==0 goto loop endlocal & set lcid=0x%ans% exit /b Still "unexpected (".
If all the outputs are correct then the script ought to work as expected. It works if the default language is English but it does not if it is another language. I'll test it out and see why you get expected ) error.
Great Ill try change to en-US and see if it works. I made a small edit, I get "unexpected (" if im not mistaken now. it flashes real quick
This will work Code: @echo off setlocal enabledelayedexpansion for /f "tokens=2 delims==" %%A in ('wmic os get oslanguage /format:list') do ( call :dec2hex %%A ) for /f %%A in ('reg query "HKLM\SYSTEM\CurrentControlSet\Control\MUI\UILanguages"') do ( for /f "tokens=3" %%a in ('reg query "%%A" /v LCID') do ( if /i %%a==%lcid% ( for /f "tokens=7 delims=\" %%b in ("%%A") do ( set locale=%%b ) ) ) ) echo Your current language is %locale% for /f "tokens=2,* delims=:" %%A in ('"dism /Online /Get-Packages|find "LanguagePack""') do ( for /f "tokens=4 delims=~" %%a in ("%%A") do ( if NOT %locale%==%%a ( set /p confirm=Do you want to remove %%a? if /i !confirm!==y ( set pkg=%%A set pkg=!pkg: =! dism /online /Remove-Package /PackageName:!pkg! ) ELSE ( echo %%a will not be removed ) ) ) ) pause exit :dec2hex setlocal enabledelayedexpansion set /a num=%1 set digits=0123456789ABCDEF set ans= :loop set /a rmd=%num% %% 16 set /a num /= 16 set ans=!digits:~%rmd%,1!%ans% if NOT %num%==0 goto loop endlocal & set lcid=0x%ans% exit /b Condition checking was case sensitive in the previos code, 0x41D was not equal to 0x41d so the locale variable was not set which in turn led to an incomplete IF statement.
Will try it asap and report back! Edit: Now working fine with asking to remove languages and also removing them Although it says my current language is sv-SE but i switched to en-US hehe. Edit2: Ok it is swedish, 7 ultimate didnt feel like actually changing language......
Good to hear, that it worked as expected. The script seems to be a good example for nested for and conditional execution.
Oyea it did work as expected! I know its possible but how to make it list the languages installed and ask me which one to remove? Annoying? lol.
You should have tried it yourself, but here's the solution. Code: @echo off setlocal enabledelayedexpansion for /f "tokens=2 delims==" %%A in ('wmic os get oslanguage /format:list') do ( call :dec2hex %%A ) for /f %%A in ('reg query "HKLM\SYSTEM\CurrentControlSet\Control\MUI\UILanguages"') do ( for /f "tokens=3" %%a in ('reg query "%%A" /v LCID') do ( if /i %%a==%lcid% ( for /f "tokens=7 delims=\" %%b in ("%%A") do ( set locale=%%b ) ) ) ) :menu cls echo Your current language is %locale% echo. echo The following languages can be removed from Windows echo. set /a i=1 for /f "tokens=2,* delims=:" %%A in ('"dism /Online /Get-Packages|find "LanguagePack""') do ( for /f "tokens=4 delims=~" %%a in ("%%A") do ( if NOT %locale%==%%a ( echo. !i!. %%a set var[!i!]=%%A set /a i+= 1 ) ) ) if %i% EQU 1 ( echo No additional language packs found echo Press any key to exit pause>NUL exit ) echo. X. Exit echo. if %i% GTR 2 ( set /a i = %i%-1 set /p choose=Select the language? [1-!i!,X] ) ELSE set /p choose=Select the language? [1,X] if /i %choose%==x exit if %choose% GTR !i! ( echo Invalid choice goto menu ) set pkg=!var[%choose%]! set pkg=!pkg: =! dism /online /Remove-Package /PackageName:!pkg! pause goto menu :dec2hex setlocal enabledelayedexpansion set /a num=%1 set digits=0123456789ABCDEF set ans= :loop set /a rmd=%num% %% 16 set /a num /= 16 set ans=!digits:~%rmd%,1!%ans% if NOT %num%==0 goto loop endlocal & set lcid=0x%ans% exit /b
Nice script! Is there a way to get it work so that the all extra packages would be removed by one dism command? like: dism /online /Remove-Package /PackageName:A /PackageName:B /PackageName:C