ServiceControllerコンポーネント制御コンピュータサービス
9307 ワード
private void Form1_Load(object sender, EventArgs e)
{
// ServiceController IIS 。 , Running。
// ServiceController IIS
//serviceController1.MachineName = ".";
//serviceController1.ServiceName = "IISAdmin";//IIS
}
// IIS
private void button1_Click(object sender, EventArgs e)
{
serviceController1.MachineName = ".";//
serviceController1.ServiceName = "IISAdmin";//
if (serviceController1.Status == //
ServiceControllerStatus.Running)
{
MessageBox.Show(//
serviceController1.DisplayName + " ");
Application.Exit();//
}
else
{
serviceController1.Start();//
MessageBox.Show(//
serviceController1.DisplayName + " ");
Application.Exit();//
}
}
// IIS
private void button3_Click(object sender, EventArgs e)
{
try
{
serviceController1.MachineName = ".";//
serviceController1.ServiceName = "IISAdmin";//
if (serviceController1.Status == //
ServiceControllerStatus.Running)
{
MessageBox.Show(//
serviceController1.DisplayName + " ");
btn_Stop.Enabled = true;//
btn_Status.Enabled = false;//
}
else
{
MessageBox.Show(//
serviceController1.DisplayName + " ");
btn_Status.Enabled = false;//
btn_Start.Enabled = true;//
}
}
catch (Exception ee)//
{ MessageBox.Show(ee.Message); }//
}
// IIS
private void button2_Click(object sender, EventArgs e)
{
try
{
serviceController1.MachineName = ".";//
serviceController1.ServiceName = "IISAdmin";//
if (serviceController1.CanStop)//
{
serviceController1.Stop();//
MessageBox.Show(//
serviceController1.DisplayName + " ");
Application.Exit();//
}
else
{
MessageBox.Show(//
serviceController1.DisplayName + " ");
Application.Exit();//
}
}
catch (Exception ee)//
{ MessageBox.Show(ee.Message); }//
}