FrmOptionSet.cs
3.4 KB
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Microsoft.Win32;
namespace ServiceManager
{
public partial class FrmOptionSet : FrmBase
{
private AutoStart m_as = null;
private string m_KeyDir = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Run";
private RegistryKey m_regLOCALMACHINE = Registry.LocalMachine;
private string m_ValueName = "";
private string m_ValueProperty = "";
private string m_DefaultValueName = "Contamination ExplorerServiceManager";
private string m_DefaultValueProperty = string.Empty;
public FrmOptionSet()
{
InitializeComponent();
this.m_ValueName = this.m_DefaultValueName;
this.Init();
}
private void btnCancel_Click(object sender, EventArgs e)
{
this.Close();
}
private void btnOK_Click(object sender, EventArgs e)
{
try
{
if (this.cbAutoStart.Checked == true)
{
if (!this.PropertyExisted(m_ValueProperty))
{
if (String.IsNullOrEmpty(this.CreateValue(this.m_regLOCALMACHINE, this.m_KeyDir, this.m_ValueName, m_ValueProperty).Trim()))
MessageBox.Show("设置失败", "失败", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
else
{
this.DeleteValue(this.m_regLOCALMACHINE, this.m_KeyDir, this.m_ValueName);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void cbAutoStart_Enter(object sender, EventArgs e)
{
this.AcceptButton = this.btnOK;
}
private string CreateValue(RegistryKey Root, string Dir, string ValueName, object ValueProperty)
{
return m_as.CreateValue(Root, Dir, ValueName, ValueProperty);
}
private bool IsExisted(string ValueName)
{
return m_as.ValueExisted(this.m_regLOCALMACHINE, this.m_KeyDir, ValueName);
}
private string GetValueNameByProperty(object ValueProperty)
{
return m_as.GetValueNameByProperty(this.m_regLOCALMACHINE, this.m_KeyDir, ValueProperty);
}
private bool PropertyExisted(object ValueProperty)
{
return m_as.PropertyExisted(this.m_regLOCALMACHINE, this.m_KeyDir, ValueProperty);
}
private bool DeleteValue(RegistryKey Root, string Dir, string ValueName)
{
return m_as.DeleteValue(Root, Dir, ValueName);
}
private void Init()
{
this.m_ValueProperty = Application.ExecutablePath + @" /n";
m_as = new AutoStart();
this.cbAutoStart.Select();
this.cbAutoStart.Focus();
if (this.PropertyExisted(m_ValueProperty))
{
this.cbAutoStart.CheckState = CheckState.Checked;
}
else
{
this.cbAutoStart.CheckState = CheckState.Unchecked;
}
this.StartPosition = FormStartPosition.CenterScreen;
}
}
}