Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for icountry.vbs

(view source code of icountry.vbs as plain text)

  1. Option Explicit
  2.  
  3. Dim numCountry
  4.  
  5. numCountry = 0
  6.  
  7. With WScript.Arguments
  8. 	If .Named.Count > 0 Then Syntax
  9. 	With .Unnamed
  10. 		If .Count = 1 Then
  11. 			If IsNumeric( .Item(0) ) Then
  12. 				If CStr( Int( .Item(0) ) ) = CStr( .Item(0) ) Then
  13. 					numCountry = Int( .Item(0) )
  14. 				End If
  15. 			End If
  16. 			If numCountry = 0 Then Syntax
  17. 		End If
  18. 	End With
  19. End With
  20.  
  21. WScript.Echo Country( numCountry )
  22.  
  23.  
  24. Function Country( numCountry )
  25. 	' Extracted from Microsoft Internet Explorer 6 Resource Kit,
  26. 	' Appendix F: Country/Region and Language Codes
  27. 	' http://technet.microsoft.com/en-us/library/dd346950.aspx
  28.  
  29. 	Dim dctCountryCodes, wshShell
  30.  
  31. 	Country = ""
  32.  
  33. 	Set dctCountryCodes = CreateObject( "Scripting.Dictionary" )
  34. 	dctCountryCodes.Add    1, "United States"
  35. 	dctCountryCodes.Add    2, "Canada"
  36. 	dctCountryCodes.Add    7, "Russia"
  37. 	dctCountryCodes.Add   20, "Egypt"
  38. 	dctCountryCodes.Add   27, "South Africa"
  39. 	dctCountryCodes.Add   30, "Greece"
  40. 	dctCountryCodes.Add   31, "The Netherlands"
  41. 	dctCountryCodes.Add   32, "Belgium"
  42. 	dctCountryCodes.Add   33, "France"
  43. 	dctCountryCodes.Add   34, "Spain"
  44. 	dctCountryCodes.Add   36, "Hungary"
  45. 	dctCountryCodes.Add   39, "Italy"
  46. 	dctCountryCodes.Add   40, "Romania"
  47. 	dctCountryCodes.Add   41, "Switzerland"
  48. 	dctCountryCodes.Add   43, "Austria"
  49. 	dctCountryCodes.Add   44, "United Kingdom"
  50. 	dctCountryCodes.Add   45, "Denmark"
  51. 	dctCountryCodes.Add   46, "Sweden"
  52. 	dctCountryCodes.Add   47, "Norway"
  53. 	dctCountryCodes.Add   48, "Poland"
  54. 	dctCountryCodes.Add   49, "Germany"
  55. 	dctCountryCodes.Add   51, "Peru"
  56. 	dctCountryCodes.Add   52, "Mexico"
  57. 	dctCountryCodes.Add   53, "Cuba"
  58. 	dctCountryCodes.Add   54, "Argentina"
  59. 	dctCountryCodes.Add   55, "Brazil"
  60. 	dctCountryCodes.Add   56, "Chile"
  61. 	dctCountryCodes.Add   57, "Colombia"
  62. 	dctCountryCodes.Add   58, "Venezuela"
  63. 	dctCountryCodes.Add   60, "Malaysia"
  64. 	dctCountryCodes.Add   61, "Australia"
  65. 	dctCountryCodes.Add   62, "Indonesia"
  66. 	dctCountryCodes.Add   63, "Philippines"
  67. 	dctCountryCodes.Add   64, "New Zealand"
  68. 	dctCountryCodes.Add   65, "Singapore"
  69. 	dctCountryCodes.Add   66, "Thailand"
  70. 	dctCountryCodes.Add   81, "Japan"
  71. 	dctCountryCodes.Add   82, "Korea"
  72. 	dctCountryCodes.Add   84, "Viet Nam"
  73. 	dctCountryCodes.Add   86, "China"
  74. 	dctCountryCodes.Add   90, "Turkey"
  75. 	dctCountryCodes.Add   91, "India"
  76. 	dctCountryCodes.Add   92, "Pakistan"
  77. 	dctCountryCodes.Add   93, "Afghanistan"
  78. 	dctCountryCodes.Add   94, "Sri Lanka"
  79. 	dctCountryCodes.Add   95, "Myanmar"
  80. 	dctCountryCodes.Add   98, "Iran"
  81. 	dctCountryCodes.Add  101, "Anguilla"
  82. 	dctCountryCodes.Add  102, "Antigua and Barbuda"
  83. 	dctCountryCodes.Add  103, "The Bahamas"
  84. 	dctCountryCodes.Add  104, "Barbados"
  85. 	dctCountryCodes.Add  105, "Bermuda"
  86. 	dctCountryCodes.Add  106, "British Virgin Islands"
  87. 	dctCountryCodes.Add  108, "Cayman Islands"
  88. 	dctCountryCodes.Add  109, "Dominica"
  89. 	dctCountryCodes.Add  110, "Dominican Republic"
  90. 	dctCountryCodes.Add  111, "Grenada"
  91. 	dctCountryCodes.Add  112, "Jamaica"
  92. 	dctCountryCodes.Add  113, "Montserrat"
  93. 	dctCountryCodes.Add  115, "St. Kitts and Nevis"
  94. 	dctCountryCodes.Add  116, "St. Vincent and the Grenadines"
  95. 	dctCountryCodes.Add  117, "Trinidad and Tobago"
  96. 	dctCountryCodes.Add  118, "Turks and Caicos Islands"
  97. 	dctCountryCodes.Add  120, "Antigua and Barbuda"
  98. 	dctCountryCodes.Add  121, "Puerto Rico"
  99. 	dctCountryCodes.Add  122, "St. Lucia"
  100. 	dctCountryCodes.Add  123, "Virgin Islands"
  101. 	dctCountryCodes.Add  124, "Guam"
  102. 	dctCountryCodes.Add  212, "Morocco"
  103. 	dctCountryCodes.Add  213, "Algeria"
  104. 	dctCountryCodes.Add  216, "Tunisia"	
  105. 	dctCountryCodes.Add  218, "Libya"
  106. 	dctCountryCodes.Add  220, "Gambia"
  107. 	dctCountryCodes.Add  221, "Senegal"
  108. 	dctCountryCodes.Add  222, "Mauritania"
  109. 	dctCountryCodes.Add  223, "Mali"
  110. 	dctCountryCodes.Add  224, "Guinea"
  111. 	dctCountryCodes.Add  225, "C“te d'Ivoire"
  112. 	dctCountryCodes.Add  226, "Burkina Faso"
  113. 	dctCountryCodes.Add  227, "Niger"
  114. 	dctCountryCodes.Add  228, "Togo"
  115. 	dctCountryCodes.Add  229, "Benin"
  116. 	dctCountryCodes.Add  230, "Mauritius"
  117. 	dctCountryCodes.Add  231, "Liberia"
  118. 	dctCountryCodes.Add  232, "Sierra Leone"
  119. 	dctCountryCodes.Add  233, "Ghana"
  120. 	dctCountryCodes.Add  234, "Nigeria"
  121. 	dctCountryCodes.Add  235, "Chad"
  122. 	dctCountryCodes.Add  236, "Central African Republic"
  123. 	dctCountryCodes.Add  237, "Cameroon"
  124. 	dctCountryCodes.Add  238, "Cape Verde"
  125. 	dctCountryCodes.Add  239, "SÆo Tom‚ and Pr¡ncipe"
  126. 	dctCountryCodes.Add  240, "Equatorial Guinea"
  127. 	dctCountryCodes.Add  241, "Gabon"
  128. 	dctCountryCodes.Add  242, "Congo"
  129. 	dctCountryCodes.Add  243, "Congo (DRC)"
  130. 	dctCountryCodes.Add  244, "Angola"
  131. 	dctCountryCodes.Add  245, "Guinea-Bissau"
  132. 	dctCountryCodes.Add  246, "Diego Garcia"
  133. 	dctCountryCodes.Add  247, "Ascension Island"
  134. 	dctCountryCodes.Add  248, "Seychelles"
  135. 	dctCountryCodes.Add  249, "Sudan"
  136. 	dctCountryCodes.Add  250, "Rwanda"
  137. 	dctCountryCodes.Add  251, "Ethiopia"
  138. 	dctCountryCodes.Add  252, "Somalia"
  139. 	dctCountryCodes.Add  253, "Djibouti"
  140. 	dctCountryCodes.Add  254, "Kenya"
  141. 	dctCountryCodes.Add  255, "Tanzania"
  142. 	dctCountryCodes.Add  256, "Uganda"
  143. 	dctCountryCodes.Add  257, "Burundi"
  144. 	dctCountryCodes.Add  258, "Mozambique"
  145. 	dctCountryCodes.Add  260, "Zambia"
  146. 	dctCountryCodes.Add  261, "Madagascar"
  147. 	dctCountryCodes.Add  262, "Reunion"
  148. 	dctCountryCodes.Add  263, "Zimbabwe"
  149. 	dctCountryCodes.Add  264, "Namibia"
  150. 	dctCountryCodes.Add  265, "Malawi"
  151. 	dctCountryCodes.Add  266, "Lesotho"
  152. 	dctCountryCodes.Add  267, "Botswana"
  153. 	dctCountryCodes.Add  268, "Swaziland"
  154. 	dctCountryCodes.Add  269, "Mayotte"
  155. 	dctCountryCodes.Add  290, "St. Helena"
  156. 	dctCountryCodes.Add  291, "Eritrea"
  157. 	dctCountryCodes.Add  297, "Aruba"
  158. 	dctCountryCodes.Add  298, "Faroe Islands"
  159. 	dctCountryCodes.Add  299, "Greenland"
  160. 	dctCountryCodes.Add  350, "Gibraltar"
  161. 	dctCountryCodes.Add  351, "Portugal"
  162. 	dctCountryCodes.Add  352, "Luxembourg"
  163. 	dctCountryCodes.Add  353, "Ireland"
  164. 	dctCountryCodes.Add  354, "Iceland"
  165. 	dctCountryCodes.Add  355, "Albania"
  166. 	dctCountryCodes.Add  356, "Malta"
  167. 	dctCountryCodes.Add  357, "Cyprus"
  168. 	dctCountryCodes.Add  358, "Finland"
  169. 	dctCountryCodes.Add  359, "Bulgaria"
  170. 	dctCountryCodes.Add  370, "Lithuania"
  171. 	dctCountryCodes.Add  371, "Latvia"
  172. 	dctCountryCodes.Add  372, "Estonia"
  173. 	dctCountryCodes.Add  373, "Moldova"
  174. 	dctCountryCodes.Add  374, "Armenia"
  175. 	dctCountryCodes.Add  375, "Belarus"
  176. 	dctCountryCodes.Add  376, "Andorra"
  177. 	dctCountryCodes.Add  377, "Monaco"
  178. 	dctCountryCodes.Add  378, "San Marino"
  179. 	dctCountryCodes.Add  379, "Vatican City"
  180. 	dctCountryCodes.Add  380, "Ukraine"
  181. 	dctCountryCodes.Add  381, "Yugoslavia"
  182. 	dctCountryCodes.Add  385, "Croatia"
  183. 	dctCountryCodes.Add  386, "Slovenia"
  184. 	dctCountryCodes.Add  387, "Bosnia and Herzegovina"
  185. 	dctCountryCodes.Add  389, "Macedonia"
  186. 	dctCountryCodes.Add  420, "Czech Republic"
  187. 	dctCountryCodes.Add  421, "Slovakia"
  188. 	dctCountryCodes.Add  423, "Liechtenstein"
  189. 	dctCountryCodes.Add  500, "Falkland Islands (Islas Malvinas)"
  190. 	dctCountryCodes.Add  501, "Belize"
  191. 	dctCountryCodes.Add  502, "Guatemala"
  192. 	dctCountryCodes.Add  503, "El Salvador"
  193. 	dctCountryCodes.Add  504, "Honduras"
  194. 	dctCountryCodes.Add  505, "Nicaragua"
  195. 	dctCountryCodes.Add  506, "Costa Rica"
  196. 	dctCountryCodes.Add  507, "Panama"
  197. 	dctCountryCodes.Add  508, "St. Pierre and Miquelon"
  198. 	dctCountryCodes.Add  509, "Haiti"
  199. 	dctCountryCodes.Add  590, "Guadeloupe"
  200. 	dctCountryCodes.Add  591, "Bolivia"
  201. 	dctCountryCodes.Add  592, "Guyana"
  202. 	dctCountryCodes.Add  593, "Ecuador"
  203. 	dctCountryCodes.Add  594, "French Guiana"
  204. 	dctCountryCodes.Add  595, "Paraguay"
  205. 	dctCountryCodes.Add  596, "Martinique"
  206. 	dctCountryCodes.Add  597, "Suriname"
  207. 	dctCountryCodes.Add  598, "Uruguay"
  208. 	dctCountryCodes.Add  599, "Netherlands Antilles"
  209. 	dctCountryCodes.Add  670, "East Timor"
  210. 	dctCountryCodes.Add  672, "Norfolk Island"
  211. 	dctCountryCodes.Add  673, "Brunei"
  212. 	dctCountryCodes.Add  674, "Nauru"
  213. 	dctCountryCodes.Add  675, "Papua New Guinea"
  214. 	dctCountryCodes.Add  676, "Tonga"
  215. 	dctCountryCodes.Add  677, "Solomon Islands"
  216. 	dctCountryCodes.Add  678, "Vanuatu"
  217. 	dctCountryCodes.Add  679, "Fiji Islands"
  218. 	dctCountryCodes.Add  680, "Palau"
  219. 	dctCountryCodes.Add  681, "Wallis and Futuna"
  220. 	dctCountryCodes.Add  682, "Cook Islands"
  221. 	dctCountryCodes.Add  683, "Niue"
  222. 	dctCountryCodes.Add  684, "American Samoa"
  223. 	dctCountryCodes.Add  685, "Samoa"
  224. 	dctCountryCodes.Add  686, "Kiribati"
  225. 	dctCountryCodes.Add  687, "New Caledonia"
  226. 	dctCountryCodes.Add  688, "Tuvalu"
  227. 	dctCountryCodes.Add  689, "French Polynesia"
  228. 	dctCountryCodes.Add  690, "Tokelau"
  229. 	dctCountryCodes.Add  691, "Micronesia"
  230. 	dctCountryCodes.Add  692, "Marshall Islands"
  231. 	dctCountryCodes.Add  705, "Kazakhstan"
  232. 	dctCountryCodes.Add  850, "North Korea"
  233. 	dctCountryCodes.Add  852, "Hong Kong SAR"
  234. 	dctCountryCodes.Add  853, "Macau SAR"
  235. 	dctCountryCodes.Add  855, "Cambodia"
  236. 	dctCountryCodes.Add  856, "Laos"
  237. 	dctCountryCodes.Add  880, "Bangladesh"
  238. 	dctCountryCodes.Add  886, "Taiwan"
  239. 	dctCountryCodes.Add  960, "Maldives"
  240. 	dctCountryCodes.Add  961, "Lebanon"
  241. 	dctCountryCodes.Add  962, "Jordan"
  242. 	dctCountryCodes.Add  963, "Syria"
  243. 	dctCountryCodes.Add  964, "Iraq"
  244. 	dctCountryCodes.Add  965, "Kuwait"
  245. 	dctCountryCodes.Add  966, "Saudi Arabia"
  246. 	dctCountryCodes.Add  967, "Yemen"
  247. 	dctCountryCodes.Add  968, "Oman"
  248. 	dctCountryCodes.Add  971, "United Arab Emirates"
  249. 	dctCountryCodes.Add  972, "Israel"
  250. 	dctCountryCodes.Add  973, "Bahrain"
  251. 	dctCountryCodes.Add  974, "Qatar"
  252. 	dctCountryCodes.Add  975, "Bhutan"
  253. 	dctCountryCodes.Add  976, "Mongolia"
  254. 	dctCountryCodes.Add  977, "Nepal"
  255. 	dctCountryCodes.Add  992, "Tajikistan"
  256. 	dctCountryCodes.Add  993, "Turkmenistan"
  257. 	dctCountryCodes.Add  994, "Azerbaijan"
  258. 	dctCountryCodes.Add  995, "Georgia"
  259. 	dctCountryCodes.Add  996, "Kyrgyzstan"
  260. 	dctCountryCodes.Add  998, "Uzbekistan"
  261. 	dctCountryCodes.Add 2691, "Comoros"
  262. 	dctCountryCodes.Add 5399, "Guantanamo Bay"
  263. 	dctCountryCodes.Add 6101, "Cocos (Keeling) Islands"
  264.  
  265. 	If numCountry < 1 Then
  266. 		Set wshShell = CreateObject( "Wscript.Shell" )
  267. 		numCountry = wshShell.RegRead( "HKEY_CURRENT_USER\Control Panel\International\iCountry" )
  268. 		Set wshShell = Nothing
  269. 		If IsNumeric( numCountry ) Then numCountry = CInt( numCountry )
  270. 	End If
  271.  
  272. 	Country = dctCountryCodes( numCountry )
  273.  
  274. 	Set dctCountryCodes = Nothing
  275. End Function
  276.  
  277.  
  278. Sub Syntax
  279. 	Dim strMsg
  280. 	strMsg = vbcrlf _
  281. 	       & "iCountry.vbs,  Version 1.01" _
  282. 	       & vbCrLf _
  283. 	       & "Return the (English) country name for the specified numeric country code" _
  284. 	       & vbCrLf & vbCrLf _
  285. 	       & "Usage:  CSCRIPT  //NoLogo  ICOUNTRY.VBS  nn" _
  286. 	       & vbCrLf & vbCrLf _
  287. 	       & "Where:  ""nn""  is either a numeric country code as found in the Windows registry" _
  288. 	       & vbCrLf _
  289. 	       & "              value HKEY_CURRENT_USER\Control Panel\International\iCountry, or" _
  290. 	       & vbCrLf _
  291. 	       & "              0 to use that same registry value from the local computer" _
  292. 	       & vbCrLf & vbCrLf _
  293. 	       & "Written by Rob van der Woude" _
  294. 	       & vbCrLf _
  295. 	       & "http://www.robvanderwoude.com"
  296. 	WScript.Echo strMsg
  297. 	WScript.Quit 1
  298. End Sub
  299.  

page last modified: 2024-04-16; loaded in 0.0158 seconds