Upgrading a Domain Controller from Windows Server 2008 to 2012

Windows Server logo

When upgrading an Active Directory Domain Controller from Windows Server 2008 (or 2008 R2) to Windows Server 2012, the AD Forest must be upgraded first.  This has to be manually done, as it is not part of the setup process.

To upgrade the AD Forest, right-click on the Command Prompt icon and select “Run as Administrator”.  Insert the Windows Server 2012 DVD (or mount the ISO using a virtual drive) and switch to that drive inside Command Prompt: “cd [Drive letter]: <ENTER>“.

At the command prompt, type “[Drive letter]:supportadprep /forestprep <ENTER>“.  You will be given a warning about how this is not a reversible operation.  Type “C” and hit <ENTER> to continue.  Once this is done, type “[Drive letter]:supportadprep /domainprep <ENTER>“.

After this step is complete, you may proceed with the upgrade to Windows Server 2012.

Check / Uncheck All Child Nodes and Uncheck Parent Node in TreeView

Visual Basic logo

As mentioned in my last post, I am working with a TreeView control that has been upgraded from VB6 to Visual Basic .NET (2012).  To programmatically cause the TreeNodes to be checked/unchecked properly, we must use the AfterCheck event.  Here is the code which is called from the AfterCheck event:

Public Sub CheckChildNodes(ByVal iNode As TreeNode)
Try
UnCheckParentNodes(iNode)
For Each sNode As TreeNode In iNode.Nodes
sNode.Checked = iNode.Checked
CheckChildNodes(sNode)
Next
Catch ex As Exception
End Try
End Sub

Public Sub UnCheckParentNodes(ByVal iNode As TreeNode)
Try
If iNode.Checked = False AndAlso iNode.Parent IsNot Nothing Then
iNode.Parent.Checked = False
UnCheckParentNodes(iNode.Parent)
End If
Catch ex As Exception
End Try
End Sub

And here is the code in the AfterCheck event that calls the above code:

Private Sub tvwDataCategory_AfterCheck(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.TreeViewEventArgs) Handles tvwDataCategory.AfterCheck
If eventArgs.Action = TreeViewAction.ByKeyboard Or eventArgs.Action = TreeViewAction.ByMouse Then
CheckChildNodes(eventArgs.Node)
End If
End Sub

Differences between the VB6 TreeNode and .NET System.Windows.Forms.TreeNode

Visual Basic logo

In working on the conversion of a VB6 Forms application to VB.NET (as mentioned in my last post), I have discovered many instances where Microsoft decided to keep the name (and sometimes even the associated syntax) of an element, while changing the functionality of the methods related to that element.
One such example is that of the TreeView and its TreeNodes.

In the VB6 application, the code associated with the NodeCheck event was written like this:

Private Sub tvwDataCategory_NodeCheck(ByVal Node As MSComctlLib.Node)
Dim n As Integer

If Left(Node.Key, cTagLength) = cDataTypeTag Then
Node.ForeColor = DefaultForeColor
If Node.Children <> 0 Then
n = Node.Child.Index
While n <> Node.Child.LastSibling.Index
If Node.Checked Then
tvwDataCategory.Nodes(n).Checked = True
Else
tvwDataCategory.Nodes(n).Checked = False
End If
n = tvwDataCategory.Nodes(n).Next.Index
Wend
If Node.Checked Then
tvwDataCategory.Nodes(n).Checked = True
Else
tvwDataCategory.Nodes(n).Checked = False
End If
End If

Else
Call FormatChecks
End If

End Sub

Even after running the VB6 code through the Visual Studio upgrade wizard, the resulting code did not work as it did before.  The NodeCheck event in VB6 has become the AfterCheck event in .NET, and the new code should read something like this:

Private Sub tvwDataCategory_AfterCheck(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.TreeViewEventArgs) Handles tvwDataCategory.AfterCheck
Dim Node As System.Windows.Forms.TreeNode = eventArgs.Node
Dim n As Integer

If VB.Left(Node.Name, cTagLength) = cDataTypeTag Then
Node.ForeColor = DefaultForeColor

Dim nNodes As TreeNodeCollection = eventArgs.Node.Nodes

For Each nNode As TreeNode In nNodes
If nNodes.Count = 0 Then
If nNode.Checked Then
tvwDataCategory.Nodes.Item(n).Checked = True
Else
tvwDataCategory.Nodes.Item(n).Checked = False
End If
End If
Next
Else
Call FormatChecks()
End If
End Sub

I am still working to verify that this will traverse the entire node and all child branches.  As the FirstSibling and LastSibling functions have been made obsolete, new code must be written to duplicate that functionality.  The adventure continues…