Search This Blog

Saturday, 31 December 2016

Setting Windows regional settings, language and locale etc to en-GB in batch

The Problem

A load of PCs at my work have strangely been showing as having different regional formats even though the languages were set correctly. This was annoying as one of our in-house apps uses .Net date-time parsing which fails when the formats aren't correct. Instead of running up to each PC and manually clicking through forms, I wanted a scripted way (any would do, of forcing all related language settings on all versions of Windows (7 and up).

The Process

I made a batch script. Quick and cheezy.
Using control intl.cpl,,f:<filepath .xml="">you can make windows apply an XML file template. https://support.microsoft.com/en-gb/kb/2764405

I don't want to carry an XML file with the batch file... It just... Annoys me... Also, some of the settings require admin rights to take effect. So, one batch function for creating a temp XML file to be deleted after use and one function to check for admin rights.

The Code


@echo off
call:IsAdmin
set XMLPath="%~dp0en-GB.xml"
if exist %XMLPath% ( del /F /Q %XMLPath% )
call:CreateLocaleXML %XMLPath%
control intl.cpl,,/f:%XMLPath%
del /F /Q %XMLPath%
pause & exit
:CreateLocaleXML
echo ^<gs:GlobalizationServices xmlns:gs="urn:longhornGlobalizationUnattend"^> >> %1
echo ^<!-- user list --^> >> %1
echo ^<gs:UserList^> >> %1
echo ^<gs:User UserID="Current" CopySettingsToDefaultUserAcct="true" CopySettingsToSystemAcct="true"/^> >> %1
echo ^</gs:UserList^> >> %1
echo ^<gs:MUILanguagePreferences^> >> %1
echo ^<gs:MUILanguage Value="en-GB"/^> >> %1
echo ^<gs:MUIFallback Value="en-GB"/^> >> %1
echo ^</gs:MUILanguagePreferences^> >> %1
echo ^<!-- system locale --^> >> %1
echo ^<gs:SystemLocale Name="en-GB"/^> >> %1
echo ^<!-- input preferences --^> >> %1
echo ^<gs:InputPreferences^> >> %1
echo ^<gs:InputLanguageID Action="add" ID="0809:00000809"/^> >> %1
echo ^<gs:InputLanguageID Action="remove" ID="0409:00000409"/^> >> %1
echo ^</gs:InputPreferences^> >> %1
echo ^<!-- user locale --^> >> %1
echo ^<gs:UserLocale^> >> %1
echo ^<gs:Locale Name="en-GB" SetAsCurrent="true" ResetAllSettings="true"^> >> %1
echo ^</gs:Locale^> >> %1
echo ^</gs:UserLocale^> >> %1
echo ^</gs:GlobalizationServices^> >> %1
goto:eof
:IsAdmin
"%systemroot%\system32\reg.exe" query "HKU\S-1-5-19\Environment"
If Not %ERRORLEVEL% EQU 0 (
Cls & Echo You must have administrator rights to continue ...
Pause & Exit
)
Cls
goto:eof

Notes

In the batch function to create the XML file, I use the echo command and redirect the output to a file, but the '<' and '>' characters from XML are interpreted by the command processor as redirections. So I used the '^' character escape symbol.

I'm not sure if this works yet... Should do though.

Tuesday, 13 December 2016

Windows 8.x and 10 Update messing with net connections - Here's a Fix

Hi,
    I'll make this quick and not pretty. It's base simple but quite useful if you help your friends and family with IT stuff.

At the time of writing, it seems like Microsoft have released a dodgy update (which to my knowledge hasn't been identified yet). There's something about the DHCP client not retreiving the IP from the router/switch/AP side. I had a good friend at work send me a heads up on this while I was on the way into work today. When I got home, my laptop had lost LAN connection through Wifi.

http://www.theregister.co.uk/2016/12/13/microsoft_windows_10_broken_networking/

There are other sources, but that's a general overview. I read the article and adjusted the fixing lines of code into a simple to use batch script.

Note:This will require a restart of the PC
 - Copy and paste the lines below into a notepad window.
 - Save the text file and rename it 'fix.bat'.
 - Run as administrator:

@Echo Off
call :IsAdmin

echo Running "netsh winsock reset catalog" ...
netsh winsock reset catalog
echo Running "netsh int ipv4 reset reset.log" ...
netsh int ipv4 reset reset.log
Pause & Exit

:IsAdmin
%systemroot%\system32\Reg.exe query "HKU\S-1-5-19\Environment"
If Not %ERRORLEVEL% EQU 0 (
 Cls & Echo You must have administrator rights to continue ... 
 Pause & Exit
)
Cls
goto:eof