After long searches, I finally got a response. After two links, help me get the current location of the machine -
http://social.msdn.microsoft.com/Forums/eu/csharpgeneral/thread/6dfaa142-c588-4cb0-b044-fa1e8138b299
http://www.siao2.com/2007/02/21/1733999.aspx
I made the following utility class if someone is interested in the final code -
public static class RegionAndLanguageHelper { #region Constants private const int GEO_FRIENDLYNAME = 8; #endregion #region Private Enums private enum GeoClass : int { Nation = 16, Region = 14, }; #endregion #region Win32 Declarations [DllImport("kernel32.dll", ExactSpelling = true, CallingConvention = CallingConvention.StdCall, SetLastError = true)] private static extern int GetUserGeoID(GeoClass geoClass); [DllImport("kernel32.dll")] private static extern int GetUserDefaultLCID(); [DllImport("kernel32.dll")] private static extern int GetGeoInfo(int geoid, int geoType, StringBuilder lpGeoData, int cchData, int langid); #endregion #region Public Methods /// <summary> /// Returns machine current location as specified in Region and Language settings. /// </summary> public static string GetMachineCurrentLocation() { int geoId = GetUserGeoID(GeoClass.Nation); ; int lcid = GetUserDefaultLCID(); StringBuilder locationBuffer = new StringBuilder(100); GetGeoInfo(geoId, GEO_FRIENDLYNAME, locationBuffer, locationBuffer.Capacity, lcid); return locationBuffer.ToString().Trim(); } #endregion }
Sanjay singh
source share