-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathSetForestNameForm.cs
84 lines (67 loc) · 2.72 KB
/
SetForestNameForm.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace ADReplStatus
{
public partial class SetForestNameForm : Form
{
public SetForestNameForm()
{
InitializeComponent();
}
private void SetForestNameForm_Load(object sender, EventArgs e)
{
if (ADReplStatusForm.gDarkMode == true)
{
this.BackColor = Color.FromArgb(32, 32, 32);
EnterForestNameLabel.BackColor = Color.FromArgb(32, 32, 32);
EnterForestNameLabel.ForeColor = Color.White;
SetForestNameTextBox.BackColor = Color.FromArgb(32, 32, 32);
SetForestNameTextBox.ForeColor = Color.White;
SetForestNameButton.BackColor = Color.FromArgb(32, 32, 32);
SetForestNameButton.ForeColor = Color.White;
SaveForestCheckBox.ForeColor = Color.White;
}
}
private void SetForestNameButton_Click(object sender, EventArgs e)
{
if (SetForestNameTextBox.Text.Length > 0)
{
ADReplStatusForm.gForestName = SetForestNameTextBox.Text;
if (SaveForestCheckBox.Checked)
{
try
{
var key = Registry.CurrentUser.CreateSubKey("SOFTWARE\\ADREPLSTATUS", true);
if (key != null)
{
key.SetValue("ForestName", SetForestNameTextBox.Text);
key.Dispose();
}
}
catch (Exception ex)
{
string errorMessage = $"ERROR: Failed to write to the HKCU\\ADREPLSTATUS registry key!\n{ex.Message}\n";
MessageBox.Show(errorMessage, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
if (ADReplStatusForm.gLoggingEnabled)
{
System.IO.File.AppendAllText(ADReplStatusForm.gLogfileName, $"[{DateTime.Now}] {errorMessage}\n");
}
}
}
if (ADReplStatusForm.gLoggingEnabled)
{
System.IO.File.AppendAllText(ADReplStatusForm.gLogfileName, $"[{DateTime.Now}] Forest name set to: {ADReplStatusForm.gForestName}\n");
}
this.Dispose();
}
}
}
}