码迷,mamicode.com
首页 > 移动开发 > 详细

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

时间:2017-03-23 22:50:53      阅读:259      评论:0      收藏:0      [点我收藏+]

标签:sharepoint

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[0];
                string pwd = arruser[1];

                DirectoryEntry appPool = new DirectoryEntry("IIS://localhost/W3SVC/AppPools");
                try
                {
                    foreach (DirectoryEntry getdir in appPool.Children)
                    {
                        if (getdir.Name != "OfficeServerApplicationPool")
                        {
                            getdir.Properties["WAMUserName"][0] = name;
                            getdir.Properties["WAMUserPass"][0] = pwd;
                            //getdir.Properties["AppPoolIdentityType"][0] = "3";  //"3"应用程序池作为特定用户帐户来运行,"0"应用程序池作为 LocalSystem 来运行,"1"应用程序池作为 LocalService 来运行,"2"应用程序池作为 NetworkService 来运行。
                            getdir.CommitChanges();                           
                            Console.WriteLine(getdir.Name + "\t" + getdir.Properties["WAMUserName"][0] + "\t" + getdir.Properties["WAMUserPass"][0]);
                        }
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    return;
                }
                Console.ReadKey();
            }
        }
    }
}


本文出自 “博深” 博客,转载请与作者联系!

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

标签:sharepoint

原文地址:http://pclzr.blog.51cto.com/30415/1909733

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!