Add application pool to the website

            DirectoryEntry _RootFolder = new DirectoryEntry("IIS://localhost/W3SVC/1/ROOT");
            DirectoryEntry _VirDir = _RootFolder.Children.Add(@"OKWeb", "IIsWebVirtualDir");
            _VirDir.Properties["Path"].Value = @"C:\test"; //设置路径
            _VirDir.Invoke("AppCreate", true);
            //设置名称
            _VirDir.Properties["AppFriendlyName"].Value = "OkWeb";
            _VirDir.Properties["AppIsolated"].Value = 2;
            _VirDir.CommitChanges();
            _RootFolder.CommitChanges();

原文地址:https://www.cnblogs.com/greencolor/p/1787265.html