none
Discover OS language and architecture of Windows 7 using command prompt RRS feed

  • Question

  • The problem: in a bat file a need make different think based on language an os architecture of windows 7 (are different setup program to be running).

    Something like this:

    IF OSLanguage = 1033 AND OSArchitecture == 32-bit DO
     ....
     ...
    IF OSLanguage == 1033 AND OSArchitecture == 64-bit DO
     ....
     ....
    and so on....

    I have tried with this script:
    FOR /f "tokens=1,2 delims==" %%A IN ('"wmic os get OSArchitecture,OSLanguage /format:list"') DO (
     IF /I %%A == "OSArchitecture"  SET MyArch = %%B
     IF /I %%A EQU "OSLanguage" SET MyLCID = %%B
    )
    ECHO %MyArch%
    ECHO %MyLCID%

    Result:
    There are many blank row in the result of the wmic command (this is curiosity not problem)
    %%A and %%B are well compiled (if I use ECHO %%A and ECHO %%B  inside the do the value are displayed)
    %MyArch% and %MyLCID% are empty

    Thanks for any idea

    LSo


    LSo Lorenzo Soncini Trento TN - Italy

    Wednesday, June 4, 2014 6:38 PM

Answers

  • The script

    @ECHO OFF
    for /f "tokens=2 delims==" %%A in ('wmic path win32_OperatingSystem get OSLanguage /Value') do set LSOLCID=%%A
    for /f "tokens=2 delims==" %%A in ('wmic path win32_OperatingSystem get OSArchitecture /Value') do set LSOARCH=%%A
    ECHO Language: %LSOLCID% - Architecture: %LSOARCH%
    IF /I %LSOLCID% EQU 1040 ECHO PIPPO ITA
    IF /I %LSOLCID% EQU 1033 ECHO PIPPO ENG
    IF /I %LSOARCH% EQU 32-bit ECHO PIPPO 32
    IF /I %LSOARCH% EQU 64-bit ECHO PIPPO 64

    work fine!

    The problem was the editor! If you save in UNICODE the script not work. I have saved with the CMD EDIT di Windows 7 (in Windows 8 disappear) or used the ANSI standard format the script work well!

    LSo


    LSo Lorenzo Soncini Trento TN - Italy

    Tuesday, September 2, 2014 4:06 PM

All replies

  • Wednesday, June 4, 2014 7:37 PM
  • Careful. If you read PROCESSOR_ARCHITECTURE from a 32-bit process, you'll get x86 even on a 64-bit system (that is the point of emulation, after all).

    I think you probably want to say something like this:


    set ARCH=
    if defined PROCESSOR_ARCHITEW6432 (
      set ARCH=%PROCESSOR_ARCHITEW6432%
    ) else (
      set ARCH=%PROCESSOR_ARCHITECTURE%
    )
    if /i {%ARCH%}=={x86} goto :32BIT
    if /i {%ARCH%}=={AMD64} goto :64BIT
    



    -- Bill Stewart [Bill_Stewart]

    Wednesday, June 4, 2014 7:42 PM
    Moderator
  • I have resolved the first issue. Now with the script:

    for /f "tokens=2 delims==" %%A in ('wmic path win32_OperatingSystem get OSLanguage /Value') do set LSOLCID=%%A
    for /f "tokens=2 delims==" %%A in ('wmic path win32_OperatingSystem get OSArchitecture /Value') do set LSOARCH=%%A
    ECHO Language: %LSOLCID% - Architecture: %LSOARCH%

    I have the right answer and the correct value in the 2 variable.

    Now if I use this function:

    IF /I {%LSOARCH%} == {32 bit} goto :32BIT
    IF /I {%LSOARCH%} == {64 bit} goto :64BIT

    I receive the error "bit} is unexpected." (In Italian is "bit} non atteso.")

    If I use

    IF /I %LSOARCH% == 32 bit goto :32BIT
    IF /I %LSOARCH% == 64 bit goto :64BIT

    the error is  "bit is unexpected." (In Italian is "bit non atteso.")

    My hipotesys is some character wrong inside the %LSOARCH%. But if I use something like this:

    SET _prefix = %LSOARCH:0,2%
    and made the if

    IF /I %_prefix% == 32 GOTO :32BIT

    I receive the same error (ECHO %_prefix% tell me correctly the value of 32)

    I use Windows 7 SP1 Professional 32 bit Italian

    LSo


    LSo Lorenzo Soncini Trento TN - Italy

    Thursday, June 5, 2014 7:58 AM
  • Any reason for using shell script (batch) instead of PowerShell?


    -- Bill Stewart [Bill_Stewart]

    Thursday, June 5, 2014 1:40 PM
    Moderator
  • Just for information...on Windows 2008 R2 Server the script work

    I use vbs o CMD because the script launch is made by MDT 2013 and is used for running specific application setup.

    I'd rather use PowerShell but I'm afraid compatibility issues with old setup. Also in the machine is installed by default Powershell 4 (is one of the first software installed)

    LSo


    LSo Lorenzo Soncini Trento TN - Italy

    Thursday, June 5, 2014 1:55 PM
  • This would be easier in VBScript than in shell script (batch). For example:


    Dim WMI
    Set WMI = GetObject("winmgmts:root/CIMV2")
    
    Dim Collection, Item, OSArchitecture, OSLanguage
    Set Collection = WMI.InstancesOf("Win32_OperatingSystem")
    For Each Item In Collection
      OSArchitecture = Item.OSArchitecture
      OSLanguage = Item.OSLanguage
      Exit For
    Next
    
    WScript.Echo "OS Architecture: " & OSArchitecture & vbNewLine _
      & "OS Language: " & OSLanguage
    


    -- Bill Stewart [Bill_Stewart]

    Thursday, June 5, 2014 2:01 PM
    Moderator
  • The script

    @ECHO OFF
    for /f "tokens=2 delims==" %%A in ('wmic path win32_OperatingSystem get OSLanguage /Value') do set LSOLCID=%%A
    for /f "tokens=2 delims==" %%A in ('wmic path win32_OperatingSystem get OSArchitecture /Value') do set LSOARCH=%%A
    ECHO Language: %LSOLCID% - Architecture: %LSOARCH%
    IF /I %LSOLCID% EQU 1040 ECHO PIPPO ITA
    IF /I %LSOLCID% EQU 1033 ECHO PIPPO ENG
    IF /I %LSOARCH% EQU 32-bit ECHO PIPPO 32
    IF /I %LSOARCH% EQU 64-bit ECHO PIPPO 64

    work fine!

    The problem was the editor! If you save in UNICODE the script not work. I have saved with the CMD EDIT di Windows 7 (in Windows 8 disappear) or used the ANSI standard format the script work well!

    LSo


    LSo Lorenzo Soncini Trento TN - Italy

    Tuesday, September 2, 2014 4:06 PM
  • Accessing the value directly in VBScript is preferable to running wmic and parsing the output, IMO.

    -- Bill Stewart [Bill_Stewart]

    Tuesday, September 2, 2014 4:08 PM
    Moderator