?
Solved

vbs active directory country code

Posted on 2008-11-07
4
Medium Priority
?
1,019 Views
Last Modified: 2013-12-24
Hi,
I am modifying user accounts with a vbs script.
I would like to query the AD Schema to get a list of all the availiable country codes and the Country names in AD.

0
Comment
Question by:coolrod_de
  • 3
4 Comments
 
LVL 65

Accepted Solution

by:
RobSampson earned 375 total points
ID: 22910076
Hi, Active Directory follows the ISO country codes for the Country property.
http://www.iso.org/iso/english_country_names_and_code_elements

Regards,

Rob.
0
 

Author Comment

by:coolrod_de
ID: 22921417
Hi,
Thanks, but seeing as the Country Code and Name (in istallation Language) must be in AD, I was hoping to Build a Dictionary Object and then Look for the Name, dicCounties.exists and then Idetify the Country Code. I would prefer to write a Query and loop rather than 180 Lines of dicCountries.add "DE","Germany"....
0
 
LVL 65

Expert Comment

by:RobSampson
ID: 22926687
OK, in that case, I've created a reasonably workable solution for you.

From a computer with Internet access, you can get a generated CountryCodes.txt file by using this script.

.....
'Retrieve_Country_Codes_From_Web_To_Text_File.vbs
strURL = "http://www.iso.org/iso/english_country_names_and_code_elements"
strOutputFile = "CountryCodes.txt"
Set objHTTP = CreateObject("MSXML2.XMLHTTP") 
objHTTP.Open "GET", strURL, False
objHTTP.Send
 
strResults = ""
strPageText = Replace(Replace(Replace(objHTTP.responseText, VbCrLf, ""), VbLf, ""), vbTab, "")
intPos = InStr(strPageText, "<strong>A</strong><a name=""a..""></a>")
If intPos > 0 Then
	strPageText = Mid(strPageText, intPos)
	While strPageText <> ""
		strPageText = Mid(strPageText, InStr(strPageText, "</tr>") + 5)
		intPos = InStr(strPageText, "<td ")
		If intPos > 0 Then
			strPageText = Mid(strPageText, intPos + 4)
			strPageText = Mid(strPageText, InStr(strPageText, ">") + 1)
			strCountry = Trim(Left(strPageText, InStr(strPageText, "<") - 1))
			strPageText = Mid(strPageText, InStr(strPageText, "<td ") + 4)
			strPageText = Mid(strPageText, InStr(strPageText, ">") + 1)
			strCode = Trim(Left(strPageText, InStr(strPageText, "<") - 1))
			If strResults = "" Then
				If strCode <> "&nbsp;" And strCode <> "" Then strResults = strResults & strCountry & "|" & strCode
			Else
				If strCode <> "&nbsp;" And strCode <> "" Then strResults = strResults & VbCrLf & strCountry & "|" & strCode
			End If
		Else
			strPageText = ""
		End If
	Wend
End If
 
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objOutputFile = objFSO.CreateTextFile(strOutputFile, True)
objOutputFile.Write strResults
objOutputFile.Close
Set objOutputFile = Nothing
 
MsgBox "Done."

Open in new window

0
 
LVL 65

Expert Comment

by:RobSampson
ID: 22926694

......

then you can use this script, to read that text file into a dictionary object, and query it.

Regards,

Rob.
'Put_Country_Codes_From_Text_File_Into_Dictionary_Object.vbs
'requires
'Retrieve_Country_Codes_From_Web_To_Text_File.vbs
 
strInputFile = "CountryCodes.txt"
Set objDict = CreateObject("Scripting.Dictionary")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Const intForReading = 1
Set objInputFile = objFSO.OpenTextFile(strInputFile, intForReading, False)
While Not objInputFile.AtEndOfStream
	strLine = objInputFile.ReadLine
	strCounty = UCase(Split(strLine, "|")(0))
	strCode = UCase(Split(strLine, "|")(1))
	objDict.Add strCounty, strCode
Wend
objInputFile.Close
Set objInputFile = Nothing
 
strCountry = InputBox("Which country to do you want to get the code for?", "Country Name", "Australia")
If objDict.Exists(UCase(strCountry)) = True Then
	strCode = objDict(UCase(strCountry))
Else
	strCode = "ZZ"
End If
 
MsgBox strCode

Open in new window

0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This post looks at MongoDB and MySQL, and covers high-level MongoDB strengths, weaknesses, features, and uses from the perspective of an SQL user.
One of the most important things in an application is the query performance. This article intends to give you good tips to improve the performance of your queries.
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
Suggested Courses

750 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question