谢谢分享~ 最好可以加上端口号自定义。private void Form1_Load(object sender, EventArgs e)
{
string path = Application.StartupPath + @"\工具和文档\WebDev.WebHost40.dll";
string str2 = Environment.GetEnvironmentVariable("windir") + @"\Microsoft.NET\assembly\GAC_32\WebDev.WebHost40\v4.0_10.0.0.0__b03f5f7f11d50a3a\WebDev.WebHost40.dll";
string str3 = Application.StartupPath + @"\工具和文档\WebServer.exe";
bool flag = false;
if (!File.Exists(path))
{
MessageBox.Show("未找到文件 " + path + Environment.NewLine + Environment.NewLine + "请找到文件之后再打开运行", "错误", MessageBoxButtons.OK, MessageBoxIcon.Hand);
flag = true;
}
if (!File.Exists(str2))
{
Directory.CreateDirectory(Environment.GetEnvironmentVariable("windir") + @"\Microsoft.NET\assembly\GAC_32\WebDev.WebHost40\v4.0_10.0.0.0__b03f5f7f11d50a3a\");
File.Copy(path, str2);
}
if (!File.Exists(str3))
{
MessageBox.Show("未找到文件 " + str3 + Environment.NewLine + Environment.NewLine + "请找到文件之后再打开运行", "错误", MessageBoxButtons.OK, MessageBoxIcon.Hand);
flag = true;
}
if (!flag)
{
string str4 = Application.StartupPath + @"\web\";
if (str4.EndsWith(@"\"))
{
str4 = str4.Substring(0, str4.Length - 1);
}
IPEndPoint localEP = new IPEndPoint(IPAddress.Any, 0);
Socket socket1 = new Socket(localEP.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
socket1.Bind(localEP);
int port = ((IPEndPoint) socket1.LocalEndPoint).Port;
socket1.Close();
Process.Start(str3, " /port:" + port.ToString() + " /path:\"" + str4);
Process.Start("http://localhost:" + port.ToString());
}
Application.Exit();
}
|