uchr4 发表于 2015-11-14 15:33:38

修改本机iis中所有application pool的identity(OfficeServerApplicationPool除外)

  using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.DirectoryServices;
using System.Collections;
  namespace ResetIISApplicationIdentity
{
    class Program
    {
      static void Main(string[] args)
      {
            string[] strusers = System.IO.File.ReadAllLines("userid.txt", System.Text.Encoding.UTF8);
            int sid = 0;
            foreach (string struser in strusers)
            {
                string[] arruser = struser.Split('|');
                string name = arruser;
                string pwd = arruser;
  DirectoryEntry appPool = new DirectoryEntry("IIS://localhost/W3SVC/AppPools");
                try
                {
                  foreach (DirectoryEntry getdir in appPool.Children)
                  {
                        if (getdir.Name != "OfficeServerApplicationPool")
                        {
                            getdir.Properties["WAMUserName"] = name;
                            getdir.Properties["WAMUserPass"] = pwd;
                            //getdir.Properties["AppPoolIdentityType"] = "3";//"3"应用程序池作为特定用户帐户来运行,"0"应用程序池作为 LocalSystem 来运行,"1"应用程序池作为 LocalService 来运行,"2"应用程序池作为 NetworkService 来运行。
                            getdir.CommitChanges();                           
                            Console.WriteLine(getdir.Name + "\t" + getdir.Properties["WAMUserName"] + "\t" + getdir.Properties["WAMUserPass"]);
                        }
                  }
                }
                catch (Exception ex)
                {
                  Console.WriteLine(ex.Message);
                  return;
                }
                Console.ReadKey();
            }
      }
    }
}

         版权声明:本文为博主原创文章,未经博主允许不得转载。
页: [1]
查看完整版本: 修改本机iis中所有application pool的identity(OfficeServerApplicationPool除外)