2012-05-16 39 views
1

我試圖訪問控制面板:區域和語言:位置:當前位置使用Ruby進行設置。我只對國家代碼感興趣。使用Ruby讀取Windows中的區域位置設置(國家代碼)?

我得到的最接近的是來自System Locale的國家代碼,但那不是我以前的樣子。

`systeminfo | findstr /B /C:"System Locale"`.to_s.upcase.strip[30..31] 

我希望有人在那裏會知道。謝謝。

回答

3

使用Win32 API的魔力:

require 'Win32API' 

getgeoid = Win32API.new('kernel32', 'GetUserGeoID', ['L'], 'L') 
location = getgeoid.call(16) 
=> 77 
location.to_s(16) 
=> "4d" 

爲了您收到的實際位置名稱值轉換,那麼你使用此表: http://msdn.microsoft.com/en-us/library/dd374073.aspx

的文檔GetUserGeoID
http://msdn.microsoft.com/en-us/library/dd318138.aspx

在哪裏可以看到編號16被定義爲GEOCLASS_NATION
http://msdn.microsoft.com/en-us/library/dd374070.aspx

+0

這是比我預期的更多的工作。但這是正確的解決方案。謝謝。 – Aeyoun

相關問題