C# - Find SQL server instance port number

Post date: Aug 27, 2013 1:41:33 PM

using System;namespace LookForPortNumberOfSqlServer { class Program { static void Main(string[] args) { string instanceName = "SQL2012"; string regSearch = @"HKEY_LOCAL_MACHINE\Software\Microsoft\Microsoft SQL Server\" + instanceName + @"\MSSQLServer\SuperSocketNetLib\Tcp\"; Object found = Microsoft.Win32.Registry.GetValue(regSearch, "tcpPort", "not found"); Console.WriteLine(regSearch); Console.WriteLine(found); } }}