我注意到,如果 CreateNoWindow = false 在 Filename 指向 Windows 可执行文件时绝对不执行任何操作,如果您可以访问 winform 应用程序的源代码,那么您可以提供一个命令行参数来控制默认可见性窗体,并在 Winform App 启动代码中执行以下操作:
static void Main(string[] args)
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Form1 form1 = new Form1();
form1.Load += new EventHandler((s,o) =>
{
//check if the form should be shown based on command line arg
if (args.Contains("dontShowWindow"))
{
//hide it
form1.ShowInTaskbar = false;
form1.Visible = form1.ShowInTaskbar = false;
}
}
);
Application.Run(form1);
}
在您调用代码中,您现在可以将“dontShowWindow”指定为进程参数:
ProcessStartInfo info = new ProcessStartInfo
{
CreateNoWindow = false,
WindowStyle = ProcessWindowStyle.Hidden,
UseShellExecute = false,
FileName = @"C:\temp\testWinForm.exe",
Arguments = "dontShowWindow"
};
Process.Start(info);
希望这可以帮助