2015-01-14 153 views

回答

0

您可以使用RegionInfo類是這樣的:

String currentRegion= System.Globalization.RegionInfo.CurrentRegion.DisplayName; 
+0

你試過嗎?這不是OP正在尋找的地區。 IIRC的「住所」與此無關。 – spender

+0

你沒有提到你在Windows 8上。 – Abhishek

+0

我在Windows 7上,它適合我。什麼是IIRC? – Abhishek

0

所以,我砍死了這一點的PowerShell命令Get-WinHomeLocation的:

如果聲明以下類:

public static class GeoTools 
{ 
    [DllImport("kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)] 
    public static extern int GetUserGeoID(int GeoClass); 
    [DllImport("kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)] 
    public static extern int GetGeoInfo(int Location, 
             uint GeoType, 
             StringBuilder GeoData, 
             int Length, 
             ushort LangID); 
} 

然後你可以:

uint GEO_FRIENDLYNAME = 8u; 
var homeLocationGeoId=GeoTools.GetUserGeoID(16); 
StringBuilder stringBuilder = new StringBuilder(256); 
int geoInfo = GeoTools.GetGeoInfo(homeLocationGeoId, 
            GEO_FRIENDLYNAME, 
            stringBuilder, 
            256, 
            0); 
var homeLocation = stringBuilder.ToString(); //yay! 
相關問題