ServiceManagerInstaller.cs
7.5 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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
using System;
using System.Collections;
using System.ComponentModel;
using System.Configuration.Install;
using System.Diagnostics;
using System.IO;
using System.Management;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using IWshRuntimeLibrary;
using Microsoft.Win32;
namespace ServiceManager
{
[RunInstaller(true)]
public partial class ServiceManagerInstaller : Installer
{
// 获取硬盘物理序列号
[DllImport("DiskSerialNo.dll")]
private static extern string GetDiskSerialNo();
// 获取网卡序列号
[DllImport("DiskSerialNo.dll")]
private static extern string GetMacAddr();
public ServiceManagerInstaller()
{
// 该调用是设计器所必需的。
InitializeComponent();
}
public override void Install(IDictionary mySavedState)
{
base.Install(mySavedState); // 安装
string strdbserver = "", strdbname = "", strdbuser = "", strdbpassword = "", strMyCMMIDBUser = "", strMyCMMIDBPassword = "";
IISManager ismang = new IISManager();
DialogResult dr;
WebConfig m_wc = new WebConfig();
m_wc.WebConfigPath = this.Context.Parameters["tdname"] + "WebService\\Web.Config";
ismang.Connect();
try
{
#region 建立IIS
// 设置WebService权限
MachineConfiguration mc = new MachineConfiguration();
if (!mc.ProcessModelSetUserName())
{
this.Rollback(mySavedState);
throw new Exception(".Net FrameWork 出现异常或版本不对,无法完成系统配置。请重装.Net FrameWork 2.0");
}
if (!ismang.CreateVirtualDirectory(this.Context.Parameters["vdname"], this.Context.Parameters["tdname"] + "WebService"))
{
dr = MessageBox.Show("服务器上虚拟目录 " + this.Context.Parameters["vdname"] + " 已存在,\r\n继续安装请按‘确定’,虚拟目录将被重新建立。\r\n退出安装请按‘取消’。", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
//MessageBox.Show(dr.ToString());
if (dr == DialogResult.Cancel)
{
this.Rollback(mySavedState);
throw new Exception("用户取消了安装,安装未完成。");
}
else
{
try
{
ismang.DeleteVirtualDirectory(this.Context.Parameters["vdname"]);
ismang.CreateVirtualDirectory(this.Context.Parameters["vdname"], this.Context.Parameters["tdname"] + "WebService");
}
catch (Exception e)
{
throw new Exception("覆盖虚拟目录时出错!" + e.Message.ToString());
}
}
}
#endregion
AddShortCut(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), this.Context.Parameters["tdname"] + "ServiceManager\\Contamination Explorer Server.exe", "Contamination Explorer Server");
AddShortCut(Environment.GetFolderPath(Environment.SpecialFolder.Programs) + "\\Contamination Explorer Server", this.Context.Parameters["tdname"] + "ServiceManager\\Contamination Explorer Server.exe", "Contamination Explorer Server");
#region 设置 ServiceManager 自动启动
string m_KeyDir = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Run";
RegistryKey m_regLOCALMACHINE = Registry.LocalMachine;
string m_ValueName = "Contamination ExplorerServiceManager";
string m_ValueProperty = this.Context.Parameters["tdname"] + "ServiceManager\\Contamination Explorer Server.exe";
AutoStart m_as = new AutoStart();
if (!m_as.PropertyExisted(m_regLOCALMACHINE, m_KeyDir, m_ValueProperty))
m_as.CreateValue(m_regLOCALMACHINE, m_KeyDir, m_ValueName, m_ValueProperty);
#endregion
//改写 WebConfig 中的 Licence 路径
m_wc.SetWebConfig(WebConfig.MyCMMIConfiguration, "MyCMMI2007.MyCMMI2007.LicencePath", this.Context.Parameters["tdname"] + "ServiceManager\\Contamination Explorer.lic");
GetDiskSerial();
MessageBox.Show("安装结束后请重新启动计算机", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (Exception ex)
{
//throw new Exception(ex.Message);
MessageBox.Show(ex.Message.ToString());
}
}
public override void Uninstall(IDictionary mySavedState)
{
base.Uninstall(mySavedState);
}
private bool AddShortCut(string locationfolder,string targetDir,string linkName)
{
try
{
if(!Directory.Exists(locationfolder))
{
DirectoryInfo di = Directory.CreateDirectory(locationfolder);
}
string folder = locationfolder + "\\" + linkName;
// Create a Windows Script Host Shell class
IWshShell_Class shell = new IWshShell_ClassClass();
// Define the shortcut file
IWshShortcut_Class shortcut = shell.CreateShortcut(folder + ".lnk") as IWshShortcut_Class;
shortcut.TargetPath = targetDir;
shortcut.Save();
return true;
}
catch
{
return false;
}
}
#region GetDiskSerial
private void GetDiskSerial()
{
try
{ //安装后弹出校验码的提示文本,以便用户进行注册获取许可证文件//wuxiangrong 2005.10.26
String infos = @"请使用该校验码:" + GetDiskID() + @",到相应的网站上注册,获取许可证文件!";
FileStream fs = new FileStream("ReadMe.txt", FileMode.OpenOrCreate);
StreamWriter sw = new StreamWriter(fs);
sw.Write(infos);
sw.Close();
Process.Start("ReadMe.txt");
//MessageBox.Show("安装结束后请重新启动计算机","提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}
// xfpan [5/17/2004]
/// <summary>
/// 获取机器唯一标志
/// </summary>
/// <returns>机器唯一标志</returns>
private string GetDiskID()
{
string DiskID = "";
DiskID = GetMAC().Trim();
if (!String.IsNullOrEmpty(DiskID))
{
DiskID = "MA-" + DiskID;
return DiskID;
}
try
{
DiskID = GetDiskSerialNo().Trim();
if (!String.IsNullOrEmpty(DiskID))
{
DiskID = "HD" + DiskID;
return DiskID;
}
}
catch{}
DiskID = GetCPUId();
if (!String.IsNullOrEmpty(DiskID))
{
DiskID = "CP" + DiskID;
return DiskID;
}
return "";
}
private string GetCPUId()
{
String HDid = "";
ManagementClass cimobject = new ManagementClass("Win32_Processor");
try
{
ManagementObjectCollection moc = cimobject.GetInstances();
foreach(ManagementObject mo in moc)
{
HDid = mo["UniqueId"].ToString();
if (!String.IsNullOrEmpty(HDid))
break;
}
}
catch
{
HDid = "";
}
return HDid.Trim();
}
private string GetMAC()
{
string strMac = "";
try
{
strMac = GetMacAddr();
}
catch
{
strMac = "";
}
return strMac.Trim();
}
// xfpan [5/17/2004]
#endregion
}
}