Exemplo n.º 1
0
        /*public static List<string> GetAppsRegistry()
         * {
         *  List<string> retList = new List<string>();
         *  try
         *  {
         *      RegistryKey softwareKey = Registry.LocalMachine.OpenSubKey("SOFTWARE");
         *      foreach (string subKeyName in softwareKey.GetSubKeyNames())
         *      {
         *          retList.Add(subKeyName);
         *      }
         *  }
         *  catch (Exception ex)
         *  {
         *      Beaprint.GrayPrint("Error: "+ex);
         *  }
         *  return retList;
         * }*/

        public static SortedDictionary <string, Dictionary <string, string> > GetInstalledAppsPermsPath(string fpath)
        {
            SortedDictionary <string, Dictionary <string, string> > results = new SortedDictionary <string, Dictionary <string, string> >();

            try
            {
                foreach (string f in Directory.GetFiles(fpath))
                {
                    results[f] = new Dictionary <string, string>()
                    {
                        { f, String.Join(", ", MyUtils.GetPermissionsFile(f, Program.currentUserSIDs)) }
                    };
                }
                foreach (string d in Directory.GetDirectories(fpath))
                {
                    results[d] = MyUtils.GetRecursivePrivs(d);
                }
            }
            catch (Exception ex)
            {
                Beaprint.GrayPrint("Error: " + ex);
            }
            return(results);
        }
Exemplo n.º 2
0
        public static SortedDictionary <string, Dictionary <string, string> > GetInstalledAppsPerms()
        {
            //Get from Program Files
            SortedDictionary <string, Dictionary <string, string> > results  = GetInstalledAppsPermsPath(@Path.GetPathRoot(Environment.SystemDirectory) + "Program Files");
            SortedDictionary <string, Dictionary <string, string> > results2 = GetInstalledAppsPermsPath(@Path.GetPathRoot(Environment.SystemDirectory) + "Program Files (x86)");

            results.Concat(results2).ToDictionary(kvp => kvp.Key, kvp => kvp.Value);

            //Get from Uninstall
            string[] subkeys = MyUtils.GetRegSubkeys("HKLM", @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall");
            if (subkeys != null)
            {
                foreach (string app in subkeys)
                {
                    string installLocation = MyUtils.GetRegValue("HKLM", String.Format(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{0}", app), "InstallLocation");
                    if (String.IsNullOrEmpty(installLocation))
                    {
                        continue;
                    }

                    installLocation = installLocation.Replace("\"", "");

                    if (installLocation.EndsWith(@"\"))
                    {
                        installLocation = installLocation.Substring(0, installLocation.Length - 1);
                    }

                    if (!results.ContainsKey(installLocation) && Directory.Exists(installLocation))
                    {
                        bool already = false;
                        foreach (string path in results.Keys)
                        {
                            if (installLocation.IndexOf(path) != -1) //Check for subfoldres of already found folders
                            {
                                already = true;
                                break;
                            }
                        }
                        if (!already)
                        {
                            results[installLocation] = MyUtils.GetRecursivePrivs(installLocation);
                        }
                    }
                }
            }

            subkeys = MyUtils.GetRegSubkeys("HKLM", @"SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall");
            if (subkeys != null)
            {
                foreach (string app in subkeys)
                {
                    string installLocation = MyUtils.GetRegValue("HKLM", String.Format(@"SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\{0}", app), "InstallLocation");
                    if (String.IsNullOrEmpty(installLocation))
                    {
                        continue;
                    }

                    installLocation = installLocation.Replace("\"", "");

                    if (installLocation.EndsWith(@"\"))
                    {
                        installLocation = installLocation.Substring(0, installLocation.Length - 1);
                    }

                    if (!results.ContainsKey(installLocation) && Directory.Exists(installLocation))
                    {
                        bool already = false;
                        foreach (string path in results.Keys)
                        {
                            if (installLocation.IndexOf(path) != -1) //Check for subfoldres of already found folders
                            {
                                already = true;
                                break;
                            }
                        }
                        if (!already)
                        {
                            results[installLocation] = MyUtils.GetRecursivePrivs(installLocation);
                        }
                    }
                }
            }

            return(results);
        }