Adding Custom Information to ADUC






Adding Custom Information to ADUC

Problem

You want schema information that you've created to be visible in the ADUC snap-in.

Solution

Using VBScript
	Set oFileSystem = WScript.CreateObject("Scripting.FileSystemObject")
	sSystemFolder = oFileSystem.GetSpecialFolder(1)
	set oRootDSE = Getobject("LDAP://RootDSE")

	' The display specifier for US English is 409; modify this
	' for another locale if necessary.
	set oCont = GetObject("LDAP://" & "CN=409, CN=DisplaySpecifiers," &
	oRootDSE.get("configurationNamingContext"))
	Set oDisplay = oCont.GetObject("displaySpecifier","cn=user-Display")

	'Add Attribute Display Names
	oDisp.PutEx 3,"attributeDisplayNames" , Array("BudgetCode,BudgetCode")
	oDisp.SetInfo

	'Add this field to the Right-Click Context Menu
	iCount = 0
	If Not IsEmpty(oDisp.shellContextMenu) Then
	  aMenu = oDisp.GetEx("shellContextMenu")
	  iCount = iCount + 1
	End If
	sNewMenu = CStr(iCount) & ",&Budget code…,budgetshell.vbs"
	oDisp.PutEx 3,"shellContextMenu" , Array(sNewMenu)
	oDisp.SetInfo
	Set sOutFile = oFileSystem.CreateTextFile(sSystemFolder & "\budgetshell.vbs",True)
	sOutFile.WriteLine "Set Args = Wscript.Arguments"
	sOutFile.WriteLine "Set oUser = GetObject(Args(0))"
	sOutFile.WriteLine "MsgBox " & Chr(34) & "Budget Code" & Chr(34) & " & vbCRLF & " &
	Chr(34) & "Budget Code: " & Chr(34) & " & oUser.BudgetCode & vbCRLF & " & Chr(34)
	sOutFile.WriteLine "Set oUser = Nothing"
	sOutFile.WriteLine "WScript.Quit"
	sOutFile.Close
	'Allow for updates
	iCount = 0
	If Not IsEmpty(oDisp.adminContextMenu) Then
	  aMenu = oDisp.GetEx("adminContextMenu")
	  iCount = iCount + 1
	End If
	sNewMenu = CStr(iCount) & ",&Budget Code…,budgetadmin.vbs"
	oDisp.PutEx 3,"adminContextMenu" , Array(sNewMenu)
	oDisp.SetInfo
	MsgBox " 
Adding Admin Context Menu Program"
	Set sOutFile = oFileSystem.CreateTextFile(sSystemFolder & "\budgetadmin.vbs",True)
	sOutFile.WriteLine "Set Args = Wscript.Arguments"
	sOutFile.WriteLine "Set oUser = GetObject(Args(0))"
	sOutFile.WriteLine "temp = InputBox(" & Chr(34) & "Current Budget Code: " & Chr(34) &
	" & oUser.BudgetCode & vbCRLF & " & Chr(34) & "New Budget Code" & Chr(34) & ")"
	sOutFile.WriteLine "if temp <> " & Chr(34) & Chr(34) & " then oUser.Put " & Chr(34) &
	"BudgetCode" & Chr(34) & ",temp"
	sOutFile.WriteLine "oUser.SetInfo"
	sOutFile.WriteLine "Set oUser = Nothing"
	sOutFile.WriteLine "WScript.Quit"
	sOutFile.Close
	Set oDisp = Nothing
	Set oCont = Nothing
	Set oRoot = Nothing
	Set oFileSystem = Nothing
	WScript.Quit

It's important that you run the script listed in this recipe only one time; otherwise you may wind up with duplicate entries in the ADUC context menu.


Discussion

Modifying the default MMC snap-ins is a nontrivial task, but it can be accomplished using VBScript to add information to the display specifiers in the Configuration NC. Let's say that you've extended the user class in your forest with an auxiliary class that stores the user's budget code for their expense reports, and you want to be able to view and edit this information using ADUC. You can create a VBScript that will display and modify this information from the right-click context menu, as shown in this recipe.

Another option would be to create a VBScript file that simply displays the necessary message boxes to display and/or update the user attribute in question, after which you could use ADSI Edit or AdMod to configure your display specifiers to call that script whenever appropriate.

If you saved such a script to the \\dc1\share\updatebudget.vbs path, for example, you could then add the following information to the adminContextMenu attribute of cn=user-Display,cn=409,cn=DisplaySpecifiers,cn=Configuration,<ForestRootDN>:

	4, &Update Budget Information,\\dc1\share\updatebudget.vbs

See Also

MSDN: Display Specifiers and MS KB 299646 (How to Add Custom Attributes to the DSFind Pick list)



 Python   SQL   Java   php   Perl 
 game development   web development   internet   *nix   graphics   hardware 
 telecommunications   C++ 
 Flash   Active Directory   Windows