using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.DirectoryServices;
using System.Collections;app
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];ide
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();
}
}
}
}spa