在你说它是一个重复的问题之前,请让我解释一下(因为我已经阅读了所有类似的主题)。
我的应用程序具有以下两种设置:
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;
}
}