Advertisement
Gravitas

Get All ProgID on System for COM Automation

Feb 13th, 2013
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.90 KB | None | 0 0
  1. // Get All ProgID on System for COM Automation
  2. // See http://procbits.com/2010/11/08/get-all-progid-on-system-for-com-automation
  3. var regClis = Registry.ClassesRoot.OpenSubKey("CLSID");
  4. var progs = new List<string>();
  5.  
  6. foreach (var clsid in regClis.GetSubKeyNames()) {
  7.     var regClsidKey = regClis.OpenSubKey(clsid);
  8.     var ProgID = regClsidKey.OpenSubKey("ProgID");
  9.     var regPath = regClsidKey.OpenSubKey("InprocServer32");
  10.  
  11.     if (regPath == null)
  12.         regPath = regClsidKey.OpenSubKey("LocalServer32");
  13.  
  14.     if (regPath != null && ProgID != null) {
  15.         var pid = ProgID.GetValue("");
  16.         var filePath = regPath.GetValue("");
  17.         progs.Add(pid + " -> " + filePath);
  18.         regPath.Close();
  19.     }
  20.  
  21.     regClsidKey.Close();
  22. }
  23.  
  24. regClis.Close();
  25.  
  26. progs.Sort();
  27.  
  28. var sw = new StreamWriter(@"c:\ProgIDs.txt");
  29. foreach (var line in progs)
  30.     sw.WriteLine(line);
  31.  
  32. sw.Close();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement