Ejemplo n.º 1
0
        /// <summary>
        /// Checks MUI Cache for invalid file references (XP Only)
        /// </summary>
        private static void ScanMUICache()
        {
            try
            {
                using (RegistryKey regKey = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\ShellNoRoam\MUICache"))
                {
                    if (regKey == null)
                        return;

                    foreach (string valueName in regKey.GetValueNames())
                    {
                        if (valueName.StartsWith("@") || valueName == "LangID")
                            continue;

                        ScannerFunctions.CurrentScannedObject = valueName;

                        if (!Utils.FileExists(valueName))
                            ScannerFunctions.StoreInvalidKey(Strings.InvalidFile, regKey.Name, valueName);
                    }
                }
            }
            catch (System.Security.SecurityException ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.Message);
            }
        }
Ejemplo n.º 2
0
        private static void ScanRegistryKey(RegistryKey baseRegKey)
        {
            if (baseRegKey == null)
            {
                return;
            }


            foreach (string strSubKey in baseRegKey.GetSubKeyNames())
            {
                // Skip needed keys, we dont want to mess the system up
                //if (strSubKey == "Microsoft" ||
                //    strSubKey == "Policies" ||
                //    strSubKey == "Classes" ||
                //    strSubKey == "Printers" ||
                //    strSubKey == "Wow6432Node")
                //    continue;

                if (IsEmptyRegistryKey(baseRegKey.OpenSubKey(strSubKey, true)))
                {
                    ScannerFunctions.StoreInvalidKey(Strings.NoRegKey, baseRegKey.Name + "\\" + strSubKey);
                }
            }

            baseRegKey.Close();
            return;
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Scan for missing links to DLLS
        /// </summary>
        public static void Scan()
        {
            try
            {
                RegistryKey regKey = Registry.LocalMachine.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\SharedDLLs");

                if (regKey == null)
                {
                    return;
                }


                // Validate Each DLL from the value names
                foreach (string strFilePath in regKey.GetValueNames())
                {
                    // Update scan dialog
                    ScannerFunctions.CurrentScannedObject = strFilePath;

                    if (!string.IsNullOrEmpty(strFilePath))
                    {
                        if (!Utils.FileExists(strFilePath))
                        {
                            ScannerFunctions.StoreInvalidKey(Strings.InvalidFile, regKey.Name, strFilePath);
                        }
                    }
                }

                regKey.Close();
            }
            catch (System.Security.SecurityException ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.Message);
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Scans for invalid references to fonts
        /// </summary>
        public static void Scan()
        {
            try
            {
                using (RegistryKey regKey = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Drivers32"))
                {
                    if (regKey == null)
                    {
                        return;
                    }


                    foreach (string strDriverName in regKey.GetValueNames())
                    {
                        string strValue = regKey.GetValue(strDriverName) as string;

                        ScannerFunctions.CurrentScannedObject = strValue;

                        if (!string.IsNullOrEmpty(strValue))
                        {
                            if (!Utils.FileExists(strValue))
                            {
                                ScannerFunctions.StoreInvalidKey(Strings.InvalidFile, regKey.Name, strDriverName);
                            }
                        }
                    }
                }
            }
            catch (System.Security.SecurityException ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.Message);
            }
        }
Ejemplo n.º 5
0
        private static void EnumMRUList(RegistryKey regKey)
        {
            foreach (string strValueName in regKey.GetValueNames())
            {
                string filePath, fileArgs;

                // Ignore MRUListEx and others
                if (!Regex.IsMatch(strValueName, "[0-9]"))
                    continue;

                string fileName = ExtractUnicodeStringFromBinary(regKey.GetValue(strValueName));
                
                // If filename is empty -> remove it
                if (string.IsNullOrEmpty(fileName.Trim()))
                {
                    ScannerFunctions.StoreInvalidKey(Strings.InvalidRegKey, regKey.ToString(), strValueName);
                    continue;
                }
                else
                {
                    string shortcutPath = string.Format("{0}\\{1}.lnk", Environment.GetFolderPath(Environment.SpecialFolder.Recent), fileName);

                    ScannerFunctions.CurrentScannedObject = shortcutPath;

                    // See if file exists in Recent Docs folder
                    if (!Utils.FileExists(shortcutPath) || !Utils.ResolveShortcut(shortcutPath, out filePath, out fileArgs))
                    {
                        ScannerFunctions.StoreInvalidKey(Strings.InvalidFile, regKey.ToString(), strValueName);
                        continue;
                    }
                }
            }
        }
Ejemplo n.º 6
0
        private static void ScanAppPaths()
        {
            RegistryKey regKey = Registry.LocalMachine.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\App Paths");

            if (regKey == null)
            {
                return;
            }

            foreach (string strSubKey in regKey.GetSubKeyNames())
            {
                RegistryKey regKey2 = regKey.OpenSubKey(strSubKey);

                if (regKey2 != null)
                {
                    ScannerFunctions.CurrentScannedObject = regKey2.ToString();

                    if (Convert.ToInt32(regKey2.GetValue("BlockOnTSNonInstallMode")) == 1)
                    {
                        continue;
                    }

                    string strAppPath = regKey2.GetValue("") as string;
                    string strAppDir  = regKey2.GetValue("Path") as string;

                    if (string.IsNullOrEmpty(strAppPath))
                    {
                        ScannerFunctions.StoreInvalidKey(Strings.InvalidRegKey, regKey2.ToString());
                        continue;
                    }

                    if (!string.IsNullOrEmpty(strAppDir))
                    {
                        if (Utils.SearchPath(strAppPath, strAppDir))
                        {
                            continue;
                        }
                        else if (Utils.SearchPath(strSubKey, strAppDir))
                        {
                            continue;
                        }
                    }
                    else
                    {
                        if (Utils.FileExists(strAppPath))
                        {
                            continue;
                        }
                    }

                    ScannerFunctions.StoreInvalidKey(Strings.InvalidFile, regKey2.Name);
                }
            }

            regKey.Close();
        }
Ejemplo n.º 7
0
        private static void ValidateExplorerExt(RegistryKey regKey)
        {
            try
            {
                // Sees if icon file exists
                string strHotIcon = regKey.GetValue("HotIcon") as string;
                if (!string.IsNullOrEmpty(strHotIcon))
                {
                    if (!Utils.IconExists(strHotIcon))
                    {
                        ScannerFunctions.StoreInvalidKey(Strings.InvalidFile, regKey.ToString(), "HotIcon");
                    }
                }

                string strIcon = regKey.GetValue("Icon") as string;
                if (!string.IsNullOrEmpty(strIcon))
                {
                    if (!Utils.IconExists(strIcon))
                    {
                        ScannerFunctions.StoreInvalidKey(Strings.InvalidFile, regKey.ToString(), "Icon");
                    }
                }

                // Lookup CLSID extension
                string strClsidExt = regKey.GetValue("ClsidExtension") as string;
                if (!string.IsNullOrEmpty(strClsidExt))
                {
                    ScannerFunctions.StoreInvalidKey(Strings.MissingCLSID, regKey.ToString(), "ClsidExtension");
                }

                // See if files exist
                string strExec = regKey.GetValue("Exec") as string;
                if (!string.IsNullOrEmpty(strExec))
                {
                    if (!Utils.FileExists(strExec))
                    {
                        ScannerFunctions.StoreInvalidKey(Strings.InvalidFile, regKey.ToString(), "Exec");
                    }
                }

                string strScript = regKey.GetValue("Script") as string;
                if (!string.IsNullOrEmpty(strScript))
                {
                    if (!Utils.FileExists(strScript))
                    {
                        ScannerFunctions.StoreInvalidKey(Strings.InvalidFile, regKey.ToString(), "Script");
                    }
                }
            }
            catch (System.Security.SecurityException ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.Message);
            }
        }
Ejemplo n.º 8
0
        const int CSIDL_FONTS = 0x0014;    // windows\fonts

        /// <summary>
        /// Finds invalid font references
        /// </summary>
        public static void Scan()
        {
            StringBuilder strPath = new StringBuilder(260);

            try
            {
                using (RegistryKey regKey = Registry.LocalMachine.OpenSubKey("Software\\Microsoft\\Windows NT\\CurrentVersion\\Fonts"))
                {
                    if (regKey == null)
                    {
                        return;
                    }


                    if (!SHGetSpecialFolderPath(IntPtr.Zero, strPath, CSIDL_FONTS, false))
                    {
                        return;
                    }

                    foreach (string strFontName in regKey.GetValueNames())
                    {
                        string strValue = regKey.GetValue(strFontName) as string;

                        // Skip if value is empty
                        if (string.IsNullOrEmpty(strValue))
                        {
                            continue;
                        }

                        // Check value by itself
                        if (Utils.FileExists(strValue))
                        {
                            continue;
                        }

                        // Check for font in fonts folder
                        string strFontPath = String.Format("{0}\\{1}", strPath.ToString(), strValue);

                        ScannerFunctions.CurrentScannedObject = strFontPath;

                        if (!File.Exists(strFontPath))
                        {
                            ScannerFunctions.StoreInvalidKey(Strings.InvalidFile, regKey.ToString(), strFontName);
                        }
                    }
                }
            }
            catch (System.Security.SecurityException ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.Message);
            }
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Do a cross-reference check on ARP Cache keys
        /// </summary>
        /// <param name="regKey"></param>
        private static void checkARPCache(RegistryKey regKey)
        {
            if (regKey == null)
            {
                return;
            }

            foreach (string subKey in regKey.GetSubKeyNames())
            {
                if (Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\" + subKey) == null)
                {
                    ScannerFunctions.StoreInvalidKey(Strings.ObsoleteRegKey, string.Format("{0}/{1}", regKey.Name, subKey));
                }
            }
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Looks for invalid references to AppIDs
        /// </summary>
        private static void ScanAppIds(RegistryKey regKey)
        {
            if (regKey == null)
            {
                return;
            }


            try
            {
                foreach (string strAppId in regKey.GetSubKeyNames())
                {
                    using (RegistryKey rkAppId = regKey.OpenSubKey(strAppId))
                    {
                        if (rkAppId != null)
                        {
                            // Update scan dialog
                            ScannerFunctions.CurrentScannedObject = rkAppId.ToString();

                            // Check for reference to AppID
                            string strCLSID = rkAppId.GetValue("AppID") as string;

                            if (!string.IsNullOrEmpty(strCLSID))
                            {
                                if (!appidExists(strCLSID))
                                {
                                    ScannerFunctions.StoreInvalidKey(Strings.MissingAppID, rkAppId.ToString());
                                }
                            }
                        }
                    }
                }
            }
            catch (System.Security.SecurityException ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.Message);
            }
            catch (System.UnauthorizedAccessException ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.Message);
            }



            regKey.Close();
        }
Ejemplo n.º 11
0
        private static void ScanInstallFolders()
        {
            RegistryKey regKey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\Folders");

            if (regKey == null)
            {
                return;
            }

            foreach (string strFolder in regKey.GetValueNames())
            {
                ScannerFunctions.CurrentScannedObject = strFolder;

                if (!Utils.DirExists(strFolder))
                {
                    ScannerFunctions.StoreInvalidKey(Strings.InvalidFile, regKey.Name, strFolder);
                }
            }
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Checks for invalid files in startup registry key
        /// </summary>
        /// <param name="regKey">The registry key to scan</param>
        private static void checkAutoRun(RegistryKey regKey)
        {
            if (regKey == null)
            {
                return;
            }


            foreach (string strProgName in regKey.GetValueNames())
            {
                string strRunPath = regKey.GetValue(strProgName) as string;
                string strFilePath, strArgs;

                if (!string.IsNullOrEmpty(strRunPath))
                {
                    ScannerFunctions.CurrentScannedObject = strRunPath;

                    // Check run path by itself
                    if (Utils.FileExists(strRunPath))
                    {
                        continue;
                    }

                    // See if file exists (also checks if string is null)
                    if (Utils.ExtractArguments(strRunPath, out strFilePath, out strArgs))
                    {
                        continue;
                    }

                    if (Utils.ExtractArguments2(strRunPath, out strFilePath, out strArgs))
                    {
                        continue;
                    }

                    ScannerFunctions.StoreInvalidKey(Strings.InvalidFile, regKey.Name, strProgName);
                }
            }

            regKey.Close();
            return;
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Scans for invalid windows help files
        /// </summary>
        private static void CheckHelpFiles(RegistryKey regKey)
        {
            if (regKey == null)
            {
                return;
            }

            foreach (string strHelpFile in regKey.GetValueNames())
            {
                string strHelpPath = regKey.GetValue(strHelpFile) as string;

                ScannerFunctions.CurrentScannedObject = strHelpPath;

                if (!HelpFileExists(strHelpFile, strHelpPath))
                {
                    ScannerFunctions.StoreInvalidKey(Strings.InvalidFile, regKey.ToString(), strHelpFile);
                }
            }

            return;
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Goes deep into sub keys to see if files exist
        /// </summary>
        /// <param name="rk">Registry subkey</param>
        private static void ParseSoundKeys(RegistryKey rk)
        {
            foreach (string strSubKey in rk.GetSubKeyNames())
            {
                // Ignores ".Default" Subkey
                if ((strSubKey.CompareTo(".Current") == 0) || (strSubKey.CompareTo(".Modified") == 0))
                {
                    // Gets the (default) key and sees if the file exists
                    RegistryKey rk2 = rk.OpenSubKey(strSubKey);

                    if (rk2 != null)
                    {
                        ScannerFunctions.CurrentScannedObject = rk2.ToString();

                        string strSoundPath = rk2.GetValue("") as string;

                        if (!string.IsNullOrEmpty(strSoundPath))
                        {
                            if (!Utils.FileExists(strSoundPath))
                            {
                                ScannerFunctions.StoreInvalidKey(Strings.InvalidFile, rk2.Name, "(default)");
                            }
                        }
                    }
                }
                else if (!string.IsNullOrEmpty(strSubKey))
                {
                    RegistryKey rk2 = rk.OpenSubKey(strSubKey);
                    if (rk2 != null)
                    {
                        ScannerFunctions.CurrentScannedObject = rk2.ToString();
                        ParseSoundKeys(rk2);
                    }
                }
            }

            return;
        }
Ejemplo n.º 15
0
        /// <summary>
        /// Finds invalid File extensions + ProgIDs referenced
        /// </summary>
        private static void ScanClasses(RegistryKey regKey)
        {
            if (regKey == null)
            {
                return;
            }


            try
            {
                foreach (string strSubKey in regKey.GetSubKeyNames())
                {
                    // Update scan dialog
                    //ScannerFunctions.CurrentScannedObject = string.Format("{0}\\{1}", regKey.Name, strSubKey);

                    // Skip any file (*)
                    if (strSubKey == "*")
                    {
                        continue;
                    }

                    if (strSubKey[0] == '.')
                    {
                        // File Extension
                        using (RegistryKey rkFileExt = regKey.OpenSubKey(strSubKey))
                        {
                            if (rkFileExt != null)
                            {
                                // Find reference to ProgID
                                string strProgID = rkFileExt.GetValue("") as string;

                                if (!string.IsNullOrEmpty(strProgID))
                                {
                                    if (!progIDExists(strProgID))
                                    {
                                        ScannerFunctions.StoreInvalidKey(Strings.MissingProgID, rkFileExt.ToString());
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        // ProgID or file class

                        // See if DefaultIcon exists
                        using (RegistryKey regKeyDefaultIcon = regKey.OpenSubKey(string.Format("{0}\\DefaultIcon", strSubKey)))
                        {
                            if (regKeyDefaultIcon != null)
                            {
                                string iconPath = regKeyDefaultIcon.GetValue("") as string;

                                if (!string.IsNullOrEmpty(iconPath))
                                {
                                    if (!Utils.IconExists(iconPath))
                                    {
                                        ScannerFunctions.StoreInvalidKey(Strings.InvalidFile, regKeyDefaultIcon.Name);
                                    }
                                }
                            }
                        }

                        // Check referenced CLSID
                        using (RegistryKey rkCLSID = regKey.OpenSubKey(string.Format("{0}\\CLSID", strSubKey)))
                        {
                            if (rkCLSID != null)
                            {
                                string guid = rkCLSID.GetValue("") as string;

                                if (!string.IsNullOrEmpty(guid))
                                {
                                    if (!clsidExists(guid))
                                    {
                                        ScannerFunctions.StoreInvalidKey(Strings.MissingCLSID, string.Format("{0}\\{1}", regKey.Name, strSubKey));
                                    }
                                }
                            }
                        }
                    }

                    // Check for unused progid/extension
                    using (RegistryKey rk = regKey.OpenSubKey(strSubKey))
                    {
                        if (rk != null)
                        {
                            if (rk.ValueCount <= 0 && rk.SubKeyCount <= 0)
                            {
                                ScannerFunctions.StoreInvalidKey(Strings.InvalidProgIDFileExt, rk.Name);
                            }
                        }
                    }
                }
            }
            catch (System.Security.SecurityException ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.Message);
            }
            catch (System.UnauthorizedAccessException ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.Message);
            }

            regKey.Close();

            return;
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Scans for the CLSID subkey
        /// <param name="regKey">Location of CLSID Sub Key</param>
        /// </summary>
        private static void ScanCLSIDSubKey(RegistryKey regKey)
        {
            if (regKey == null)
            {
                return;
            }

            try
            {
                foreach (string strCLSID in regKey.GetSubKeyNames())
                {
                    RegistryKey rkCLSID = regKey.OpenSubKey(strCLSID);

                    if (rkCLSID == null)
                    {
                        continue;
                    }

                    ScannerFunctions.CurrentScannedObject = rkCLSID.ToString();

                    // Check for valid AppID
                    string strAppID = regKey.GetValue("AppID") as string;
                    if (!string.IsNullOrEmpty(strAppID))
                    {
                        if (!appidExists(strAppID))
                        {
                            ScannerFunctions.StoreInvalidKey(Strings.MissingAppID, rkCLSID.ToString(), "AppID");
                        }
                    }

                    // See if DefaultIcon exists
                    using (RegistryKey regKeyDefaultIcon = rkCLSID.OpenSubKey("DefaultIcon"))
                    {
                        if (regKeyDefaultIcon != null)
                        {
                            string iconPath = regKeyDefaultIcon.GetValue("") as string;

                            if (!string.IsNullOrEmpty(iconPath))
                            {
                                if (!Utils.IconExists(iconPath))
                                {
                                    ScannerFunctions.StoreInvalidKey(Strings.InvalidFile, string.Format("{0}\\DefaultIcon", rkCLSID.ToString()));
                                }
                            }
                        }
                    }

                    // Look for InprocServer files
                    using (RegistryKey regKeyInprocSrvr = rkCLSID.OpenSubKey("InprocServer"))
                    {
                        if (regKeyInprocSrvr != null)
                        {
                            string strInprocServer = regKeyInprocSrvr.GetValue("") as string;

                            if (!string.IsNullOrEmpty(strInprocServer))
                            {
                                if (!Utils.FileExists(strInprocServer))
                                {
                                    ScannerFunctions.StoreInvalidKey(Strings.InvalidInprocServer, regKeyInprocSrvr.ToString());
                                }
                            }

                            regKeyInprocSrvr.Close();
                        }
                    }

                    using (RegistryKey regKeyInprocSrvr32 = rkCLSID.OpenSubKey("InprocServer32"))
                    {
                        if (regKeyInprocSrvr32 != null)
                        {
                            string strInprocServer32 = regKeyInprocSrvr32.GetValue("") as string;

                            if (!string.IsNullOrEmpty(strInprocServer32))
                            {
                                if (!Utils.FileExists(strInprocServer32))
                                {
                                    ScannerFunctions.StoreInvalidKey(Strings.InvalidInprocServer32, regKeyInprocSrvr32.ToString());
                                }
                            }

                            regKeyInprocSrvr32.Close();
                        }
                    }

                    rkCLSID.Close();
                }
            }
            catch (System.Security.SecurityException ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.Message);
            }
            catch (System.UnauthorizedAccessException ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.Message);
            }

            regKey.Close();
            return;
        }
Ejemplo n.º 17
0
        private static void ValidateFileExt(RegistryKey regKey)
        {
            bool bProgidExists = false, bAppExists = false;

            try
            {
                // Skip if UserChoice subkey exists
                if (regKey.OpenSubKey("UserChoice") != null)
                {
                    return;
                }

                // Parse and verify OpenWithProgId List
                using (RegistryKey rkProgids = regKey.OpenSubKey("OpenWithProgids"))
                {
                    if (rkProgids != null)
                    {
                        foreach (string strProgid in rkProgids.GetValueNames())
                        {
                            if (progIDExists(strProgid))
                            {
                                bProgidExists = true;
                            }
                        }
                    }
                }

                // Check if files in OpenWithList exist
                using (RegistryKey rkOpenList = regKey.OpenSubKey("OpenWithList"))
                {
                    if (rkOpenList != null)
                    {
                        foreach (string strValueName in rkOpenList.GetValueNames())
                        {
                            if (strValueName == "MRUList")
                            {
                                continue;
                            }

                            string strApp = rkOpenList.GetValue(strValueName) as string;

                            if (appExists(strApp))
                            {
                                bAppExists = true;
                            }
                        }
                    }
                }

                if (!bProgidExists && !bAppExists)
                {
                    ScannerFunctions.StoreInvalidKey(Strings.InvalidFileExt, regKey.ToString());
                }
            }
            catch (System.Security.SecurityException ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.Message);
            }
            catch (System.UnauthorizedAccessException ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.Message);
            }

            return;
        }
Ejemplo n.º 18
0
        /// <summary>
        /// Finds invalid windows explorer entries
        /// </summary>
        private static void ScanExplorer()
        {
            try
            {
                // Check Browser Help Objects
                using (RegistryKey regKey = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\explorer\\Browser Helper Objects"))
                {
                    if (regKey != null)
                    {
                        RegistryKey rkBHO = null;

                        foreach (string strGuid in regKey.GetSubKeyNames())
                        {
                            if ((rkBHO = regKey.OpenSubKey(strGuid)) != null)
                            {
                                // Update scan dialog
                                ScannerFunctions.CurrentScannedObject = rkBHO.ToString();

                                if (!clsidExists(strGuid))
                                {
                                    ScannerFunctions.StoreInvalidKey(Strings.MissingCLSID, rkBHO.ToString());
                                }
                            }
                        }
                    }
                }

                // Check IE Toolbars
                using (RegistryKey regKey = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Internet Explorer\\Toolbar"))
                {
                    if (regKey != null)
                    {
                        foreach (string strGuid in regKey.GetValueNames())
                        {
                            // Update scan dialog
                            ScannerFunctions.CurrentScannedObject = "CLSID: " + strGuid;

                            if (!IEToolbarIsValid(strGuid))
                            {
                                ScannerFunctions.StoreInvalidKey(Strings.InvalidToolbar, regKey.ToString(), strGuid);
                            }
                        }
                    }
                }

                // Check IE Extensions
                using (RegistryKey regKey = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Internet Explorer\\Extensions"))
                {
                    RegistryKey rkExt = null;


                    if (regKey != null)
                    {
                        foreach (string strGuid in regKey.GetSubKeyNames())
                        {
                            if ((rkExt = regKey.OpenSubKey(strGuid)) != null)
                            {
                                // Update scan dialog
                                ScannerFunctions.CurrentScannedObject = rkExt.ToString();

                                ValidateExplorerExt(rkExt);
                            }
                        }
                    }
                }

                // Check Explorer File Exts
                using (RegistryKey regKey = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts"))
                {
                    RegistryKey rkFileExt = null;


                    if (regKey != null)
                    {
                        foreach (string strFileExt in regKey.GetSubKeyNames())
                        {
                            if ((rkFileExt = regKey.OpenSubKey(strFileExt)) == null || strFileExt[0] != '.')
                            {
                                continue;
                            }

                            // Update scan dialog
                            ScannerFunctions.CurrentScannedObject = rkFileExt.ToString();

                            ValidateFileExt(rkFileExt);
                        }
                    }
                }
            }
            catch (System.Security.SecurityException ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.Message);
            }
            catch (System.UnauthorizedAccessException ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.Message);
            }

            return;
        }
Ejemplo n.º 19
0
        /// <summary>
        /// Verifies installed programs in add/remove list
        /// </summary>
        public static void Scan()
        {
            try
            {
                using (RegistryKey regKey = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall"))
                {
                    if (regKey == null)
                    {
                        return;
                    }

                    foreach (string strProgName in regKey.GetSubKeyNames())
                    {
                        using (RegistryKey regKey2 = regKey.OpenSubKey(strProgName))
                        {
                            if (regKey2 != null)
                            {
                                ScannerFunctions.CurrentScannedObject = regKey2.ToString();

                                Common_Tools.ProgramInfo progInfo = new Common_Tools.ProgramInfo(regKey2);

                                if (regKey2.ValueCount <= 0)
                                {
                                    ScannerFunctions.StoreInvalidKey(Strings.InvalidRegKey, regKey2.ToString());
                                    continue;
                                }

                                if (progInfo.WindowsInstaller)
                                {
                                    continue;
                                }

                                if (string.IsNullOrEmpty(progInfo.DisplayName) && (!progInfo.Uninstallable))
                                {
                                    ScannerFunctions.StoreInvalidKey(Strings.InvalidRegKey, regKey2.ToString());
                                    continue;
                                }

                                // Check display icon
                                if (!string.IsNullOrEmpty(progInfo.DisplayIcon))
                                {
                                    if (!Utils.IconExists(progInfo.DisplayIcon))
                                    {
                                        ScannerFunctions.StoreInvalidKey(Strings.InvalidFile, regKey2.ToString(), "DisplayIcon");
                                    }
                                }

                                // Check install location
                                if (!string.IsNullOrEmpty(progInfo.InstallLocation))
                                {
                                    if ((!Utils.DirExists(progInfo.InstallLocation)) && (!Utils.FileExists(progInfo.InstallLocation)))
                                    {
                                        ScannerFunctions.StoreInvalidKey(Strings.InvalidFile, regKey2.ToString(), "InstallLocation");
                                    }
                                }

                                // Check install source
                                if (!string.IsNullOrEmpty(progInfo.InstallSource))
                                {
                                    if ((!Utils.DirExists(progInfo.InstallSource)) && (!Utils.FileExists(progInfo.InstallSource)))
                                    {
                                        ScannerFunctions.StoreInvalidKey(Strings.InvalidFile, regKey2.ToString(), "InstallSource");
                                    }
                                }

                                // Check ARP Cache
                                if (progInfo.SlowCache)
                                {
                                    if (!string.IsNullOrEmpty(progInfo.FileName))
                                    {
                                        if (!Utils.FileExists(progInfo.FileName))
                                        {
                                            ScannerFunctions.StoreInvalidKey(Strings.InvalidRegKey, progInfo.SlowInfoCacheRegKey);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }

                checkARPCache(Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\App Management\ARPCache\"));
                checkARPCache(Registry.CurrentUser.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\App Management\ARPCache\"));
            }
            catch (System.Security.SecurityException ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.Message);
            }
        }