using System; using System.Collections; using System.Collections.Generic; using System.Collections.Specialized; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.IO; using System.Security.AccessControl; using System.Text.RegularExpressions; using System.DirectoryServices; using System.Threading; using System.Diagnostics; using System.Globalization; using System.Deployment; using System.Reflection; //using Excel = Microsoft.Office.Interop.Excel; namespace Permissions { public partial class Form1 : Form { // CONFIGURATION int optionsToggleMove = 28; int debugPanelMove = 333; string LDAPDirEnt = "LDAP://DC=domain,DC=local"; // TODO: Obsolete? string getUserInfo = "sAMAccountName"; // TODO: Make configurable through UI string ignoreGroupNameBegin = "BUILTIN,LOCAL,NT AUTHORITY,SYSTEM,S-"; // TODO: Make configurable through UI public static string startFolder = @""; // TODO: Obsolete, remove all references int maxDirDepth = 1; // END CONFIGURATION string groupNameStripBegin = Environment.UserDomainName + @"\"; string permInfo = ""; int resultCount = 0; Dictionary groupHist = new Dictionary(); ArrayList groupNames = new ArrayList(); Dictionary groupsAndMembers = new Dictionary(); public static ArrayList folderList = new ArrayList(); public static ArrayList folderListTemp = new ArrayList(); public static ArrayList debugInfo = new ArrayList(); // GUI public Form1() { InitializeComponent(); string currentVersion = Application.ProductVersion.ToString(); version_lbl.Text = "v" + currentVersion; updateDebugInfo("Function InitializeComponent() called"); this.KeyPreview = true; this.Height = this.Height - optionsToggleMove; result_panel.Location = new Point(result_panel.Location.X, result_panel.Location.Y - optionsToggleMove); this.Width = this.Width - debugPanelMove; label3.Text = ""; saveAs_bttn.Enabled = false; clear_bttn.Enabled = false; startTime_label.Text = ""; endTime_label.Text = ""; Folder_textbox.Text = ""; results_textbox.Text = resultCount.ToString(); tabControl1.TabPages.Remove(homeDir); updateDebugInfo("Program started"); updateDebugInfo("Version: " + currentVersion); } public void UnhandledThreadExceptionHandler(object sender, ThreadExceptionEventArgs e) { this.HandleUnhandledException(e.Exception); } public void HandleUnhandledException(Exception e, bool ShowMessageBox = false) { // do what you want here. updateDebugInfo("---------------------------"); updateDebugInfo("Unhandeled exeption:"); updateDebugInfo(e.Message); updateDebugInfo("---------------------------"); if (ShowMessageBox == true) { if (MessageBox.Show("An unexpected error has occurred. Continue?", "My application", MessageBoxButtons.YesNo, MessageBoxIcon.Stop, MessageBoxDefaultButton.Button2) == DialogResult.No) { Application.Exit(); } } } private void controlsEnabled(bool enabled) { updateDebugInfo("Function controlsEnabled(bool " + enabled + ") called"); saveAs_bttn.Enabled = enabled; clear_bttn.Enabled = enabled; getPermissions_bttn.Enabled = enabled; getPermissions_bttn.Visible = enabled; skipDoubleGroup_chkBox.Enabled = enabled; ignorePassGroups_chkBox.Enabled = enabled; onlyLeesGebr_chkBox.Enabled = enabled; recusive_chkBox.Enabled = enabled; getOwnerGroup_chkBox.Enabled = enabled; multiPath_bttn.Enabled = enabled; maxLvl_numud.Enabled = enabled; if (folderListTemp.Count < 2) { path_panel.Enabled = enabled; } } public void startScan() { updateDebugInfo("Function startScan() called"); updateDebugInfo("Scan options:"); updateDebugInfo("Recursive: " + recusive_chkBox.Checked); updateDebugInfo("Recursive levels: " + maxLvl_numud.Value); updateDebugInfo("Ignore __pass groups: " + ignorePassGroups_chkBox.Checked); updateDebugInfo("Skip double groups: " + skipDoubleGroup_chkBox.Checked); updateDebugInfo("Only __lees && __gebr groups: " + onlyLeesGebr_chkBox.Checked); updateDebugInfo("Get __eign group members: " + getOwnerGroup_chkBox.Checked); if (upDateDebugLog.IsBusy) { upDateDebugLog.CancelAsync(); pauseDebug_bttn.Text = "Scan running"; pauseDebug_bttn.Enabled = false; updateDebugInfo("Pausing debug background worker to prevent conflicts between worker threads"); }; loading_pic_visible(true); cancel_bttn.Visible = true; cancel_bttn.Enabled = true; folderListTemp.Clear(); controlsEnabled(false); mainProgressBar.Visible = true; startTime_label.Text = DateTime.Now.Hour.ToString() + ":" + DateTime.Now.Minute.ToString() + ":" + DateTime.Now.Second.ToString(); } public void endScan() { updateDebugInfo("Function endScan() called"); loading_pic_visible(false); cancel_bttn.Visible = false; cancel_bttn.Enabled = false; mainProgressBar.Visible = false; controlsEnabled(true); groupHist.Clear(); label3.Text = ""; endTime_label.Text = DateTime.Now.Hour.ToString() + ":" + DateTime.Now.Minute.ToString() + ":" + DateTime.Now.Second.ToString(); if (pauseDebug_bttn.Enabled == false && pauseDebug_bttn.Text == "Scan running") { upDateDebugLog.RunWorkerAsync(); pauseDebug_bttn.Text = "Pause debugger"; pauseDebug_bttn.Enabled = true; }; } private void updateResults(int resultCount) { results_textbox.Text = resultCount.ToString(); } public delegate void updateResultsCallback(int resultCount); private void updateRichTextBox1(string txt) { richTextBox1.Text = txt; } public delegate void updateRichTextBox1Callback(string txt); private void updateDebug_rtextbox(string txt) { if (txt != debug_rtextbox.Text) { debug_rtextbox.Text = txt; } } public delegate void updateDebug_rtextboxCallback(string txt); private void updateDataGridView1(string dataGridInfo) { string[] dataGridInfo2 = dataGridInfo.Split('|'); dataGridView1.Rows.Add(dataGridInfo2[0], dataGridInfo2[1], dataGridInfo2[2]); } public delegate void updateDataGridView1Callback(string dataGridInfo); private void updateLabel3(string txt) { label3.Text = txt; } public delegate void updateLabel3Callback(string text); private void loading_pic_visible(bool visible) { loading_pic.Visible = visible; } public delegate void loading_pic_visibleCallback(bool visible); private void mainProgressBar_update(int Current, bool visible) { mainProgressBar.Value = Current; mainProgressBar.Visible = visible; } public delegate void mainProgressBar_updateCallback(int Current, bool visible); private void mainProgressBar_setMax(int Max) { mainProgressBar.Maximum = Max; } public delegate void mainProgressBar_setMaxCallback(int Max); private void updateMemUsage_lbl(string txt) { memUsage_lbl.Text = txt; } public delegate void updateMemUsage_lblCallback(string text); public void toggleDebugPanelVisible() { if (debug_panel.Visible == false) { this.Width = this.Width + debugPanelMove; debug_panel.Visible = true; updateDebugInfo("Debug panel opened"); upDateDebugLog.RunWorkerAsync(); updateDebugInfo("Debug background worker started"); tabControl1.TabPages.Add(homeDir); } else if (debug_panel.Visible == true) { this.Width = this.Width - debugPanelMove; debug_panel.Visible = false; updateDebugInfo("Debug panel closed"); if (upDateDebugLog.IsBusy) { upDateDebugLog.CancelAsync(); }; updateDebugInfo("Debug background worker stopped"); tabControl1.TabPages.Remove(homeDir); } } public void toggleCSVvisible() { if (dataGridView1.Visible == true) { dataGridView1.Visible = false; } else { dataGridView1.Visible = true; } } // GUI controls private void cancel_bttn_Click(object sender, EventArgs e) { updateDebugInfo("cancel_bttn was clicked"); label3.Text = "Cancelling..."; if (getPermissionsRecursive.IsBusy) { getPermissionsRecursive.CancelAsync(); }; cancel_bttn.Enabled = false; } private void options_link_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) { updateDebugInfo("options_Link was clicked"); if (options_panel.Visible) { updateDebugInfo("Disabling options panel"); options_panel.Visible = false; options_link.Text = "-------------- Show options --------------"; //this.Height = this.Height - optionsToggleMove; result_panel.Height = result_panel.Height + optionsToggleMove; dataGridView1.Height = dataGridView1.Height + optionsToggleMove; richTextBox1.Height = richTextBox1.Height + optionsToggleMove; result_panel.Location = new Point(result_panel.Location.X, result_panel.Location.Y - optionsToggleMove); } else { updateDebugInfo("Enabling options panel"); options_panel.Visible = true; options_link.Text = "-------------- Hide options ---------------"; //this.Height = this.Height + optionsToggleMove; result_panel.Height = result_panel.Height - optionsToggleMove; dataGridView1.Height = dataGridView1.Height - optionsToggleMove; richTextBox1.Height = richTextBox1.Height - optionsToggleMove; result_panel.Location = new Point(result_panel.Location.X, result_panel.Location.Y + optionsToggleMove); }; } private void saveAs_bttn_Click(object sender, EventArgs e) { updateDebugInfo("saveAs_bttn was clicked"); if (results_textbox.Text != "0" && results_textbox.Text != "") { string savedFile = ""; saveFD.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop); saveFD.Title = "Save as..."; saveFD.FileName = "permissions"; saveFD.Filter = "Excel Files|*.xls|CSV Files|*.csv|TXT Files|*.txt"; if (saveFD.ShowDialog() != DialogResult.Cancel) { savedFile = saveFD.FileName; controlsEnabled(false); label3.Invoke(new updateLabel3Callback(this.updateLabel3), new object[] { "Saving file..." }); loading_pic.Invoke(new loading_pic_visibleCallback(this.loading_pic_visible), new object[] { true }); if (File.Exists(savedFile)) { File.Delete(savedFile); } //TODO: Make full use of the background worker for saving to file if (savedFile.EndsWith(".xls")) { updateDebugInfo("Saving file als .xls in " + savedFile); saveAs.RunWorkerAsync(savedFile); } else if (Path.GetExtension(savedFile).ToLower() == ".csv" || Path.GetExtension(savedFile).ToLower() == ".txt") { updateDebugInfo("Saving file als .csv in " + savedFile); saveCSV(savedFile); } else { MessageBox.Show("Unsupported file format..."); updateDebugInfo("Unsupported file format..."); } } } else { MessageBox.Show("No results"); updateDebugInfo("No results"); } } private void getPermissions_bttn_Click(object sender, EventArgs e) { updateDebugInfo("getPermissions_bttn was clicked"); scanPermissions(); } private void Folder_textbox_KeyPress(object sender, KeyPressEventArgs e) { if (e.KeyChar == (char)13) { scanPermissions(); } } private void clear_bttn_Click(object sender, EventArgs e) { updateDebugInfo("clear_bttn was clicked"); richTextBox1.Text = ""; permInfo = ""; resultCount = 0; results_textbox.Text = resultCount.ToString(); dataGridView1.Rows.Clear(); groupHist.Clear(); groupsAndMembers.Clear(); startTime_label.Text = ""; endTime_label.Text = ""; saveAs_bttn.Enabled = false; clear_bttn.Enabled = false; updateDebugInfo("All results cleared"); } private void multiPath_bttn_Click(object sender, EventArgs e) { updateDebugInfo("multiPath_bttn was clicked"); multiPath multiPathForm = new multiPath(); controlsEnabled(false); if(multiPathForm.ShowDialog() == DialogResult.OK) { controlsEnabled(true); } else { controlsEnabled(true); } updateDebugInfo("The multipath dialogue was used"); if (folderList.Count > 0) { path_panel.Enabled = false; Folder_textbox.Text = "[Multiple Folders]"; updateDebugInfo("Multipath folder count = " + folderList.Count + ""); if (folderList.Count == 1) { path_panel.Enabled = true; Folder_textbox.Text = folderList[0].ToString().Replace(startFolder, ""); updateDebugInfo("Found only 1 value in multipath array"); } } else { path_panel.Enabled = true; Folder_textbox.Text = ""; updateDebugInfo("The multipath dialogue was cancelled"); } } private void Form1_KeyDown(object sender, KeyEventArgs e) { if (e.Control && e.KeyCode == Keys.D) { updateDebugInfo("CTRL + D was pressed"); toggleDebugPanelVisible(); } } private void viewCSV_bttn_Click(object sender, EventArgs e) { toggleCSVvisible(); } private void pauseDebug_bttn_Click(object sender, EventArgs e) { if (upDateDebugLog.IsBusy) { upDateDebugLog.CancelAsync(); pauseDebug_bttn.Text = "Resume debugger"; updateDebugInfo("Debug background worker stopped"); }; if (!upDateDebugLog.IsBusy) { pauseDebug_bttn.Text = "Pause debugger"; upDateDebugLog.RunWorkerAsync(); updateDebugInfo("Debug background worker started"); }; } private void tabControl1_SelectedIndexChanged(object sender, EventArgs e) { updateDebugInfo("Selected TAB changed to: "+tabControl1.SelectedTab.ToString()); } private void recusive_chkBox_CheckedChanged(object sender, EventArgs e) { if (recusive_chkBox.Checked) { maxLvl_numud.Visible = true; label7.Visible = true; } else { maxLvl_numud.Visible = false; label7.Visible = false; } } // Functions private void scanPermissions() { updateDebugInfo("Function scanPermissions() called"); updateDebugInfo("Folder_textbox.text = " + Folder_textbox.Text + ""); if (folderList.Count == 0) { updateDebugInfo("folderList count = 0"); folderList.Add(Folder_textbox.Text); updateDebugInfo("folderList add " + Folder_textbox.Text + ""); } bool dirExists = true; foreach (string f in folderList) { if (!Directory.Exists(f)) { dirExists = false; } } if (dirExists) { updateDebugInfo("Folders in folderList exist"); startScan(); updateDebugInfo("Scanning folders:"); foreach (string f in folderList) { folderListTemp.Add(f); updateDebugInfo(" " + f + ""); } getPermissionsRecursive.RunWorkerAsync(folderListTemp); } else { MessageBox.Show("Path incorrect"); updateDebugInfo("Path incorrect!"); if (Folder_textbox.Enabled) { updateDebugInfo("Cleared folderList"); folderList.Clear(); } } } public bool ignoreGroupNamesBegin(string ignoreGroups, string ignoredGroupNameBegin) { updateDebugInfo("Function ignoreGroupNamesBegin(string " + ignoreGroups + ", string " + ignoredGroupNameBegin + ") called"); string[] ignoredGroups = ignoreGroups.Split(','); bool result = false; if (!result) { foreach (string ignoregroup in ignoredGroups) { if (!result) { if (ignoredGroupNameBegin.StartsWith(ignoregroup)) { result = true; } } } } return result; } public ArrayList splitGroupMembers(Dictionary GroupsAndMembers, string groupName) { ArrayList splitGroupMembers = new ArrayList(); if (GroupsAndMembers.ContainsKey(groupName)) { string[] s = GroupsAndMembers[groupName].Split('|'); foreach (string gm in s) { if (gm != "") { splitGroupMembers.Add(gm); } } } return splitGroupMembers; } public Dictionary GetGroupMembers(string strGroup) { string groupMembers = ""; updateDebugInfo("Getting group members for " + strGroup); if (!groupsAndMembers.ContainsKey(strGroup)) { updateDebugInfo("Group was not in cache, doing LDAP queries"); try { DirectoryEntry ent = new DirectoryEntry(LDAPDirEnt); DirectorySearcher srch = new DirectorySearcher("(CN=" + strGroup + ")"); SearchResultCollection coll = srch.FindAll(); foreach (SearchResult rs in coll) { ResultPropertyCollection resultPropColl = rs.Properties; foreach (Object memberColl in resultPropColl["member"]) { DirectoryEntry gpMemberEntry = new DirectoryEntry("LDAP://" + memberColl); System.DirectoryServices.PropertyCollection userProps = gpMemberEntry.Properties; object obVal = userProps[getUserInfo].Value; if (null != obVal) { groupMembers = groupMembers + "|" + obVal.ToString(); } } } if (groupMembers != "") { groupsAndMembers.Add(strGroup, groupMembers); } } catch (Exception ex) { HandleUnhandledException(ex); } } return groupsAndMembers; } public static string StringCollectionToString(StringCollection stringCollection) { string outputString = ""; if (stringCollection != null && stringCollection.Count > 0) { foreach (string inputString in stringCollection) outputString += inputString + ","; outputString = outputString.Substring(0, outputString.Length - 1); } return outputString; } public ArrayList DirSearch(string sDir) { ArrayList directories = new ArrayList(); updateDebugInfo("Function DirSearch(string " + sDir + ") was called"); directories.Add(sDir); foreach (string d in Directory.GetDirectories(sDir)) { if (getPermissionsRecursive.CancellationPending) { break; }; string[] dirCount = sDir.Split('\\'); directories.Add(d); if (dirCount.Length < maxDirDepth) { foreach (string f in Directory.GetDirectories(d)) { if (getPermissionsRecursive.CancellationPending) { break; }; directories.Add(f); } DirSearch(d); } } return directories; } private void releaseObject(object obj) { try { System.Runtime.InteropServices.Marshal.ReleaseComObject(obj); obj = null; } catch (Exception ex) { obj = null; HandleUnhandledException(ex); } finally { GC.Collect(); } } /* private void saveXLS(string savedFile) { CultureInfo oldCI = Thread.CurrentThread.CurrentCulture; Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US"); Excel.Application xlApp; Excel.Workbook xlWorkBook; Excel.Worksheet xlWorkSheet; object misValue = System.Reflection.Missing.Value; xlApp = new Excel.ApplicationClass(); xlWorkBook = xlApp.Workbooks.Add(misValue); xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1); int i = 0; int j = 0; for (i = 0; i <= dataGridView1.RowCount - 1; i++) { for (j = 0; j <= dataGridView1.ColumnCount - 1; j++) { DataGridViewCell cell = dataGridView1[j, i]; xlWorkSheet.Cells[i + 1, j + 1] = cell.Value; } } xlWorkBook.SaveAs(savedFile, Excel.XlFileFormat.xlWorkbookNormal, misValue, misValue, misValue, misValue, Excel.XlSaveAsAccessMode.xlExclusive, misValue, misValue, misValue, misValue, misValue); xlWorkBook.Close(true, misValue, misValue); xlApp.Quit(); releaseObject(xlWorkSheet); releaseObject(xlWorkBook); releaseObject(xlApp); MessageBox.Show("File saved as: " + savedFile); updateDebugInfo("File saved as: " + savedFile); if (oldCI != null) { Thread.CurrentThread.CurrentCulture = oldCI; } } */ private void saveCSV(string savedFile) { richTextBox1.SaveFile(savedFile, RichTextBoxStreamType.PlainText); MessageBox.Show("File saved as: " + savedFile); updateDebugInfo("File saved as: " + savedFile); label3.Invoke(new updateLabel3Callback(this.updateLabel3), new object[] { "" }); loading_pic.Invoke(new loading_pic_visibleCallback(this.loading_pic_visible), new object[] { false }); controlsEnabled(true); } public string currentTimeString() { string currentTimeString = DateTime.Now.Hour.ToString() + ":" + DateTime.Now.Minute.ToString() + ":" + DateTime.Now.Second.ToString(); return currentTimeString; } public void updateDebugInfo(string info) { try { debugInfo.Add(currentTimeString() + "|" + info); } catch (Exception eDebugInfoAdd) { HandleUnhandledException(eDebugInfoAdd); }; } // Background workers private void getPermissionsRecursive_DoWork(object sender, DoWorkEventArgs e) { int maxDirDept_plus = 0; if (Int32.TryParse(maxLvl_numud.Value.ToString(), out maxDirDept_plus) && recusive_chkBox.Checked) { maxDirDept_plus = Int32.Parse(maxLvl_numud.Value.ToString()); } else { maxDirDept_plus = 1; } maxDirDepth = maxDirDept_plus; updateDebugInfo("Max dir depth set to:" + maxDirDepth); updateDebugInfo("Background worker getPermissionsRecurisve started"); ArrayList subPath = new ArrayList(); foreach (string f in folderListTemp) { if (recusive_chkBox.Checked) { label3.Invoke(new updateLabel3Callback(this.updateLabel3), new object[] { "Scanning for folders(" + f + ")..." }); updateDebugInfo("Scanning folders..."); foreach (string subPath2 in DirSearch(f)) { if (getPermissionsRecursive.CancellationPending) { e.Cancel = true; label3.Invoke(new updateLabel3Callback(this.updateLabel3), new object[] { "Cancelled..." }); Thread.Sleep(2); break; } subPath.Add(subPath2); } } else { subPath.Add(f); } } subPath.Sort(); int currentProgress = 0; updateDebugInfo("Found " + subPath.Count + " Folders to check ACL"); foreach (string subDir in subPath) { currentProgress = currentProgress + 1; mainProgressBar.Invoke(new mainProgressBar_setMaxCallback(this.mainProgressBar_setMax), new object[] { subPath.Count }); mainProgressBar.Invoke(new mainProgressBar_updateCallback(this.mainProgressBar_update), new object[] { currentProgress, true }); if (getPermissionsRecursive.CancellationPending) { e.Cancel = true; break; } label3.Invoke(new updateLabel3Callback(this.updateLabel3), new object[] { "Scanning ACL (" + subDir + ")..." }); updateDebugInfo("Scanning ACL (" + subDir + ")..."); // Load directory information DirectorySecurity myDirectorySecurity = Directory.GetAccessControl(subDir); // Obtain the access control list (ACL) AuthorizationRuleCollection ACL = myDirectorySecurity.GetAccessRules(true, false, typeof(System.Security.Principal.NTAccount)); // Go thru each access control entry (ACE) in the ACL foreach (AuthorizationRule ACE in ACL) { System.Threading.Thread.Sleep(50); if (getPermissionsRecursive.CancellationPending) { e.Cancel = true; label3.Invoke(new updateLabel3Callback(this.updateLabel3), new object[] { "Cancelled..." }); updateDebugInfo("Cancelled backgroundworker"); Thread.Sleep(2); break; } string groupName = ACE.IdentityReference.ToString(); groupName = groupName.Replace(groupNameStripBegin, ""); if (getOwnerGroup_chkBox.Checked) { if (groupName.Contains("__gebr") || groupName.Contains("__lees")) { string groupNameOwner = ""; groupNameOwner = groupName.Replace("__gebr", "__eign"); groupNameOwner = groupName.Replace("__lees", "__eign"); if (!groupHist.ContainsKey(groupNameOwner) || !groupHist.ContainsValue(subDir)) { if (skipDoubleGroup_chkBox.Checked) { groupHist[groupNameOwner] = subDir; } if (!ignoreGroupNamesBegin(ignoreGroupNameBegin, groupNameOwner)) { bool getMembers = true; if (groupNameOwner.StartsWith(ignoreGroupNameBegin)) { getMembers = false; } if (getMembers) { label3.Invoke(new updateLabel3Callback(this.updateLabel3), new object[] { "Getting members for " + groupNameOwner + "..." }); Dictionary groupMembers = GetGroupMembers(groupNameOwner); ArrayList membersOfGroup = splitGroupMembers(groupMembers, groupNameOwner); foreach (string gm in membersOfGroup) { string dataGridInfo = subDir + "|" + groupNameOwner + "|" + gm; permInfo = permInfo + subDir + "," + groupNameOwner + "," + gm + "\n"; dataGridView1.Invoke(new updateDataGridView1Callback(this.updateDataGridView1), new object[] { dataGridInfo }); richTextBox1.Invoke(new updateRichTextBox1Callback(this.updateRichTextBox1), new object[] { permInfo }); resultCount = dataGridView1.RowCount; results_textbox.Invoke(new updateResultsCallback(this.updateResults), new object[] { resultCount }); } } } } } } if (!groupHist.ContainsKey(groupName) || !groupHist.ContainsValue(subDir)) { if (skipDoubleGroup_chkBox.Checked) { groupHist[groupName] = subDir; } if (!ignoreGroupNamesBegin(ignoreGroupNameBegin, groupName)) { bool getMembers = true; if (ignorePassGroups_chkBox.Checked && groupName.EndsWith("__pass")) { getMembers = false; } else if (onlyLeesGebr_chkBox.Checked && groupName.EndsWith("__gebr") == false && groupName.EndsWith("__lees") == false) { getMembers = false; } else if (groupName.StartsWith(ignoreGroupNameBegin)) { getMembers = false; } if (getMembers) { label3.Invoke(new updateLabel3Callback(this.updateLabel3), new object[] { "Getting members for " + groupName + "..." }); Dictionary groupMembers = GetGroupMembers(groupName); ArrayList membersOfGroup = splitGroupMembers(groupMembers, groupName); foreach (string gm in membersOfGroup) { string dataGridInfo = subDir + "|" + groupName + "|" + gm; permInfo = permInfo + subDir + "," + groupName + "," + gm + "\n"; dataGridView1.Invoke(new updateDataGridView1Callback(this.updateDataGridView1), new object[] { dataGridInfo }); richTextBox1.Invoke(new updateRichTextBox1Callback(this.updateRichTextBox1), new object[] { permInfo }); resultCount = dataGridView1.RowCount; results_textbox.Invoke(new updateResultsCallback(this.updateResults), new object[] { resultCount }); } } } } } } e.Result = permInfo; } private void getPermissionsRecursive_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { endScan(); updateDebugInfo("Background worker getPermissionsRecurisve stopped"); mainProgressBar.Invoke(new mainProgressBar_setMaxCallback(this.mainProgressBar_setMax), new object[] { 0 }); mainProgressBar.Invoke(new mainProgressBar_updateCallback(this.mainProgressBar_update), new object[] { 0, false }); } private void saveAs_DoWork(object sender, DoWorkEventArgs e) { updateDebugInfo("Background worker saveAs started"); string savedFile = (string)e.Argument; if (savedFile.EndsWith(".xls")) { updateDebugInfo("Saving as .xls file"); //saveXLS(savedFile); } else if (Path.GetExtension(savedFile).ToLower() == ".csv" || Path.GetExtension(savedFile).ToLower() == ".txt") { updateDebugInfo("Saving as .csv or .txt file"); saveCSV(savedFile); } else { MessageBox.Show("Unsupported file format..."); updateDebugInfo("Unsupported file format..."); } } private void saveAs_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { label3.Invoke(new updateLabel3Callback(this.updateLabel3), new object[] { "" }); loading_pic.Invoke(new loading_pic_visibleCallback(this.loading_pic_visible), new object[] { false }); controlsEnabled(true); updateDebugInfo("Background worker saveAs stopped"); } private void updateDebugLog_DoWork(object sender, DoWorkEventArgs e) { updateDebugInfo("Starting debug background worker"); while (true) { string debugInfoTemp = ""; try { foreach (string d in debugInfo) { debugInfoTemp = debugInfoTemp + d + "\n"; } } catch (Exception ex) { HandleUnhandledException(ex); } PerformanceCounter performanceCounter = new PerformanceCounter(); performanceCounter.CategoryName = "Process"; performanceCounter.CounterName = "Working Set"; performanceCounter.InstanceName = Process.GetCurrentProcess().ProcessName; memUsage_lbl.Invoke(new updateMemUsage_lblCallback(this.updateMemUsage_lbl), new object[] { ((uint)performanceCounter.NextValue() / 1024).ToString("N0") + " MB" }); Thread.Sleep(500); if (upDateDebugLog.CancellationPending) { e.Cancel = true; updateDebugInfo("Cancelling debug background worker"); break; } try { debug_rtextbox.Invoke(new updateDebug_rtextboxCallback(this.updateDebug_rtextbox), new object[] { debugInfoTemp }); } catch (Exception eUpdateDebugInfo) { HandleUnhandledException(eUpdateDebugInfo); }; } updateDebugInfo("Stopping debug background worker"); } } }