Get All ProgID on System for COM Automation

If you want to use Silverlight COM Automation, you need to know the ProgID of your COM component. These are buried in the registry. Here is a snippet that I found (don't remember where) and modified a bit to do this:

var regClis = Registry.ClassesRoot.OpenSubKey("CLSID");
var progs = new List<string>();

foreach (var clsid in regClis.GetSubKeyNames()) {
    var regClsidKey = regClis.OpenSubKey(clsid);
    var ProgID = regClsidKey.OpenSubKey("ProgID");
    var regPath = regClsidKey.OpenSubKey("InprocServer32");

    if (regPath == null)
        regPath = regClsidKey.OpenSubKey("LocalServer32");

    if (regPath != null && ProgID != null) {
        var pid = ProgID.GetValue("");
        var filePath = regPath.GetValue("");
        progs.Add(pid + " -> " + filePath);
        regPath.Close();
    }

    regClsidKey.Close();
}

regClis.Close();

progs.Sort();

var sw = new StreamWriter(@"c:\ProgIDs.txt");
foreach (var line in progs)
    sw.WriteLine(line);

sw.Close();

If you made it this far, you should follow me on Twitter.

-JP

Want to test-drive Bitcoin without any risk? Check out my bitcoin wallet Coinbolt. It includes test coins for free.

comments powered by Disqus