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.
Or (alternately), the "Home location" in Control Panel -> Region -> Location tab.
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.
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