using System; using System.ComponentModel; using System.Configuration; using System.Diagnostics; using System.Drawing; using System.Windows.Forms; using Microsoft.Win32; namespace ControlApp; public class ConfigSettingsForm : Form { private IContainer components; private CheckBox checkBox1; private TextBox textBox1; private Label label1; private Button button1; private TextBox textBox2; private Label label2; private Label label3; private TextBox textBox3; private CheckBox checkBox2; private Button button2; private Button button3; private Panel panel1; private Button button4; private Label label4; private ComboBox delaycmb; private Label label5; public ConfigSettingsForm() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { Configuration configuration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); KeyValueConfigurationCollection apps = configuration.AppSettings.Settings; apps.Remove("LocalDrive"); apps.Remove("AutoRun"); apps.Remove("UserName"); apps.Remove("Password"); apps.Remove("Delay"); apps.Remove("RunAll"); apps.Add("LocalDrive", textBox1.Text); if (checkBox1.Checked) { apps.Add("AutoRun", "True"); } else { apps.Add("AutoRun", "False"); } apps.Add("UserName", textBox2.Text); apps.Add("Password", textBox3.Text); if (checkBox2.Checked) { apps.Add("RunAll", "True"); } else { apps.Add("RunAll", "False"); } if (delaycmb.SelectedIndex == 0) { apps.Add("Delay", "30"); } else if (delaycmb.SelectedIndex == 1) { apps.Add("Delay", "60"); } else if (delaycmb.SelectedIndex == 2) { apps.Add("Delay", "120"); } configuration.Save(ConfigurationSaveMode.Full); ConfigurationManager.RefreshSection(configuration.AppSettings.SectionInformation.Name); Close(); } protected override void OnLoad(EventArgs e) { base.OnLoad(e); textBox1.Text = ConfigurationManager.AppSettings["LocalDrive"]; textBox2.Text = ConfigurationManager.AppSettings["UserName"]; textBox3.Text = ConfigurationManager.AppSettings["Password"]; if (ConfigurationManager.AppSettings["AutoRun"] == "True") { checkBox1.Checked = true; } else { checkBox1.Checked = false; } if (ConfigurationManager.AppSettings["RunAll"] == "True") { checkBox2.Checked = true; } else { checkBox2.Checked = false; } switch (ConfigurationManager.AppSettings["Delay"]) { case "30": delaycmb.SelectedIndex = 0; break; case "60": delaycmb.SelectedIndex = 1; break; case "120": delaycmb.SelectedIndex = 2; break; } } private void ConfigSettingsForm_Load(object sender, EventArgs e) { } private void button2_Click(object sender, EventArgs e) { string Password = ConfigurationManager.AppSettings["Password"]; if (Password != null || Password == "") { Password = textBox3.Text; } string user = ConfigurationManager.AppSettings["UserName"]; if (user != null || user == "") { user = textBox2.Text; } Process.Start(new ProcessStartInfo { FileName = "https://www.thecontrolapp.co.uk/Pages/Sub/SubSettings.aspx?user=" + user + "&password=" + Password, UseShellExecute = true }); } private void button3_Click(object sender, EventArgs e) { using RegistryKey key = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", writable: true); key.SetValue("ControlApp", "\"" + Application.ExecutablePath + "\""); } private void button4_Click(object sender, EventArgs e) { using RegistryKey key = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", writable: true); key.DeleteValue("My Program", throwOnMissingValue: false); } protected override void Dispose(bool disposing) { if (disposing && components != null) { components.Dispose(); } base.Dispose(disposing); } private void InitializeComponent() { this.checkBox1 = new System.Windows.Forms.CheckBox(); this.textBox1 = new System.Windows.Forms.TextBox(); this.label1 = new System.Windows.Forms.Label(); this.button1 = new System.Windows.Forms.Button(); this.textBox2 = new System.Windows.Forms.TextBox(); this.label2 = new System.Windows.Forms.Label(); this.label3 = new System.Windows.Forms.Label(); this.textBox3 = new System.Windows.Forms.TextBox(); this.checkBox2 = new System.Windows.Forms.CheckBox(); this.button2 = new System.Windows.Forms.Button(); this.button3 = new System.Windows.Forms.Button(); this.panel1 = new System.Windows.Forms.Panel(); this.button4 = new System.Windows.Forms.Button(); this.label4 = new System.Windows.Forms.Label(); this.delaycmb = new System.Windows.Forms.ComboBox(); this.label5 = new System.Windows.Forms.Label(); this.panel1.SuspendLayout(); base.SuspendLayout(); this.checkBox1.AutoSize = true; this.checkBox1.Location = new System.Drawing.Point(12, 22); this.checkBox1.Name = "checkBox1"; this.checkBox1.Size = new System.Drawing.Size(119, 19); this.checkBox1.TabIndex = 0; this.checkBox1.Text = "Auto run sent exe"; this.checkBox1.UseVisualStyleBackColor = true; this.textBox1.Location = new System.Drawing.Point(6, 47); this.textBox1.Name = "textBox1"; this.textBox1.Size = new System.Drawing.Size(103, 23); this.textBox1.TabIndex = 1; this.label1.AutoSize = true; this.label1.Location = new System.Drawing.Point(115, 50); this.label1.Name = "label1"; this.label1.Size = new System.Drawing.Size(74, 15); this.label1.TabIndex = 2; this.label1.Text = "File Location"; this.button1.Location = new System.Drawing.Point(114, 351); this.button1.Name = "button1"; this.button1.Size = new System.Drawing.Size(75, 23); this.button1.TabIndex = 3; this.button1.Text = "Ok"; this.button1.UseVisualStyleBackColor = true; this.button1.Click += new System.EventHandler(button1_Click); this.textBox2.Location = new System.Drawing.Point(6, 76); this.textBox2.Name = "textBox2"; this.textBox2.Size = new System.Drawing.Size(100, 23); this.textBox2.TabIndex = 4; this.label2.AutoSize = true; this.label2.Location = new System.Drawing.Point(115, 79); this.label2.Name = "label2"; this.label2.Size = new System.Drawing.Size(65, 15); this.label2.TabIndex = 5; this.label2.Text = "User Name"; this.label3.AutoSize = true; this.label3.Location = new System.Drawing.Point(115, 108); this.label3.Name = "label3"; this.label3.Size = new System.Drawing.Size(57, 15); this.label3.TabIndex = 7; this.label3.Text = "Password"; this.textBox3.Location = new System.Drawing.Point(6, 105); this.textBox3.Name = "textBox3"; this.textBox3.Size = new System.Drawing.Size(100, 23); this.textBox3.TabIndex = 6; this.checkBox2.AutoSize = true; this.checkBox2.Location = new System.Drawing.Point(12, 138); this.checkBox2.Name = "checkBox2"; this.checkBox2.Size = new System.Drawing.Size(133, 19); this.checkBox2.TabIndex = 12; this.checkBox2.Text = "Run All Outstanding"; this.checkBox2.UseVisualStyleBackColor = true; this.button2.Location = new System.Drawing.Point(6, 321); this.button2.Name = "button2"; this.button2.Size = new System.Drawing.Size(183, 23); this.button2.TabIndex = 13; this.button2.Text = "Change Server Settings"; this.button2.UseVisualStyleBackColor = true; this.button2.Click += new System.EventHandler(button2_Click); this.button3.Location = new System.Drawing.Point(14, 27); this.button3.Name = "button3"; this.button3.Size = new System.Drawing.Size(54, 23); this.button3.TabIndex = 17; this.button3.Text = "Add"; this.button3.UseVisualStyleBackColor = true; this.button3.Click += new System.EventHandler(button3_Click); this.panel1.Controls.Add(this.button4); this.panel1.Controls.Add(this.label4); this.panel1.Controls.Add(this.button3); this.panel1.Location = new System.Drawing.Point(9, 248); this.panel1.Name = "panel1"; this.panel1.Size = new System.Drawing.Size(175, 63); this.panel1.TabIndex = 18; this.button4.Location = new System.Drawing.Point(88, 27); this.button4.Name = "button4"; this.button4.Size = new System.Drawing.Size(65, 23); this.button4.TabIndex = 18; this.button4.Text = "Remove"; this.button4.UseVisualStyleBackColor = true; this.button4.Click += new System.EventHandler(button4_Click); this.label4.AutoSize = true; this.label4.Location = new System.Drawing.Point(39, 0); this.label4.Name = "label4"; this.label4.Size = new System.Drawing.Size(97, 15); this.label4.TabIndex = 0; this.label4.Text = "Windows Startup"; this.delaycmb.FormattingEnabled = true; this.delaycmb.Items.AddRange(new object[3] { "30s", "60s", "120s" }); this.delaycmb.Location = new System.Drawing.Point(12, 163); this.delaycmb.Name = "delaycmb"; this.delaycmb.Size = new System.Drawing.Size(94, 23); this.delaycmb.TabIndex = 19; this.label5.AutoSize = true; this.label5.Location = new System.Drawing.Point(115, 166); this.label5.Name = "label5"; this.label5.Size = new System.Drawing.Size(36, 15); this.label5.TabIndex = 20; this.label5.Text = "Delay"; base.AutoScaleDimensions = new System.Drawing.SizeF(7f, 15f); base.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; base.ClientSize = new System.Drawing.Size(196, 382); base.Controls.Add(this.label5); base.Controls.Add(this.delaycmb); base.Controls.Add(this.panel1); base.Controls.Add(this.button2); base.Controls.Add(this.checkBox2); base.Controls.Add(this.label3); base.Controls.Add(this.textBox3); base.Controls.Add(this.label2); base.Controls.Add(this.textBox2); base.Controls.Add(this.button1); base.Controls.Add(this.label1); base.Controls.Add(this.textBox1); base.Controls.Add(this.checkBox1); base.Name = "ConfigSettingsForm"; this.Text = "ConfigSettingsForm"; base.Load += new System.EventHandler(ConfigSettingsForm_Load); this.panel1.ResumeLayout(false); this.panel1.PerformLayout(); base.ResumeLayout(false); base.PerformLayout(); } }