Beispiel #1
0
            // Create a new application pool in IIS
            public static void Create(string machine, ApplicationPool item)
            {
                using (DirectoryEntry root = DirectoryEntryTool.GetRoot(DirectoryEntryTool.RootType.AppPool, machine))
                {
                    DirectoryEntry entry = root.Invoke("Create", "IIsApplicationPool", item.Name) as DirectoryEntry;
                    if (entry != null)
                    {
                        if (IISTools.IISMajorVersionNumber > 6)
                        {
                            entry.Properties["Enable32BitAppOnWin64"].Value = item.Enable32BitAppOnWin64;
                        }

                        if (IISTools.IISMajorVersionNumber >= 7)
                        {
                            entry.Properties["ManagedRuntimeVersion"].Value = item.ManagedRuntimeVersion;
                            entry.Properties["ManagedPipelineMode"].Value   = (int)item.ManagedPipelineMode;
                        }

                        entry.InvokeSet("AppPoolIdentityType", new Object[] { (int)item.AppPoolIdentityType });

                        entry.CommitChanges();
                        entry.Dispose();
                    }

                    root.CommitChanges();
                }
            }
Beispiel #2
0
            // Get the names of all the application pools in IIS
            public static List <ApplicationPool> FindAll(string machine)
            {
                using (DirectoryEntry root = DirectoryEntryTool.GetRoot(DirectoryEntryTool.RootType.AppPool, machine))
                {
                    List <ApplicationPool> result = new List <ApplicationPool>();
                    foreach (DirectoryEntry entry in root.Children)
                    {
                        ApplicationPool item = new ApplicationPool();
                        item.Name = entry.Name;

                        if (IISTools.IISMajorVersionNumber > 6)
                        {
                            if (entry.Properties.Contains("Enable32BitAppOnWin64"))
                            {
                                item.Enable32BitAppOnWin64 = (bool)entry.Properties["Enable32BitAppOnWin64"].Value;
                            }
                        }

                        if (IISTools.IISMajorVersionNumber >= 7)
                        {
                            if (entry.Properties.Contains("ManagedRuntimeVersion"))
                            {
                                item.ManagedRuntimeVersion = (string)entry.Properties["ManagedRuntimeVersion"].Value;
                            }

                            if (entry.Properties.Contains("ManagedPipelineMode"))
                            {
                                int value = (int)entry.Properties["ManagedPipelineMode"].Value;
                                if (Enum.IsDefined(typeof(PipelineMode), value))
                                {
                                    item.ManagedPipelineMode = (PipelineMode)value;
                                }
                                else
                                {
                                    item.ManagedPipelineMode = PipelineMode.Other;
                                }
                            }
                        }

                        try
                        {
                            int value = (int)entry.InvokeGet("AppPoolIdentityType");
                            if (Enum.IsDefined(typeof(IdentityType), value))
                            {
                                item.AppPoolIdentityType = (IdentityType)value;
                            }
                            else
                            {
                                item.AppPoolIdentityType = IdentityType.Other;
                            }
                        }
                        catch { }

                        result.Add(item);
                    }

                    return(result);
                }
            }
Beispiel #3
0
 // Delete an application pool from IIS
 public static void Delete(string machine, string name)
 {
     using (DirectoryEntry root = DirectoryEntryTool.GetRoot(DirectoryEntryTool.RootType.AppPool, machine))
     {
         root.Invoke("Delete", "IIsApplicationPool", name);
         root.CommitChanges();
     }
 }
Beispiel #4
0
 // Delete a virtual directory
 public static void Delete(string machine, string name)
 {
     using (DirectoryEntry root = DirectoryEntryTool.GetRoot(DirectoryEntryTool.RootType.IIS, machine))
     {
         using (DirectoryEntry entry = DirectoryEntryTool.GetVirtualDirectory(machine, root, name))
         {
             root.Children.Remove(entry);
             root.CommitChanges();
         }
     }
 }
Beispiel #5
0
            // Create a virtual directory
            public static void Create(string machine, VirtualDirectory item)
            {
                using (DirectoryEntry root = DirectoryEntryTool.GetRoot(DirectoryEntryTool.RootType.IIS, machine))
                {
                    using (DirectoryEntry entry = DirectoryEntryTool.GetVirtualDirectory(machine, root, item.Name))
                    {
                        root.CommitChanges();
                        entry.CommitChanges();

                        SetProperties(entry, item);
                    }
                }
            }
Beispiel #6
0
            public static void UpdateEnable32BitAppOnWin64(string machine, ApplicationPool item, bool value)
            {
                using (DirectoryEntry root = DirectoryEntryTool.GetRoot(DirectoryEntryTool.RootType.AppPool, machine))
                {
                    using (DirectoryEntry pool = root.Children.Find(item.Name, "IIsApplicationPool"))
                    {
                        pool.Properties["Enable32BitAppOnWin64"].Value = value;

                        pool.CommitChanges();

                        item.Enable32BitAppOnWin64 = value;
                    }
                }
            }
Beispiel #7
0
            // Get the names of all the virtual directories in IIS
            public static List <VirtualDirectory> FindAll(string machine)
            {
                List <VirtualDirectory> result = new List <VirtualDirectory>();

                using (DirectoryEntry root = DirectoryEntryTool.GetRoot(DirectoryEntryTool.RootType.IIS, machine))
                {
                    foreach (DirectoryEntry entry in root.Children)
                    {
                        VirtualDirectory item = new VirtualDirectory();
                        item.Name = entry.Name;

                        if (entry.Properties.Contains("Path"))
                        {
                            item.Path = (string)entry.Properties["Path"].Value;
                        }
                        else
                        {
                            item.Path = null;
                        }

                        if (entry.Properties.Contains("AppFriendlyName"))
                        {
                            item.AppFriendlyName = (string)entry.Properties["AppFriendlyName"].Value;
                        }
                        else
                        {
                            item.AppFriendlyName = null;
                        }

                        if (entry.Properties.Contains("AppPoolId"))
                        {
                            item.AppPoolId = (string)entry.Properties["AppPoolId"].Value;
                        }
                        else
                        {
                            item.AppPoolId = null;
                        }

                        result.Add(item);
                    }
                }

                return(result);
            }