Exemplo n.º 1
0
        public static int RemoveConfigurationDataForIP(string packID, SqlConnection scoConnection)
        {
            packID = GuidUtilities.RemoveBracesFromGuid(packID);
            string queryString = string.Format("DELETE FROM [Orchestrator].[dbo].[CONFIGURATION] Where AND DataValue like '%{0}%' ", packID);

            return(SQLUtilities.RunDeleteQuery(queryString, scoConnection));
        }
Exemplo n.º 2
0
        public static int RemoveActivityType(string typeID, SqlConnection scoConnection, bool replaceWithUnknown, bool deletedOnly)
        {
            //TODO: Also need to remove QIKOBJECT instances
            int    numAffected = 0;
            string whereClause = string.Empty;

            if (deletedOnly)
            {
                whereClause = string.Format("WHERE obj.ObjectType = '{0}' AND obj.Deleted = 1)", typeID);
            }
            else
            {
                whereClause = string.Format("WHERE obj.ObjectType = '{0}')", typeID);
            }

            StringBuilder sb = new StringBuilder();

            typeID = GuidUtilities.RemoveBracesFromGuid(typeID);
            if (replaceWithUnknown)
            {
                sb.Append("UPDATE [Orchestrator].[dbo].[OBJECTS] obj");
                sb.Append("SET obj.ObjectType = 'DDDDDDDD-DDDD-DDDD-DDDD-DDDDDDDDDDDD', set obj.Enabled = 0");
                sb.Append(whereClause);
            }
            else
            {
                sb.Append("DELETE FROM [Orchestrator].[dbo].[OBJECTS]");
                sb.Append(whereClause);
            }
            numAffected += SQLUtilities.RunDeleteQuery(sb.ToString(), scoConnection);
            return(numAffected);
        }
Exemplo n.º 3
0
        public static int RemoveCapDataForIP(string packID, SqlConnection scoConnection)
        {
            packID = GuidUtilities.RemoveBracesFromGuid(packID);
            string queryString = string.Format("DELETE FROM [Orchestrator].[dbo].[CAPS] Where UniqueID = '{0}'", packID);

            return(SQLUtilities.RunDeleteQuery(queryString, scoConnection));
        }
Exemplo n.º 4
0
        public static string GetDeployedIpVersion(string productCode, string computerName)
        {
            string version = string.Empty;

            string uninstallKey = GuidUtilities.AddBracesToGuid(productCode);

            RegistryKey key;

            if ((string.IsNullOrEmpty(computerName) || (Utilities.IsLocalComputer(computerName))))
            {
                key = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64);
            }
            else
            {
                key = RegistryKey.OpenRemoteBaseKey(RegistryHive.LocalMachine, computerName, RegistryView.Registry64);
            }
            string      baseKey = @"SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\";
            RegistryKey ipKey   = key.OpenSubKey(baseKey + uninstallKey);

            if (null == ipKey)
            {
                return(string.Empty);
            }
            object versionObj = ipKey.GetValue("DisplayVersion");

            if (null != versionObj)
            {
                return(versionObj.ToString());
            }
            return(string.Empty);
        }
Exemplo n.º 5
0
        public static bool IpIsDeployed(string productCode, string computerName)
        {
            // check this key: HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\SystemCenter2012\Orchestrator\IPs
            // and enumerate the subkeys to find the one matching the programcode (this key is set when msi is installed)

            RegistryKey key;

            if ((string.IsNullOrEmpty(computerName) || (Utilities.IsLocalComputer(computerName))))
            {
                key = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64);
            }
            else
            {
                key = RegistryKey.OpenRemoteBaseKey(RegistryHive.LocalMachine, computerName, RegistryView.Registry64);
            }
            RegistryKey ipKey = key.OpenSubKey(_ipsRegistryKey);

            String[] ValueNames = ipKey.GetValueNames();
            foreach (string name in ValueNames)
            {
                string value = ipKey.GetValue(name).ToString();
                if (string.Compare(value, GuidUtilities.AddBracesToGuid(productCode), true) == 0)
                {
                    return(true);
                }
            }

            return(false);
        }
Exemplo n.º 6
0
        public static int RemoveLinkTriggersForActivityType(string typeID, SqlConnection scoConnection, bool deletedOnly)
        {
            StringBuilder sb = new StringBuilder();

            typeID = GuidUtilities.RemoveBracesFromGuid(typeID);

            sb.Append("DELETE FROM [Orchestrator].[dbo].[TRIGGERS]");
            sb.Append("WHERE ParentID IN");
            sb.Append(GetSelectObjectTypeSubQueryString(typeID, deletedOnly));

            return(SQLUtilities.RunDeleteQuery(sb.ToString(), scoConnection));
        }
Exemplo n.º 7
0
        public static int RemoveJobDataForActivityType(string typeID, SqlConnection scoConnection, bool deletedOnly)
        {
            StringBuilder sb = new StringBuilder();

            typeID = GuidUtilities.RemoveBracesFromGuid(typeID);

            sb.Append(" DELETE FROM [Orchestrator].[dbo].[OBJECTINSTANCEDATA] ");
            sb.Append(" WHERE ObjectInstanceID IN ");
            sb.Append(" (SELECT UniqueID FROM [Orchestrator].[dbo].[OBJECTINSTANCES] ");
            sb.Append("  WHERE ObjectID IN ");
            sb.Append(GetSelectObjectTypeSubQueryString(typeID, deletedOnly));
            sb.Append(string.Format(")", typeID));
            return(SQLUtilities.RunDeleteQuery(sb.ToString(), scoConnection));
        }
Exemplo n.º 8
0
        private static string GetSelectObjectTypeSubQueryString(string typeID, bool deletedOnly)
        {
            StringBuilder sb = new StringBuilder();

            typeID = GuidUtilities.RemoveBracesFromGuid(typeID);

            sb.Append("(SELECT obj.UniqueID FROM [Orchestrator].[dbo].[OBJECTS] obj");

            if (deletedOnly)
            {
                sb.Append(string.Format("WHERE obj.ObjectType = '{0}' AND obj.Deleted = 1)", typeID));
            }
            else
            {
                sb.Append(string.Format("WHERE obj.ObjectType = '{0}')", typeID));
            }
            return(sb.ToString());
        }
Exemplo n.º 9
0
        public static string BuildActivityTypesListForQuery(string packID)
        {
            StringBuilder queryString = new StringBuilder();

            Dictionary <string, string> activitiesList = new Dictionary <string, string>();

            activitiesList = GetActivitesInIP(packID);
            if (activitiesList != null)
            {
                int i = 0;
                queryString.Append(" (");
                foreach (string activityID in activitiesList.Values)
                {
                    if (i > 0)
                    {
                        queryString.Append(", ");
                    }
                    queryString.Append(string.Format("'{0}'", GuidUtilities.RemoveBracesFromGuid(activityID)));
                    i++;
                }
                queryString.Append(")");
                return(queryString.ToString());
            }
            else
            {
                Dictionary <string, string> aList = new Dictionary <string, string>();
                aList = GetActivitesInIP(packID);
                int i = 0;
                queryString.Append(" (");
                foreach (string activityID in aList.Values)
                {
                    if (i > 0)
                    {
                        queryString.Append(", ");
                    }
                    queryString.Append(string.Format("'{0}'", GuidUtilities.RemoveBracesFromGuid(activityID)));
                    i++;
                }
                queryString.Append(")");
                return(queryString.ToString());
            }
        }
Exemplo n.º 10
0
        public static string GetOIPFilePath(string packID, string managementServerName)
        {
            string oipFile = Path.Combine(_scoCommonFilesFolder, _packsPath, GuidUtilities.AddBracesToGuid(packID) + ".oip");

            if ((string.IsNullOrEmpty(managementServerName) || (Utilities.IsLocalComputer(managementServerName))))
            {
                if (File.Exists(oipFile))
                {
                    return(oipFile);
                }
            }
            else
            {
                if (File.Exists(oipFile))
                {
                    return(oipFile);
                }
            }
            return(null);
        }
Exemplo n.º 11
0
        public static List <string> GetRunbookNamesWhereActivityTypeIsUsed(string typeID, SqlConnection scoConnection)
        {
            List <string> runbookList = new List <string>();
            StringBuilder queryString = new StringBuilder();

            queryString.Append("Select DISTINCT Name FROM [Orchestrator].[dbo].[POLICIES] WHERE UniqueID IN ");
            queryString.Append("(Select ParentID from [Orchestrator].[dbo].[OBJECTS] ");
            queryString.Append(string.Format("Where ObjectType = '{0}')", GuidUtilities.RemoveBracesFromGuid(typeID)));

            SqlDataReader myReader  = null;
            SqlCommand    myCommand = new SqlCommand(queryString.ToString(), scoConnection);

            myReader = myCommand.ExecuteReader();

            //read the list
            while (myReader.Read())
            {
                //insert into list
                runbookList.Add(myReader[0].ToString());
            }
            myReader.Close();
            return(runbookList);
        }
Exemplo n.º 12
0
        public static string UninstallMsi(string productCode, string computerName, ConnectionOptions connectionOptions)
        {
            //uses WMI to uninstall the application, then deletes the MSI from the Management Server path

            StringBuilder log = new StringBuilder();

            string selectQuery = string.Format("Select * FROM Win32_Product Where IdentifyingNumber = '{0}'", GuidUtilities.AddBracesToGuid(productCode));

            //ConnectionOptions oConn = new ConnectionOptions();
            //oConn.Username = "******";
            //oConn.Password = "******";

            ManagementObjectCollection products = WMIUtilities.QueryWMI(selectQuery, computerName, connectionOptions);

            log.AppendLine(string.Format("Found [{0}] matches", products.Count));
            foreach (ManagementObject product in products)
            {
                log.Append(string.Format("Uninstalling '{0}'", product.Properties["Name"].ToString()));

                var result = product.InvokeMethod("Uninstall", null);
                log.Append(string.Format("The Uninstall method result is {0}", result.ToString()));
            }
            return(log.ToString());
        }