title: Find all instances of sql server programmatically
body: <p>I know that there's quite a few subjects similar to this one, but none of them provided the correct answer I am looking for.  </p>
  
  <p>I am struggling to gather all the instances of SQL-Server on our network. It should be able to detect what version of SQl-Server is running. The different versions we have running vary between '<code>SQL Server 2000</code>' and '<code>SQL Server 2008 R2</code>'</p>
  
  <p>To give you a little background information, currently I am developing on our local network, but later on it will be run on our servers to gather information.</p>
  
  <p>Some of the information gathered is:</p>
  
  <ul>
  <li>application pools</li>
  <li>iis installations</li>
  <li>all databases on a server</li>
  <li>and some more stuff like this</li>
  </ul>
  
  <p>This all above is working without a problem through WMI queries. But I can not get the correct instances of SQl-Server by WMI or namespaces within Visual Studio 2010.</p>
  
  <p>Some of the things I've tried according to other solutions found around stackoverflow and other sites: </p>
  
  <ol>
  <li>WMI, using varying namespaces such as <code>root\\Microsoft\\SqlServer\\ComputerManagement10</code> with the <code>ServerSettings</code> class. But this only gives SQLSERVER and SQLEXPRESS without a version number. Making it kind of useless. </li>
  <li>I also tried <code>root\\CIMV2 Win32_Product</code> including a where like sql clause. But this returns much more data than just what I am looking for. In addition the query itself is very slow.</li>
  <li>Later on I found some Classes within Visual Studio such as <code>SqlDataSourceEnumerator</code> for example. Though this only works if a certain service is running and some ports are open. Which we preferably not do due to possible security issues and possible incorrect data</li>
  <li>I also saw some people referring to some other namespaces (will write them here once I find them again), but msdn stated that these namespaces we're going to be removed in the near future. <br></li>
  </ol>
  
  <p>To summarize: I need to retrieve all installed instances of <code>SQL-Server</code> on a domain with versions varying between 2000 and 2008 R2. <br></p>