【发布时间】:2010-08-09 12:47:09
【问题描述】:
在你说这是一个重复的问题之前,请让我解释一下(因为我已经阅读了所有类似的主题)。
我的应用程序具有以下两种设置:
procStartInfo.CreateNoWindow = true;
procStartInfo.WindowStyle = ProcessWindowStyle.Hidden;
并且还有 WindowsApplication 作为输出类型。
当我调用命令行命令时,黑色窗口仍然出现。我还能做些什么来隐藏窗口吗?并非所有命令都发生这种情况,XCOPY 是黑色窗口确实闪烁的情况。这只发生在我 XCOPY 的目的地也已经包含该文件并且它提示我是否要替换它时。即使我传入 /Y 它仍然会短暂闪烁。
如果有帮助,我愿意使用 vbscript,但还有其他想法吗?
客户端会调用我的可执行文件,然后传入一个命令行命令,即:
C:\MyProgram.exe start XCOPY c:\Test.txt c:\ProgramFiles\
这是应用程序的完整代码:
class Program
{
static void Main(string[] args)
{
string command = GetCommandLineArugments(args);
// /c tells cmd that we want it to execute the command that follows and then exit.
System.Diagnostics.ProcessStartInfo procStartInfo = new System.Diagnostics.ProcessStartInfo("cmd.exe", "/c " + command);
procStartInfo.RedirectStandardOutput = true;
procStartInfo.UseShellExecute = false;
// Do not create the black window.
procStartInfo.CreateNoWindow = true;
procStartInfo.WindowStyle = ProcessWindowStyle.Hidden;
System.Diagnostics.Process process = new System.Diagnostics.Process();
process.StartInfo = procStartInfo;
process.Start();
}
private static string GetCommandLineArugments(string[] args)
{
string retVal = string.Empty;
foreach (string arg in args)
retVal += " " + arg;
return retVal;
}
}
【问题讨论】:
-
你能把剩下的
Process/ProcessStartInfo代码贴出来吗? -
@fletcher:问题中指出输出类型是 Windows 应用程序而不是控制台。我已经使用设置为 Windows 应用程序的输出类型对其进行了测试,它工作正常。 @snow:我会仔细检查你的 OutputType 设置。
-
@fletcher 这实际上是个问题!我希望窗口根本不显示!
-
我开始认为这是 XCOPY 特有的错误...有人有这方面的经验吗?
-
啊,我的错。我错过了 WinForms 部分
标签: c# .net command-prompt xcopy