I am trying to get all of the server names from the installed instances of SQL Server locally. I know that there is a command of "sqlcmd -L" that returns this list in cmd. The following is the code that I am using to run a the cmd.
Process sqlServers = new Process();
ProcessStartInfo psi = new ProcessStartInfo();
psi.RedirectStandardOutput = true;
psi.CreateNoWindow = false; (DEBUGGING PURPOSES)
psi.FileName = "cmd";
psi.Arguments = @"sqlcmd -L";
psi.UseShellExecute = false;
sqlServers = Process.Start(psi);
string serverList = sqlServers.StandardOutput.ReadToEnd();
sqlServers.WaitForExit(30000);
I have used this code base in another section of the program, and it works fine. Although I am not reading back a value.
Can someone please help me find why when I run this code that a cmd window opens, but no arguments are run and nothing is returned.