How can I programmatically access the region of a Windows computer?

4

2

How can I programmatically access the region of a Windows computer?

Specifically, I'm looking for this value in the Region & Language settings panel in Windows 10.

Windows 10 Region

Or (alternately), the "Home location" in Control Panel -> Region -> Location tab.

Windows Control Panel Location

I'm hoping to find something that will work for Windows 7-10. Also noting that my selected default language is English (United States). I have tried both logging out and restarting my computer to get the any changes to apply. I have tried the following commands (from powershell):

wmic os get locale
// 0409 -> Translates to United States
// This one is especially problematic - 
// it doesn't seem to change
// when I change my default language.

Get-Culture
// 1033 -> English (United States)

Get-UICulture
// 1033 -> English (United States)

I would prefer not to rely on the operating system's selected language, if at all possible. A non-powershell solution would be great, too, since I'm not sure I can rely on powershell scripts being executable on the end-user's machines.


Edit: This answer on Stack Overflow works for me, and reports "Canada" as expected (or "CA", if I use a GeoType of 4, which is what I'm actually after). I'm not using C Sharp (or anything that would be able to interface with kernel32.dll directly), so if anyone knows where to get that information elsewhere, it would still be appreciated. But I can write a .NET Core application that grabs it for me, if I have to.

dvlsg

Posted 2018-08-31T21:22:35.833

Reputation: 165

Answers

1

The Windows Region setting appears to be stored, per user, in registry here: HKEY_CURRENT_USER:\Control Panel\International\Geo\. If you did wind up using Powershell to retrieve this value, you could do so with:

gp 'HKCU:\Control Panel\International\Geo\' | select -exp Name

Example for US:

Region CA Region CA PS

Example for CA:

Region US Region US PS

root

Posted 2018-08-31T21:22:35.833

Reputation: 2 992

Perfect, thank you. I'm going to mark this one as the answer as it's likely what I'll end up using (still not sure if I'll be able to rely on having access to run powershell scripts on the end-users' machines), but the Get-WinHomeLocation looks very helpful as well. – dvlsg – 2018-09-02T06:56:36.520

3

How do I get the windows home location?

Use Get-WinHomeLocation:

The Get-WinHomeLocation cmdlet gets the value of the user GeoID setting and returns a .NET GeoID object. The Windows GeoID setting is a user setting that describes the home location of the current user account. A home location is the country or region. Applications that require the home location of the current user account, such as a driver for a television tuner application, can use this setting.

For a table of GeoIDs, see Table of Geographical Locations.

Examples

Example 1: Display the GeoID for the current account

PS C:\> Get-WinHomeLocation
HomeLocation     Description
----             -----------
244              United States

This command returns the GeoID setting and its display name for the current user account.

Source Get-WinHomeLocation

DavidPostill

Posted 2018-08-31T21:22:35.833

Reputation: 118 938

Thank you, this looks really helpful. This will be the solution I reach for if I end up being able to use powershell. – dvlsg – 2018-09-02T06:57:35.433

1

systeminfo | findstr “Locale” | find "System" | cut -f2 -d( | sed s/)//g

relies on the GNU text utilities cut and sed since Windows does not have the text filtering capavbility needed out of the box. Their Win32 binaries may be downloaded from http://gnuwin32.sourceforge.net/packages/coreutils.htm and copied into the path of the machine, or into the directory where you will execute the command.

systeminfo is a part of Windows which extracts info about your configuration and hardware. We take its output and filter it with findstr, another Window executable, to show only the lines with "locale", then use find, yet another Windows executable, to filter the remaining lines to show only those also including "System". Then, we use cut to throw away everything up to and including "(", and sed finishes the job by throwing away the close parenthesis character ")".

It's not Powershell, and although it does depend on two foreign binaries, they are benign and small (39KB and 79KB).

K7AAY

Posted 2018-08-31T21:22:35.833

Reputation: 6 962

Thanks for the response - I'm actually getting en-us;English (United States) reported for both System Locale and Input Locale, so it looks like that may still correspond to the language? – dvlsg – 2018-08-31T23:41:57.480

Yeah. I actually already had coreutils on my machine already. The exact output from the whole command pipe is United States. – dvlsg – 2018-08-31T23:45:33.623

That's the Region, what you wanted, right? – K7AAY – 2018-08-31T23:46:44.207

It is, but it's reporting United States, when my machine is set to Canada. I suspect it's pulling united states from my selected default language (which is indeed en-US). I was just curious if there was a way to get the selected region in the screenshots above. Looks like there's a way to get it by interfacing with kernel32.dll, but I don't have access to that in the application I'm using, short of writing a separate .exe and interfacing with that. – dvlsg – 2018-08-31T23:48:08.360