From 547992623099ede654f6c24b04c800b3827fe921 Mon Sep 17 00:00:00 2001 From: Dylan Bickerstaff Date: Sun, 3 Mar 2019 23:13:26 -0500 Subject: [PATCH] Finished lookup enhancements. --- SuperADD/Main.cs | 59 ++++++++++++++++++++++------------- SuperADD/MainForm.Designer.cs | 1 + 2 files changed, 38 insertions(+), 22 deletions(-) diff --git a/SuperADD/Main.cs b/SuperADD/Main.cs index 5235e80..d6f6701 100644 --- a/SuperADD/Main.cs +++ b/SuperADD/Main.cs @@ -52,7 +52,7 @@ public Main(int autoIndex = -1, bool autoContinue = false) { new ProgressUI().CloseProgressDialog(); tsEnv = new TSEnvironment(); - foreach(string key in tsEnv.Variables) + foreach (string key in tsEnv.Variables) { if (key == "JOINDOMAIN") { @@ -70,7 +70,7 @@ public Main(int autoIndex = -1, bool autoContinue = false) } } } - catch(COMException) + catch (COMException) { IPGlobalProperties globalProperties = IPGlobalProperties.GetIPGlobalProperties(); desktopMode = true; @@ -325,21 +325,30 @@ private Task findCurrentComputerName() { return Task.Run(() => { - showMsg("Find Computer Name: Searching in Offline Registry...", loadImg); - try + showMsg("Find Computer Name: Getting list of logical drives...", loadImg); + string[] drives = Environment.GetLogicalDrives(); + showMsg("Find Computer Name: Searching in offline registries...", loadImg); + foreach (string drive in drives) { - Registry.RegistryHiveOnDemand registryHive = new Registry.RegistryHiveOnDemand(@"C:\Windows\System32\config\SYSTEM"); - Registry.Abstractions.RegistryKey key = registryHive.GetKey(@"ControlSet001\Control\ComputerName\ComputerName"); - foreach (Registry.Abstractions.KeyValue value in key.Values) + string rPath = drive + @"Windows\System32\config\SYSTEM"; + if (File.Exists(rPath)) { - if (value.ValueName == "ComputerName") + try { - return value.ValueData; + Registry.RegistryHiveOnDemand registryHive = new Registry.RegistryHiveOnDemand(rPath); + Registry.Abstractions.RegistryKey key = registryHive.GetKey(@"ControlSet001\Control\ComputerName\ComputerName"); + foreach (Registry.Abstractions.KeyValue value in key.Values) + { + if (value.ValueName == "ComputerName") + { + return value.ValueData; + } + } } + catch (IOException) { } } } - catch (Exception) {} - showMsg("Find Computer Name: Searching in Online Registry...", loadImg); + showMsg("Find Computer Name: Searching in online registry...", loadImg); Microsoft.Win32.RegistryKey computerName = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(@"SYSTEM\ControlSet001\Control\ComputerName\ComputerName", false); hideMsg(); return (string)computerName.GetValue("ComputerName"); @@ -358,7 +367,7 @@ private async void createComputer() showMsg("No Organizational Unit is selected.", warnImg); return; } - if(adDomainName == "" || adUserName == "" || adPassword == "") + if (adDomainName == "" || adUserName == "" || adPassword == "") { promptShadowPanel.BringToFront(); promptPanel.BringToFront(); @@ -374,7 +383,7 @@ private async void createComputer() postData.Add("function", "update"); postData.Add("cn", nameTextBox.Text); postData.Add("description", descTextBox.Text); - if(computerOverwriteConfirmed) + if (computerOverwriteConfirmed) { postData.Add("confirm", ""); } @@ -395,7 +404,7 @@ private async void createComputer() } else { - if(desktopMode) + if (desktopMode) { hideMsg(); } @@ -441,7 +450,7 @@ private void setTSVariables(bool joinDomain = true, bool exitSuperADD = true) Application.Exit(); } } - catch(Exception e) + catch (Exception e) { showMsg("Error setting TS Variables: " + e.Message, warnImg); } @@ -470,11 +479,12 @@ private async void findCurrentDescriptionAndOU() var results = JsonConvert.DeserializeObject>>(rawResults); foreach (Dictionary computer in results) { - if (computer["cn"] == nameTextBox.Text) + if (computer["cn"].ToLower() == nameTextBox.Text.ToLower()) { suppressFindNextName = true; OUList.SelectedIndex = ouIndex; suppressFindNextName = false; + nameTextBox.Text = computer["cn"]; descTextBox.Text = computer["description"]; found = true; break; @@ -537,7 +547,7 @@ private void OUList_SelectedIndexChanged(object sender, EventArgs e) if (elm.Element("Name").Value == (string)lv.SelectedItem) { currentlySelectedOU = elm.Element("DistinguishedName").Value; - if(lv == OUList) + if (lv == OUList) { currentCreateSelectedOU = elm.Element("DistinguishedName").Value; } @@ -558,15 +568,15 @@ private void saveNextBtn_Click(object sender, EventArgs e) private void nameTextBox_TextChanged(object sender, EventArgs e) { - foreach(char character in invalidNameCharacters) + foreach (char character in invalidNameCharacters) { nameTextBox.Text = nameTextBox.Text.Replace(character, '\0'); } - if(nameTextBox.Text.Length > 15) + if (nameTextBox.Text.Length > 15) { nameTextBox.Text = nameTextBox.Text.Substring(0, 15); } - if(autoRunIndex == -2) + if (autoRunIndex == -2) { saveNextBtn.PerformClick(); } @@ -597,7 +607,7 @@ private void promptSubmitBtn_Click(object sender, EventArgs e) private void Main_Load(object sender, EventArgs e) { - if(autoRunIndex > -1 && autoRunIndex < OUList.Items.Count) + if (autoRunIndex > -1 && autoRunIndex < OUList.Items.Count) { OUList.SelectedIndex = autoRunIndex; if (autoRunContinue) @@ -613,7 +623,7 @@ private void Main_Load(object sender, EventArgs e) private void prompt_KeyPress(object sender, KeyPressEventArgs e) { - if(e.KeyChar == '\r') + if (e.KeyChar == '\r') { promptSubmitBtn.PerformClick(); } @@ -624,5 +634,10 @@ private async void findCurrentNameBtn_Click(object sender, EventArgs e) nameTextBox.Text = await findCurrentComputerName(); findCurrentDescriptionAndOU(); } + + private void SearchADBtn_Click(object sender, EventArgs e) + { + findCurrentDescriptionAndOU(); + } } } diff --git a/SuperADD/MainForm.Designer.cs b/SuperADD/MainForm.Designer.cs index 259e9fe..5261dd1 100644 --- a/SuperADD/MainForm.Designer.cs +++ b/SuperADD/MainForm.Designer.cs @@ -167,6 +167,7 @@ private void InitializeComponent() this.SearchADBtn.TabIndex = 19; this.SearchADBtn.Text = "Lookup"; this.SearchADBtn.UseVisualStyleBackColor = true; + this.SearchADBtn.Click += new System.EventHandler(this.SearchADBtn_Click); // // findCurrentNameBtn //