开发者

How to detect in which country/region installer is running

How to detect in w开发者_运维问答hich country / region installer is running (offline).


There's GetUserDefaultGeoName function:

[Code]

function GetUserDefaultGeoName(GeoName: string; GeoNameCount: Integer): Integer; 
  external 'GetUserDefaultGeoName@Kernel32.dll stdcall';

function GetGeoName: string;
begin
  SetLength(Result, 100);
  SetLength(Result, GetUserDefaultGeoName(Result, Length(Result)));
end;


You should access registry key HKEY_CURRENT_USER/Control Panel/International/sCountry or possibly sLanguage.

Note this will give you the cultural conventions and language the user wants rather the actual geographical location.

A possible alternative is HKEY_CURRENT_USER/Software/Microsoft/Windows NT/TimeZones/TimeZoneKeyName which may give you a clue as to the real location.

Otherwise you could use a web service like http://www.ip-adress.com/ which will tell you the location of the machines ISP, which may well be in a different country from the machine itself given the tortured topology of some corporate networks.

What usually works best is to ask the user to "Select Country" from a pull-down menu.


You should not rely on registry values, they might be changed or removed from later version of Windows without further notice. I recommend to use Windows API GetLocaleInfo() directly instead.

BTW, why do you want to do that? If you just want to make your installer automatically use a language corresponds to the language settings in the user's control panel, set LanguageDetectionMethod=locale in the [Setup] section.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