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"; The "3" application pool runs as a specific user account, the "0" application pool runs as LocalSystem, the "1" application pool runs as LocalService, and the "2" application pool runs as 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 ();
}
}
}
}
This article from "Bo shen" blog, reproduced please contact the author!
Modify the identity of all application pool in native IIS (except Officeserverapplicationpool) C #