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的文章

  • 相关阅读:
    Atitit sql计划任务与查询优化器统计信息模块
    Atitit  数据库的事件机制触发器与定时任务attilax总结
    Atitit 图像处理知识点体系知识图谱 路线图attilax总结 v4 qcb.xlsx
    Atitit 图像处理 深刻理解梯度原理计算.v1 qc8
    Atiti 数据库系统原理 与数据库方面的书籍 attilax总结 v3 .docx
    Atitit Mysql查询优化器 存取类型 范围存取类型 索引存取类型 AND or的分析
    Atitit View事件分发机制
    Atitit 基于sql编程语言的oo面向对象大规模应用解决方案attilax总结
    Atitti 存储引擎支持的国内点与特性attilax总结
    Atitit 深入理解软件的本质 attilax总结 软件三原则"三次原则"是DRY原则和YAGNI原则的折
  • 原文地址:https://www.cnblogs.com/xqf222/p/3306869.html
Copyright © 2011-2022 走看看