[Batch] Remove language batch?

Discussion in 'Scripting' started by tcntad, Oct 20, 2010.

  1. tcntad

    tcntad MDL Guru

    Oct 26, 2009
    4,488
    1,506
    150
    I think this would be the right place to ask..

    I have Windows 7 AIO with 3 languages but im only using English.. So after an install of windows 7 ultimate i have 2 extra languages i really dont need..
    The languages are there beacuse other might need swedish language and my gf wants chinese language..

    I want to run the script manually after install if i want:)
    I guess i have to identify the installed language and somehow remove the other two..

    But how can i do that?

    Edit: Nice with a scripting subforum!
     
  2. timesurfer

    timesurfer MDL Developer

    Nov 22, 2009
    8,527
    4,112
    270
    Please feel free to ask any batch file questions in the batch repo.
     
  3. tcntad

    tcntad MDL Guru

    Oct 26, 2009
    4,488
    1,506
    150
    I will do that too then!
     
  4. timesurfer

    timesurfer MDL Developer

    Nov 22, 2009
    8,527
    4,112
    270
    Just want to not have thousand threads when we have the repo. It's just my opinion.

    ;)
     
  5. tcntad

    tcntad MDL Guru

    Oct 26, 2009
    4,488
    1,506
    150
    of course ;)
     
  6. MasterDisaster

    MasterDisaster MDL Expert

    Aug 29, 2009
    1,256
    674
    60
    @timesurfer

    I think it would be a good idea to have individual threads for each problem, so a solution can be posted for it and later discussing and clarifying doubts about the solution.

    Everything in a single thread makes it difficult in the later stage of the thread. For example take the Windows Loader thread or Windows Repository thread, how many times have you given the same answer over and over again even though the answer lies in the first post.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  7. timesurfer

    timesurfer MDL Developer

    Nov 22, 2009
    8,527
    4,112
    270
    #7 timesurfer, Oct 21, 2010
    Last edited: Oct 24, 2010
    I agree ;)
     
  8. MasterDisaster

    MasterDisaster MDL Expert

    Aug 29, 2009
    1,256
    674
    60
    #8 MasterDisaster, Oct 21, 2010
    Last edited by a moderator: Apr 20, 2017
    Run the following code in command prompt to make a list of installed languages.

    Code:
    for /f "tokens=2,* delims=:" %A in ('"dism /Online /Get-Packages|find "LanguagePack""') do @for /f "tokens=4 delims=~" %a in ("%A") do echo %a
    
    Code:
    wmic OS get OSLanguage
    
    This will give the Installed OS language in LCID form. The next step would be to determine a reliable way of getting the system default language.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  9. tcntad

    tcntad MDL Guru

    Oct 26, 2009
    4,488
    1,506
    150
    #9 tcntad, Oct 21, 2010
    Last edited by a moderator: Apr 20, 2017
    (OP)
    Thats a good start:)
     
  10. MasterDisaster

    MasterDisaster MDL Expert

    Aug 29, 2009
    1,256
    674
    60
    #10 MasterDisaster, Oct 21, 2010
    Last edited by a moderator: Apr 20, 2017
    Check this code in VM before trying it out on a real machine. Run the script as Administrator.

    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 pkg=%%A
    set pkg=!pkg: =!
    dism /online /Remove-Package /PackageName:!pkg!
    )
    )
    )
    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
    
    First for gets the lcid
    Second for convert lcid to locale name
    Third for removes language packs except the current language.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  11. tcntad

    tcntad MDL Guru

    Oct 26, 2009
    4,488
    1,506
    150
    #11 tcntad, Oct 21, 2010
    Last edited by a moderator: Apr 20, 2017
    (OP)
    Thanks alot MD!

    I actually have a laptop right next to me with win7 so i ca try it there:)
     
  12. tcntad

    tcntad MDL Guru

    Oct 26, 2009
    4,488
    1,506
    150
    Absolutely nothing happens on my laptop... Blank commandoprompt then shutdown.
     
  13. MasterDisaster

    MasterDisaster MDL Expert

    Aug 29, 2009
    1,256
    674
    60
    Did you run it as Administrator?
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  14. tcntad

    tcntad MDL Guru

    Oct 26, 2009
    4,488
    1,506
    150
    yep, both from usb and desktop.
    Edit: Ill try from a vm now instead.
     
  15. MasterDisaster

    MasterDisaster MDL Expert

    Aug 29, 2009
    1,256
    674
    60
    #15 MasterDisaster, Oct 21, 2010
    Last edited by a moderator: Apr 20, 2017
    OK lets do it one step at a time
    Code:
    wmic OS get OSLanguage
    reg query "HKLM\SYSTEM\CurrentControlSet\Control\MUI\UILanguages
    dism /Online /Get-Intl
    
    Post the output of the above commands
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  16. tcntad

    tcntad MDL Guru

    Oct 26, 2009
    4,488
    1,506
    150
    #16 tcntad, Oct 21, 2010
    Last edited by a moderator: Apr 20, 2017
    (OP)

    Works fine:)
    Code:
    D:\>wmic OS get OSLanguage
    OSLanguage
    1033
    
    
    D:\>reg query "HKLM\SYSTEM\CurrentControlSet\Control\MUI\UILanguages
    
    HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\MUI\UILanguages\en-US
    HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\MUI\UILanguages\zh-TW
    
    D:\>dism /Online /Get-Intl
    
    Deployment Image Servicing and Management tool
    Version: 6.1.7600.16385
    
    Image Version: 6.1.7600.16385
    
    Reporting online international settings.
    
    Default system UI language : en-US
    System locale : sv-SE
    Default time zone : W. Europe Standard Time
    Active keyboard(s) : 041d:0000041d, 0409:00000409
    Keyboard layered driver : PC/AT Enhanced Keyboard (101/102-Key)
    
    Installed language(s): en-US
      Type : Fully localized language.
    Installed language(s): zh-TW
      Type : Partially localized language, MUI type.
      Fallback Languages en-US
    
    The operation completed successfully.
    
    I just had to add pause in the script otherwise the window would shutdown immediately.
     
  17. MasterDisaster

    MasterDisaster MDL Expert

    Aug 29, 2009
    1,256
    674
    60
    #17 MasterDisaster, Oct 21, 2010
    Last edited by a moderator: Apr 20, 2017
    OK, your default language is english and you have a chinese as additional language

    Post the output of the following command. Just open a command prompt as Administrator and copy paste the code and hit enter.
    Code:
    dism /Online /Get-Packages|find "LanguagePack"
    
    This will list the package names of the installed language packs.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  18. tcntad

    tcntad MDL Guru

    Oct 26, 2009
    4,488
    1,506
    150
    #18 tcntad, Oct 21, 2010
    Last edited by a moderator: Apr 20, 2017
    (OP)
    Took some time but here it is.. Probably beacuseof my harddrive.. really need a new one!.
    Code:
    Microsoft Windows [Version 6.1.7600]
    Copyright (c) 2009 Microsoft Corporation.  All rights reserved.
    
    C:\Users\Pet>dism /Online /Get-Packages|find "LanguagePack"
    Package Identity : Microsoft-Windows-Client-LanguagePack-Package~31bf3856ad364e3
    5~amd64~en-US~6.1.7600.16385
    Package Identity : Microsoft-Windows-Client-LanguagePack-Package~31bf3856ad364e3
    5~amd64~zh-TW~6.1.7600.16385
    
     
  19. MasterDisaster

    MasterDisaster MDL Expert

    Aug 29, 2009
    1,256
    674
    60
    What the script basically does is gets the LCID from wmic output and stroes it in LCID variable in hexadecimal form.

    Next it iterates through the MUI\UILanguages key in HKLM\SYSTEM\CurrentControlSet\Control and matches the LCID value with the subkeys. If a match is successful, it stores the key name say en-us in the locale variable.

    Now the dism command is run to find packages with LanguagePack and checks if the locale of the language pack matches with the system locale. If it does not match it issues the RemovePackage command of dism to remove the package.

    Add pause to the script after each for and see where it quits abruptly.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  20. tcntad

    tcntad MDL Guru

    Oct 26, 2009
    4,488
    1,506
    150
    #20 tcntad, Oct 21, 2010
    Last edited: Oct 21, 2010
    (OP)
    Tried both the small commands and now the big one. sofar sogood.

    Edit: Deleting chinese traditional (zh-tw) language pack worked fine, even asked me to restart:)
    I will try this on my laptop once again..

    Edit2: Still doesnt work, ran the script with the commands to find out languages (called "bla.cmd") that worked just fine
    But when i ran "lang.cmd" with the code from posts above it did the same, just shut down.