Overblog Tous les blogs Top blogs Technologie & Science Tous les blogs Technologie & Science
Editer l'article Suivre ce blog Administration + Créer mon blog
MENU

[vbs] [ps1] [SCCM] auto configuration of uilanguage

Publié le par damcuvelier

in vbscript:

usage: cscript <script.vbs> /country:france  ## or cscript <script.vbs> /country:belgium-french

 

strComputer = "."

Dim oReg, strKeyPath
dim iRetVal, oWsh, sCmdfr,sCmdus,sCmddelfr
Dim gethomepath, oOsdV4
Dim OSDUserLocale, OSDSystemLocale
Dim OSDInputLocale, OSDUILanguage
Dim OSDGeoID
dim GetTsVariable,result
Dim colNamedArguments

const HKEY_CURRENT_USER = &H80000001
const HKEY_LOCAL_MACHINE = &H80000002

Set colNamedArguments = WScript.Arguments.Named
gethomepath=left(WScript.ScriptFullName,len(WScript.ScriptFullName)-len(WScript.ScriptName)-1)

Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\default:StdRegProv")
strKeyPath = "SOFTWARE\Classes\MIME\Database\Rfc1766"

 

Set oWsh = CreateObject("WScript.Shell")

  On Error Resume Next
    Set oOsdV4 = CreateObject("Microsoft.SMS.TSEnvironment")
    GetTsVariable = Err.number
  On Error GoTo 0
 
If not GetTsVariable=0 Then
    vGeoID = split(InitializeLANGs(),";")(3)
    vOSDGeoID = CLng("&H" & vGeoID)
    OSDInputLocale = split(InitializeLANGs(),";")(0)
    OSDUserLocale = split(InitializeLANGs(),";")(1)
    OSDUILanguage = split(InitializeLANGs(),";")(2)
    OSDSystemLocale = "en-US"
    OSDUILanguageFallback = "en-US"
    OSDGeoID = vOSDGeoID
else
OSDUserLocale = oOsdV4("OSDUserLocale")
OSDSystemLocale = oOsdV4("OSDSystemLocale")
OSDInputLocale = oOsdV4("OSDInputLocale")
OSDUILanguage = oOsdV4("OSDUILanguage")
OSDGeoID = oOsdV4("OSDGeoID")
end if

oReg.GetStringValue HKEY_LOCAL_MACHINE,strKeyPath,split(OSDInputLocale,":")(0),strValue
if isnull(strValue) = true then
strValue = split(InitializeLANGs(),";")(1)
end if

if instr(split(strValue)(0),"-")>0 then
result = split(strValue,";")(0)
else
result = lcase(split(strValue,";")(0)) & "-" & ucase(split(strValue,";")(0))
end if

 

 

If GetTsVariable=0 Then
Set ProgressUI = CreateObject("Microsoft.SMS.TsProgressUI")
ProgressUI.CloseProgressDialog
end if

sCmd = "cmd /c cscript //nologo " & gethomepath &"\RegionalSettings.wsf /UserLocale:"& OSDUserLocale &" /SystemLocale:en-US /KeyboardLocale:" & chr(34) & OSDInputLocale & ";0409:00000409" & chr(34) & " /UILanguage:" & result & " /GeoID:"& OSDGeoID


iRetVal = oWsh.Run(sCmd, 0, true)

 

function InitializeLANGs()
    Dim ListvariablesLANG, ObjFile, oOption, Line
    Set ObjFile = CreateObject("Scripting.FileSystemObject")
    ListvariablesLANG = "LangWiz_Initialization.ini"
    'Chargement de la liste des LANGs
    For Each Line In Split(ObjFile.OpenTextFile(ListvariablesLANG,1).ReadAll(),vbCrLf)
        if trim(Line)="" _
        or ubound(split(Line,";")) < 1 then
        else
        if instr(colNamedArguments.Item("country"),"-") > 0  then
        argument = split(colNamedArguments.Item("country"),"-")(0) & " (" & split(colNamedArguments.Item("country"),"-")(1) & ")"
        else
        argument = colNamedArguments.Item("country")
        end if
            if instr(lcase(split(Line,";")(0)),lcase(trim(argument)))>0 then
            InitializeLANGs = split(Line,";")(1) & ";" & split(Line,";")(2) & ";" & split(Line,";")(3) & ";" & split(Line,";")(4)
            end if
        end if
    Next
