Modify the identity of all application pool in native IIS (except Officeserverapplicationpool) C #

Source: Internet
Author: User

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 #

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.