zoukankan      html  css  js  c++  java
  • C#IIS网站应用程序池列表添加修改删除

    //添加应用程序池空间引用
    using System.DirectoryServices;
    using System.Text;
    using System.Text.RegularExpressions;
    using System.Diagnostics;
    using System.Management;

    private void button2_Click(object sender, System.EventArgs e)
      {
       this.richTextBox1.Text="";
       DirectoryEntry appPool = new DirectoryEntry("IIS://localhost/W3SVC/AppPools");
         foreach(DirectoryEntry a in appPool.Children)
         {      
       this.richTextBox1.AppendText(a.Name+"/r");   
         }
      }

      private void button3_Click(object sender, System.EventArgs e)
      {
       string AppPoolName=this.textBox1.Text.Trim();
       bool ExistAppPoolFlag=false;

       try
       {
        DirectoryEntry newpool;
          DirectoryEntry apppools=new DirectoryEntry("IIS://localhost/W3SVC/AppPools");
        foreach(DirectoryEntry a in apppools.Children)
          {      
         if(a.Name==AppPoolName)
         {
          ExistAppPoolFlag=true;
         }
          }   
        if(ExistAppPoolFlag==false)
        {
         newpool=apppools.Children.Add(AppPoolName, "IIsApplicationPool");     
         newpool.CommitChanges();
         MessageBox.Show("应用程序池添加成功","添加成功");
        }
        else
        {
         MessageBox.Show("应用程序池已经存在","添加失败");   
        }
       }
       catch(Exception ex)
       {
        MessageBox.Show(ex.Message,"错误");      
       }
         
      }

      private void button4_Click(object sender, System.EventArgs e)
      {
       string oldAppPoolName=this.textBox1.Text.Trim();
       string newAppPoolName=this.textBox2.Text.Trim();
       bool ExistAppPoolFlag=false;

       try
       {    
          DirectoryEntry apppools=new DirectoryEntry("IIS://localhost/W3SVC/AppPools");
        foreach(DirectoryEntry a in apppools.Children)
          {      
         if(a.Name==oldAppPoolName)
         {
          ExistAppPoolFlag=true;
          a.Rename(newAppPoolName);
          a.CommitChanges();
          MessageBox.Show("应用程序池名称修改成功","修改成功"); 
         }
          }   
        if(ExistAppPoolFlag==false)
        {     
         MessageBox.Show("应用程序池未找到","修改失败");   
        }
       }
       catch(Exception ex)
       {
        MessageBox.Show(ex.Message,"错误");      
       }
      }
      
      
      private void button5_Click(object sender, System.EventArgs e)
      {
       string AppPoolName=this.textBox1.Text.Trim();
       bool ExistAppPoolFlag=false;

       try
       {    
          DirectoryEntry apppools=new DirectoryEntry("IIS://localhost/W3SVC/AppPools");
        foreach(DirectoryEntry a in apppools.Children)
          {      
         if(a.Name==AppPoolName)
         {
          ExistAppPoolFlag=true;
          a.DeleteTree();      
          MessageBox.Show("应用程序池名称删除成功","删除成功"); 
         }
          }   
        if(ExistAppPoolFlag==false)
        {     
         MessageBox.Show("应用程序池未找到","删除失败");   
        }
       }
       catch(Exception ex)
       {
        MessageBox.Show(ex.Message,"错误");      
       }
      
      } 

    //备注:参考了http://my6521.blog.hexun.com/6602808_d.html的文章

  • 相关阅读:
    Windows Phone 7 日期选择控件DatePicker和时间选择控件TimePicker
    Windows Phone 7 开发小技巧
    Windows Phone 7 MVVM模式的学习笔记
    Windows Phone 7 网络编程之留言板应用
    C# 中的INotifyPropertyChanged和ObservableCollection<T>
    《深入浅出:Windows Phone 7应用开发》
    Windows Phone 7 MVVM模式通讯方式之实现Command
    Windows Phone 7 chart图表编程
    Windows Phone 7 网络编程之调用web service
    Perst嵌入式数据库介绍
  • 原文地址:https://www.cnblogs.com/xqf222/p/3306869.html
Copyright © 2011-2022 走看看