Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Is there a way to register user and password for an account on IIS?
- using ( new Impersonator( "myUsername", "myDomainname", "myPassword" ) )
- {
- // <code that executes under the new context>
- }
- //Initialize the metabase path
- string metabasePath = "IIS://localhost/W3SVC/AppPools";
- //Specify the name for your application pool
- string appPoolName = "testAppPool"; //specify the domain account as domainusername
- //Specify the identity that will run the application pool
- string appPoolUser = "User1";
- //Specify the password for the user
- string appPoolPass = "Password1";
- DirectoryEntry pool1;
- DirectoryEntry apppools = new DirectoryEntry(metabasePath);
- pool1 = apppools.Children.Find(appPoolName, "IIsApplicationPool");
- /*Change Application Pool Identity*/
- pool1.InvokeSet("AppPoolIdentityType", new Object[] { 3 });
- pool1.InvokeSet("WAMUserName", new Object[] { Environment.MachineName + @"" + appPoolUser }); //If you are using a local account
- pool1.InvokeSet("WAMUserPass", new Object[] { appPoolPass });
- /*Commit changes*/
- pool1.CommitChanges();
Add Comment
Please, Sign In to add comment