[英]Programmatically get the location set up in regional settings
您可以像這樣使用RegionInfo
類:
String currentRegion= System.Globalization.RegionInfo.CurrentRegion.DisplayName;
因此,我從powershell cmdlet Get-WinHomeLocation
破解了此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!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.