Skip to content

Commit

Permalink
Finished lookup enhancements.
Browse files Browse the repository at this point in the history
  • Loading branch information
krisdb2009 committed Mar 4, 2019
1 parent 2da55a5 commit 5479926
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 22 deletions.
59 changes: 37 additions & 22 deletions SuperADD/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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")
{
Expand All @@ -70,7 +70,7 @@ public Main(int autoIndex = -1, bool autoContinue = false)
}
}
}
catch(COMException)
catch (COMException)
{
IPGlobalProperties globalProperties = IPGlobalProperties.GetIPGlobalProperties();
desktopMode = true;
Expand Down Expand Up @@ -325,21 +325,30 @@ private Task<String> 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");
Expand All @@ -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();
Expand All @@ -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", "");
}
Expand All @@ -395,7 +404,7 @@ private async void createComputer()
}
else
{
if(desktopMode)
if (desktopMode)
{
hideMsg();
}
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -470,11 +479,12 @@ private async void findCurrentDescriptionAndOU()
var results = JsonConvert.DeserializeObject<List<Dictionary<string, string>>>(rawResults);
foreach (Dictionary<string, string> 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;
Expand Down Expand Up @@ -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;
}
Expand All @@ -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();
}
Expand Down Expand Up @@ -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)
Expand All @@ -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();
}
Expand All @@ -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();
}
}
}
1 change: 1 addition & 0 deletions SuperADD/MainForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 5479926

Please sign in to comment.