[Batch] Remove language batch?

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

  1. MasterDisaster

    MasterDisaster MDL Expert

    Aug 29, 2009
    1,256
    674
    60
    #21 MasterDisaster, Oct 21, 2010
    Last edited: Oct 21, 2010
    Maybe something is different on the laptop. Have you tried adding a pause after each for?

    Post the output of bla.cmd on the laptop.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  2. tcntad

    tcntad MDL Guru

    Oct 26, 2009
    4,214
    1,363
    150
    #22 tcntad, Oct 21, 2010
    Last edited: Oct 21, 2010
    (OP)
    Hm i added some pause but not after every for :p

    Illl also reinstall 7 on it..

    Edit:

    I addded
    echo pause 1 and pause after "call dec2hex %%a )"

    then echo pause 2 and pause after second for [dism online/...... !pkg! ) ) ) ]
    Seems like the script jumps directly to echch pause 3 which is right before ":Dec2hex"

    Hope you know what i mean :p
     
  3. MasterDisaster

    MasterDisaster MDL Expert

    Aug 29, 2009
    1,256
    674
    60
    There are only 3 main for loops.
    Select the target, Search for target and Destroy the target
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  4. tcntad

    tcntad MDL Guru

    Oct 26, 2009
    4,214
    1,363
    150
    yep i know..

    I ran the big script on my computer (where i removed zh-tw already) and it did the same as on my laptop.
    Seems like it shuts down if it cant find any languagepack besides the one in use(?) but i dont understand why it does that on my laptop:/..
     
  5. MasterDisaster

    MasterDisaster MDL Expert

    Aug 29, 2009
    1,256
    674
    60
    But the script should pause at the end if it does not find any additional language packs.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  6. tcntad

    tcntad MDL Guru

    Oct 26, 2009
    4,214
    1,363
    150
    it does pause.. atleast on my computer and after pressing the famous anykey then yes it dissapears.
     
  7. MasterDisaster

    MasterDisaster MDL Expert

    Aug 29, 2009
    1,256
    674
    60
    What is the output of the following command on your laptop

    dism /Online /Get-Packages|find "LanguagePack"
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  8. tcntad

    tcntad MDL Guru

    Oct 26, 2009
    4,214
    1,363
    150
    #28 tcntad, Oct 21, 2010
    Last edited: Oct 21, 2010
    (OP)
    Edit:

    Same as earlier but included swedish lp.

    Ill install windows 7 now.. should take roughly 20 minutes
     
  9. MasterDisaster

    MasterDisaster MDL Expert

    Aug 29, 2009
    1,256
    674
    60
    How could that be? Try this

    dism /Online /Get-Packages|more

    press space for next screen and CTRL+C to break out of the command

    The first output of the above command will be the installed language pack.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  10. tcntad

    tcntad MDL Guru

    Oct 26, 2009
    4,214
    1,363
    150
    Yep they are.. And it works fine..

    Although i just started reinstalling windows 7 on my laptop hehe.
     
  11. tcntad

    tcntad MDL Guru

    Oct 26, 2009
    4,214
    1,363
    150
    #31 tcntad, Oct 21, 2010
    Last edited: Oct 21, 2010
    (OP)
    Done reinstalling windows...

    Now this command seems to work fine:)
    Edit2: Ye its working from a script

    Edit3:
    dism /online /get-pacakges:more works fine..

    Edit4:

    Ran the script from cmd (not rightclick and run as admin) and then i got "unexpected (". Or < but i doubt it :p
     
  12. tcntad

    tcntad MDL Guru

    Oct 26, 2009
    4,214
    1,363
    150
    Tried it again to see if you missed or added too many ( or ) but coudnt see any.. Script still just shuts down.
     
  13. MasterDisaster

    MasterDisaster MDL Expert

    Aug 29, 2009
    1,256
    674
    60
    Are you sure they are other additional language packs? The script works correctly if there is an additional language installed. It worked for you once on your desktop. Please give the output of bla.cmd on your laptop. Something has to be different on that laptop which I may have overlooked.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  14. tcntad

    tcntad MDL Guru

    Oct 26, 2009
    4,214
    1,363
    150
    #34 tcntad, Oct 23, 2010
    Last edited by a moderator: Apr 20, 2017
    (OP)
    Well Ive used the same language packs on my computer, same source etc, ill try again then.
    Right after installing windows 7 hm.

    Edit:
    Ran dism /online /get-packages|find "languagePack" & it works fine.
    Code:
    Paketidentitet : Microsoft-Windows-Client-LanguagePack-Package~31bf3856ad364e35~x86~en-US~6.1.7600.16385
    Paketidentitet : Microsoft-Windows-Client-LanguagePack-Package~31bf3856ad364e35~x86~sv-SE~6.1.7600.16385
    Paketidentitet : Microsoft-Windows-Client-LanguagePack-Package~31bf3856ad364e35~x86~zh-TW~6.1.7600.16385
    
    Ran wmic OS get OSLanguage & it works fine
    Code:
    DISM-verktyget (Deployment Image Servicing and Management)
    Version: 6.1.7600.16385
    
    Avbildningsversion: 6.1.7600.16385
    
    Rapporterar internationella inställningar online.
    
    Standardspråk för systemets användargränssnitt : sv-SE
    Användargränssnittets reservspråk är : en-US
    Systemspråkinställning : sv-SE
    Standardtidszon : W. Europe Standard Time
    Aktiva tangentbord : 041d:0000041d, 0409:00000409
    Tangentbordsdrivrutin : Utökat PC/AT-tangentbord (101/102 tangenter)
    
    Installerade språk: en-US
      Typ: fullständigt lokaliserat språk.
    Installerade språk: sv-SE
      Typ: delvis lokaliserat språk, MUI-typ.
      Reservspråk en-US
    Installerade språk: zh-TW
      Typ: delvis lokaliserat språk, MUI-typ.
      Reservspråk en-US
    
    Åtgärden har slutförts.
    
    Ran the first code you posted & its not working..

    Edit: Can i have the script ask me what languagepack to remove? :p
     
  15. MasterDisaster

    MasterDisaster MDL Expert

    Aug 29, 2009
    1,256
    674
    60
    #35 MasterDisaster, Oct 23, 2010
    Last edited by a moderator: Apr 20, 2017
    You mean this command does not work

    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
    
    This is an important step, since the output of this command is used to compare with the locale variable. If you tried it in a batch file you need to add an additional % to %A and %a.

    For confirmation before deletion of a language pack add something like
    Code:
    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
    )
    )
    )
    )
    
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  16. tcntad

    tcntad MDL Guru

    Oct 26, 2009
    4,214
    1,363
    150
    #36 tcntad, Oct 23, 2010
    Last edited by a moderator: Apr 20, 2017
    (OP)
    Wow i see i have alot more to learn about scripting :p

    So can I take the above script and replace it with your initial code you first posted?
     
  17. MasterDisaster

    MasterDisaster MDL Expert

    Aug 29, 2009
    1,256
    674
    60
    You need to replace the 3rd for loop.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  18. tcntad

    tcntad MDL Guru

    Oct 26, 2009
    4,214
    1,363
    150
    #38 tcntad, Oct 23, 2010
    Last edited by a moderator: Apr 20, 2017
    (OP)
    Will try that..

    replace
    Code:
    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!
    )
    )
    )
    
    with
    Code:
    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
    )
    )
    )
    )
    
    Correct?
     
  19. MasterDisaster

    MasterDisaster MDL Expert

    Aug 29, 2009
    1,256
    674
    60
    Yes, that is correct
    What about the output of the first code snippet? Does it list the installed languages?
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  20. tcntad

    tcntad MDL Guru

    Oct 26, 2009
    4,214
    1,363
    150
    #40 tcntad, Oct 23, 2010
    Last edited by a moderator: Apr 20, 2017
    (OP)
    Tried that.. Still shuts down.. I get message: unexpected )

    And yes the code
    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
    
    works fine on my computer.