清风的blog 优然探索

C# 绿色IIS

 

private void button1_Click(object sender, EventArgs e)
{
    if (this.button1.Text == "启动服务")
    {
        if ((this.textBox1.Text == "") || (this.textBox1.Text == "0"))
        {
            MessageBox.Show("请输入端口");
        }
        else if (Convert.ToInt32(this.textBox1.Text) > 0xffff)
        {
            MessageBox.Show("端口范围错误!在(1~65535)之间未使用的端口.");
        }
        else if (this.textBox2.Text == "")
        {
            MessageBox.Show("请选择网站目录");
        }
        else
        {
            if (this.textBox3.Text == "")
            {
                this.textBox3.Text = "/";
            }
            if (this.comboBox1.GetItemText(this.comboBox1.SelectedItem) == "v4.0")
            {
                if (!File.Exists(@"c:\WebServer40.EXE"))
                {
                    File.WriteAllBytes(@"c:\WebServer40.EXE", Files.WebDev_WebServer40);
                }
                this.p = Process.Start(@"c:\WebServer40.EXE", "/port:" + this.textBox1.Text + " /path:\"" + this.textBox2.Text + "\" /vpath:\"" + this.textBox3.Text + "\"");
                this.pid = this.p.Id;
            }
            else
            {
                if (!File.Exists(@"c:\WebServer20.EXE"))
                {
                    File.WriteAllBytes(@"c:\WebServer20.EXE", Files.WebDev_WebServer40);
                }
                this.p = Process.Start(@"c:\WebServer20.EXE", "/port:" + this.textBox1.Text + " /path:\"" + this.textBox2.Text + "\" /vpath:\"" + this.textBox3.Text + "\"");
                this.pid = this.p.Id;
            }
            this.toolStripStatusLabel1.Text = "启动成功!";
            this.button1.Text = "停止服务";
        }
    }
    else
    {
        this.p.Kill();
        this.pid = 0;
        this.toolStripStatusLabel1.Text = "服务已经关闭!";
        this.button1.Text = "启动服务";
    }
}

 

 

2014年12月1日 | 发布:admin | 分类:未分类 | 评论:0

发表留言: