Example #1
0
 private string GetRegistryPath(Session session, RegistryRoot root, string key, string name)
 {
     bool allUsers = session.EvaluateCondition("ALLUSERS = 1", true);
     string rootName = "????";
     switch(root)
     {
         case RegistryRoot.LocalMachine : rootName = "HKLM"; break;
         case RegistryRoot.CurrentUser  : rootName = "HKCU"; break;
         case RegistryRoot.Users        : rootName = "HKU"; break;
         case RegistryRoot.UserOrMachine: rootName = (allUsers ? "HKLM" : "HKCU"); break;
         case RegistryRoot.ClassesRoot  : rootName = (allUsers ? @"HKLM\Software\Classes" : @"HKCU\Software\Classes"); break;
         // TODO: Technically, RegistryRoot.ClassesRoot should be under HKLM on NT4.
     }
     if(name.Length == 0) name = "(Default)";
     if(name == "+" || name == "*") name = "";
     else name = " : " + name;
     using(Record formatRec = new Record(0))
     {
         formatRec[0] = String.Format(@"{0}\{1}{2}", rootName, key, name);
         return session.FormatRecord(formatRec);
     }
 }
Example #2
0
        private object[][] GetComponentRegistryRows(string productCode, string componentCode, Session session, bool includeComponent)
        {
            ArrayList rows = new ArrayList();
            string componentPath = new ComponentInstallation(componentCode, productCode).Path;

            string componentKey = (string) session.Database.ExecuteScalar(
                "SELECT `Component` FROM `Component` WHERE `ComponentId` = '{0}'", componentCode);
            if(componentKey == null) return null;
            int attributes = Convert.ToInt32(session.Database.ExecuteScalar(
                "SELECT `Attributes` FROM `Component` WHERE `Component` = '{0}'", componentKey));
            bool registryKeyPath = (attributes & (int) ComponentAttributes.RegistryKeyPath) != 0;
            if(!registryKeyPath && componentPath.Length > 0) componentPath = Path.GetDirectoryName(componentPath);
            string keyPath = (string) session.Database.ExecuteScalar(
                "SELECT `KeyPath` FROM `Component` WHERE `Component` = '{0}'", componentKey);

            using (View view = session.Database.OpenView("SELECT `Registry`, `Root`, `Key`, `Name`, " +
                "`Value` FROM `Registry` WHERE `Component_` = '{0}'", componentKey))
            {
                view.Execute();

                foreach (Record rec in view) using (rec)
                {
                    string regName = (string) rec["Name"];
                    if(regName == "-") continue;  // Don't list deleted keys

                    string regTableKey = (string) rec["Registry"];
                    bool isKey = registryKeyPath && keyPath == regTableKey;
                    string regPath = this.GetRegistryPath(session, (RegistryRoot) Convert.ToInt32(rec["Root"]),
                        (string) rec["Key"], (string) rec["Name"]);

                    string dbValue;
                    using(Record formatRec = new Record(0))
                    {
                        formatRec[0] = rec["Value"];
                        dbValue = session.FormatRecord(formatRec);
                    }

                    string installedValue = this.GetRegistryValue(regPath);
                    bool exists = installedValue != null;
                    if(!exists) installedValue = "";
                    bool match = installedValue == dbValue;

                    object[] row;
                    if(includeComponent) row = new object[] { isKey, regTableKey, regPath, exists, dbValue, installedValue, match, componentCode };
                    else row = new object[] { isKey, regTableKey, regPath, exists, dbValue, installedValue, match };
                    rows.Add(row);
                }
            }

            return (object[][]) rows.ToArray(typeof(object[]));
        }