End function

 

-----------------------------------------------------------------------------------------------------------------

 

on the same folder, add this answer file:

LangWiz_Initialization.ini

->

Belgium (French);080c:0000080c;"fr-BE";"fr-FR";15
Canada (French);0c0c:00000c0c;"fr-CA";"fr-FR";27
France (French);040c:0000040c;"fr-FR";"fr-FR";54
Gabon (French);040c:0000040c;"fr-FR";"fr-FR";57
Brazil (English);0416:00000416;"pt-BR";"en-US";20
Canada (English);1009:00001009;"en-CA";"en-US";27

 

-----------------------------------------------------------------------------------------------------------------

the same in powershell (not tested again): 

$ErrorActionPreference = "SilentlyContinue"

$HKEY_CURRENT_USER =2147483649
$HKEY_Local_Machine =2147483650
$computer ='.'
$invocation = (Get-Variable MyInvocation).Value
$directorypath = Split-Path $invocation.MyCommand.Path
$reg = [WMIClass]"ROOT\DEFAULT:StdRegProv"
$strKeyPath = "SOFTWARE\Classes\MIME\Database\Rfc1766"
$oOsdV4 = New-Object -COMObject Microsoft.SMS.TSEnvironment
    
function InitializeLANG
{
    $ListvariablesLANG = [IO.File]::ReadAllText("LangWiz_Initialization.ini")
    # Chargement de la liste des LANGs
    ForEach ($Line In $ListvariablesLANG){
        if (!(($Line.trim -eq "") -or (ubound($Line.split(";")) -le 1))) {
            if ([string]$country.contains("-"){$argument = split($country),"-")($country),"-")(1)} else {$argument = $country}
            
            if ([string](lcase($Line.split(";")(0))).contains(lcase(trim($argument)))) {$InitializeLANGs = $Line.split(";")(1) + ";" + $Line.split(";")(2) + ";" + $Line.split(";")(3) + ";" + $Line.split(";")(4)}
        }
    }

}
 
If (!($GetTsVariable -eq 0)) 
{
    $vGeoID = $InitializeLANGs.split(";")(3)
    $vOSDGeoID = [long]("&HvGeoID")
    $OSDInputLocale = $InitializeLANGs.split(";")(0)
    $OSDUserLocale = $InitializeLANGs.split(";")(1)
    $OSDUILanguage = $InitializeLANGs.split(";")(2)
    $OSDSystemLocale = "en-US"
    $OSDUILanguageFallback = "en-US"
    $OSDGeoID = $vOSDGeoID
} else {
$OSDUserLocale = $tsenv.Value('OSDUserLocale')
$OSDSystemLocale = $tsenv.Value('OSDSystemLocale')
$OSDInputLocale = $tsenv.Value('OSDInputLocale')
$OSDUILanguage = $tsenv.Value('OSDUILanguage')
$OSDGeoID = $tsenv.Value('OSDGeoID')
}

$strValue = $reg.GetStringValue($HKEY_LOCAL_MACHINE, $strKeyPath, $OSDInputLocale.split(":")(0))
if (! $strValue) {$strValue = InitializeLANGs().split(";")(1)}
if ([string]$strValue.contains("-")) {$result = $strValue.split(";")(0)} else {$result = ($strValue.split(";")(0)).lcase & "-" & ($strValue.split(";")(0)).ucase}

if ($GetTsVariable -eq 0) {
$ProgressUI = New-Object -COMObject Microsoft.SMS.TsProgressUI
$ProgressUI.CloseProgressDialog
}

$sCmd = "cmd /c cscript //nologo " & $directorypath &"\RegionalSettings.wsf /UserLocale:"& $OSDUserLocale &" /SystemLocale:en-US /KeyboardLocale:" & chr(34) & $OSDInputLocale & ";0409:00000409" & chr(34) & " /UILanguage:" & $result & " /GeoID:"& $OSDGeoID

& $sCmd
 

 

and now with or without sccm uilanguage in windows 7 will be configured automatically

Commenter cet article