简体   繁体   中英

Programmatically determine which iFilters are installed

I have a problem whereby the Adobe PDF iFilter doesn't work consistently for us. As such, we like to use the one from Foxit . The problem is, if we install the Foxit iFilter and then later the client decides to reinstall Adobe Reader it may overwrite the Foxit iFilter.

We can use tools such as IFilter Explorer to view this but I'd like a way to do this in the application and warn the user/client that the iFilter has changed.

Is there a way to check iFilters from code (C#)? Or other potential solutions to this problem?

Since the foxit IFilter implements IPersistStream interface, I think you can try get this interface from the IFilter, and query for its CLSID to see if it is the one from foxit. Foxit IFilter has a CLSID of {987f8d1a-26e6-4554-b007-6b20e2680632} , which is the "Persistent Handlers Addins Registered" column in IFilter Explorer.

Adobe's IFilter doesn't seem to be implementing this interface.

I would expect that IFilters are stored in the registry, therefore you could use Process Monitor to see what keys IFilter Explorer is checking.

Then check on MSDN that this is consistent with the documentation.

Then do the same thing using .NET's registry types in your application.

Based on hunting for this answer, the registration can exist at both System and User level, so you are likely going to need to enumerate multiple registry keys.

一个奇怪的答案;)但作为替代方式可以使用Windows 7 SDK中的外部控制台应用程序Filtreg.exe将此作业委托给它。

I'm using this small function to give out a list. It just uses the extension NOT the document type! In the most cases this is ok and could be easily changed here.

/// <summary>
/// Implements a Function to get all available IFilters currently registered in this system
/// </summary>    
public string GetFilterList()
{
    //Our resulting string. We give back a ';' seperated list of extensions.
    string result = @"";
    string persistentHandlerClass;

    RegistryKey rk = Registry.LocalMachine.OpenSubKey(@"Software\Classes");
    if (rk == null)
        return null;

    using (rk)
    {
        foreach(string subKeyName in rk.GetSubKeyNames())
        {
            if (subKeyName[0] == '.') //possible Extension
            {
                RegistryKey sk = Registry.LocalMachine.OpenSubKey(@"Software\Classes\" + subKeyName + @"\PersistentHandler");
                if (sk == null)
                    continue;

                using (sk)
                {
                    persistentHandlerClass = (string)sk.GetValue(null);
                }

                if (persistentHandlerClass != null)
                {
                    string filterPersistClass = ReadStrFromHKLM(@"Software\Classes\CLSID\" + persistentHandlerClass +
                        @"\PersistentAddinsRegistered\{89BCB740-6119-101A-BCB7-00DD010655AF}");
                    string dllName = ReadStrFromHKLM(@"Software\Classes\CLSID\" + filterPersistClass + @"\InprocServer32");

                    // skip query.dll results, cause it's not an IFilter itself
                    if (dllName != null && filterPersistClass != null && (dllName.IndexOf("query.dll") < 0))
                    {
                        //result = result + subKeyName + @"[" + dllName + @"] - persistentHandlerClassAddin: " + persistentHandlerClass + "\r\n";  //[C:\Windows\system32\query.dll]
                        //result = result + subKeyName + @"[" + dllName + @"];";  //[C:\Windows\system32\query.dll]
                        result = result + subKeyName.ToLower() + @";";
                    }
                }

            }
        }

        return result;
    }

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM