Reputation: 127
I am new to c# and I'm rewriting my old batch file script into it but I've come across this problem:
Basically I want to hide sqlcmd window so I've tried this
Process bkp = new Process();
bkp.StartInfo.CreateNoWindow = true;
bkp.StartInfo.UseShellExecute = false;
bkp.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
bkp = Process.Start("C:\\Program Files (x86)\\Microsoft SQL Server\\90\\Tools\\Binn\\SQLCMD.EXE", "-S This-PC\\MyApp -U user -P pass -Q \"query\"");
But this doesn't work and the black window is still present. Is there a way to really hide it?
Thanks
Upvotes: 3
Views: 553
Reputation: 20296
You prepared the bkp
object but it's not used at all. It gets overwritten at the moment when Process.Start
method is called.
It should look like this:
Process bkp = new Process();
bkp.StartInfo.CreateNoWindow = true;
bkp.StartInfo.UseShellExecute = false;
bkp.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
bkp.StartInfo.FileName = "C:\\Program Files (x86)\\Microsoft SQL Server\\90\\Tools\\Binn\\SQLCMD.EXE";
bkp.StartInfo.Arguments = "-S This-PC\\MyApp -U user -P pass -Q \"query\"";
bkp.Start();
Upvotes: 3