public COMAdminCatalogCollection GetCatalogCollection()
 {
     if (oAppCollection == null)
     {
         oAppCollection = (COMAdminCatalogCollection)GetCatalog().GetCollection("Applications");
         oAppCollection.Populate();
     }
     return(oAppCollection);
 }
Example #2
0
        /// <summary>
        /// Configures a COM+ application associated with the specified IIS virtual directory
        /// to run under the interactive user account instead of a system account.
        /// </summary>
        /// <param name="name">The virtual directory name</param>
        /// <returns>True if successful, otherwise false</returns>
        public static bool SetVirtualDirectoryHostIdentity(string name)
        {
            try
            {
                // Set application pool identity on IIS 6.0
                if (IsOldIsolationMode())
                {
                    // Instantiate the admin object
                    Type     type    = Type.GetTypeFromProgID("COMAdmin.COMAdminCatalog");
                    object   catalog = Activator.CreateInstance(type);
                    object[] args    = new object[] { "Applications" };

                    // Get the COM+ applications collection
                    COMAdminCatalogCollection apps = (COMAdminCatalogCollection)type.InvokeMember("GetCollection",
                                                                                                  BindingFlags.InvokeMethod, null, catalog, args);
                    apps.Populate();

                    string appName = "//root/" + name.ToLower() + "}";

                    // Look for our COM+ application
                    foreach (COMAdminCatalogObject app in apps)
                    {
                        if (app.Name.ToString().ToLower().EndsWith(appName))
                        {
                            // Set logon to interactive user
                            app.set_Value("Identity", "Interactive User");
                            app.set_Value("Password", "");
                            apps.SaveChanges();
                        }
                    }
                }
                else
                {
                    // Get pool object
                    DirectoryEntry pool = new DirectoryEntry("IIS://localhost/W3SVC/AppPools/" + name);

                    // Set properties
                    pool.Properties["AppPoolIdentityType"][0] = 3;
                    pool.Properties["WAMUserName"][0]         = "Interactive User";
                    pool.Properties["WAMUserPass"][0]         = "";

                    // Save changes
                    pool.CommitChanges();
                }
            }
            catch
            {
                return(false);
            }

            return(true);
        }
 static void Main(string[] args)
 {
     COMAdminCatalog catalog = new COMAdminCatalog();
     COMAdminCatalogCollection applications = catalog.GetCollection("Applications");
     applications.Populate();
     for (int i = 0; i < applications.Count; i++)
     {
         COMAdminCatalogObject application = applications.Item[i];
         Console.WriteLine(application.Name);
         Console.WriteLine(application.Value["Identity"]);
     }
     Console.WriteLine("Press any key to continue...");
     Console.ReadKey();
 }
 public COMAdminCatalogCollection GetAppItems()
 {
     if (oCollection == null)
     {
         try
         {
             COMAdminCatalogCollection appColl = GetCatalogCollection();
             foreach (COMAdminCatalogObject app in appColl)
             {
                 if (app.Name.ToString().ToLower() == "")                         //Config.ComApplication.ToLower() )
                 {
                     oCollection = (COMAdminCatalogCollection)appColl.GetCollection("Components", app.Key);
                     oCollection.Populate();
                     break;
                 }
             }
         }
         catch (Exception oEx)
         {
             Common.Log.Write(this, oEx);
         }
     }
     return(oCollection);
 }
Example #5
0
        static private void performccreatecomappop(appoptions apopts)
        {
            try
            {
                bool bins   = ((apopts & appoptions.install) != 0);
                bool bunins = ((apopts & appoptions.uninstall) != 0);
                bool bstart = ((apopts & appoptions.start) != 0);
                bool bstop  = ((apopts & appoptions.stop) != 0);

                COMAdminCatalog           catalog      = new COMAdminCatalog();
                COMAdminCatalogCollection applications = catalog.GetCollection("Applications") as COMAdminCatalogCollection;
                applications.Populate();
                if (bins || bunins || bstart || bstop || breg)
                {
                    for (int i = 0; i < applications.Count; ++i)
                    {
                        COMAdminCatalogObject app = applications.get_Item(i) as COMAdminCatalogObject;
                        if (app.Name.ToString() == appname)
                        {
                            if (bstart)
                            {
                                catalog.StartApplication(appname);
                                return;
                            }

                            catalog.ShutdownApplication(appname);
                            if (bins || bunins)
                            {
                                applications.Remove(i);
                                applications.SaveChanges();
                            }
                            break;
                        }
                    }


                    if (bins)
                    {
                        applications.Populate();

                        COMAdminCatalogObject application = applications.Add() as COMAdminCatalogObject;
                        application.Value["ID"]         = Guid.NewGuid().ToString("B");
                        application.Value["Name"]       = appname;
                        application.Value["RunForever"] = brunforever;
                        applications.SaveChanges();

                        if (System.Environment.OSVersion.Version.Major > 5)
                        {
                            COMAdminCatalogCollection roles = (COMAdminCatalogCollection)applications.GetCollection("Roles", application.Key);
                            roles.Populate();
                            COMAdminCatalogObject role = roles.Add() as COMAdminCatalogObject;
                            role.Value["Name"] = "DefaultRole";
                            roles.SaveChanges();
                            COMAdminCatalogCollection users = (COMAdminCatalogCollection)roles.GetCollection("UsersInRole", role.Key);
                            users.Populate();
                            COMAdminCatalogObject user = users.Add() as COMAdminCatalogObject;
                            user.Value["User"] = "******";
                            users.SaveChanges();
                        }
                        applications.SaveChanges();
                    }
                }

                if (breg || bunreg)
                {
                    if (data.Count == 0)
                    {
                        if (filename == "")
                        {
                            ShowSyntax();
                        }

                        List <KeyValuePair <string, string> > progclsidlst = new List <KeyValuePair <string, string> >();
                        if (filename.ToLower().IndexOf(".wsc") != -1)
                        {
                            progclsidlst = CodeGenHelper.GetclsidsfromWSC(filename);
                        }
                        else
                        {
                            progclsidlst = CodeGenHelper.GetclsidsfromAssembly(filename);
                            if (progclsidlst.Count == 0)
                            {
                                progclsidlst = CodeGenHelper.GetclsidsfromTLB(filename);
                            }
                        }

                        foreach (var kv in progclsidlst)
                        {
                            data.Add(kv.Key);
                        }
                    }

                    foreach (string d in data)
                    {
                        if (breg)
                        {
                            catalog.ImportComponent(appname, d);
                        }
                    }
                }
                else if (bgac || bungac)
                {
                    if (bgac)
                    {
                        catalog.InstallComponent(appname, filename, "", "");
                    }
                }

                applications.SaveChanges();
            }
            catch
            {
            }
        }