我是C#的新手,正在将旧的批处理文件脚本重写到其中,但是遇到了这个问题:

基本上我想隐藏sqlcmd窗口,所以我尝试了

        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\"");


但这不起作用,并且仍然存在黑色窗口。有没有办法真正隐藏它?

谢谢

最佳答案

您准备了bkp对象,但根本没有使用它。调用Process.Start方法时,它会被覆盖。

它看起来应该像这样:

  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();

关于c# - 在C#应用程序中隐藏sqlcmd,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/26317405/

10-10 23:28