public static Forest GetForest(string domain, string username, string password) { Forest forest = null; DirectoryContext contextForest = AD.GetContext(DirectoryContextType.Forest, domain, username, password); try { forest = Forest.GetForest(contextForest); } catch (Exception ex) { MessageBox.Show(ex.Message, "Error getting forest", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } return(forest); }