隐藏进程窗口,为什么它不起作用? [英] Hiding the process window, why isn't it working?

查看:93
本文介绍了隐藏进程窗口,为什么它不起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我现在尝试了几种方法来隐藏新进程的窗口(在这种情况下,它只是用于测试的notepad.exe),但是无论我尝试什么,它都将无法正常工作.

I have tried several things now to hide the window of a new process (in this case it's just notepad.exe for testing), but it just won't work regardless of what I try.

我现在已经读了很多帖子,都说同样的话,为什么它对我不起作用?

I have read many posts now all saying the same so why isn't it working for me?

我有一个控制台应用程序,应该在不显示其窗口的情况下启动其他进程.

I have a console app that is supposed to launch other processes without showing their windows.

我试图使我的控制台应用程序在没有窗口的情况下启动notepad.exe,但这只是行不通.

I have tried to make my console app launch notepad.exe without a window, but it just won't work.

ProcessStartInfo info = new ProcessStartInfo("path to notepad.exe");

info.RedirectStandardOutput = true;
info.RedirectStandardError = true;                                
info.CreateNoWindow = true;
info.UseShellExecute = false;                                

Process proc = Process.Start(info);

我还尝试过为info.WindowStyle使用各种设置,并且尝试将控制台应用程序配置为Windows应用程序,但是我做什么都没关系,子进程始终会打开一个窗口.

I have also tried using various setting for info.WindowStyle and I have tried to configure my console app to be a Windows application, but it doesn't really matter what I do, the child process always opens a window.

这是不是从控制台应用程序允许的,或者这是什么问题-也许有人可以阐明这一点吗?

Is this not allowed from a console app or what is the problem here - can anyone shed some light on this maybe?

我正在Windows 7 x64上使用.NET 4.0

I'm using .NET 4.0 on Windows 7 x64

推荐答案

以我的经验,每当我启动"cmd.exe"时,以下方法都会起作用.

In my experience, the following works whenever I fire up "cmd.exe".

info.CreateNoWindow = true;
info.UseShellExecute = false;                                

它似乎不适用于"notepad.exe".它也无法与其他应用程序一起使用,例如"excel.exe"和"winword.exe".

It doesn't seem to work with "notepad.exe". It fails with other apps too, like "excel.exe" and "winword.exe".

这可行,但是:

ProcessStartInfo info = new ProcessStartInfo("notepad.exe");

info.WindowStyle = ProcessWindowStyle.Hidden;

Process proc = Process.Start(info);

来自 MSDN :

一个窗口可以是可见的也可以是隐藏的.系统通过不绘制隐藏窗口来显示它.如果窗口是隐藏的,则将其有效地禁用.隐藏的窗口可以处理来自系统或其他窗口的消息,但是不能处理来自用户的输入或显示输出.通常,应用程序在自定义窗口外观时可能会隐藏一个新窗口,然后使窗口样式为 Normal .若要使用ProcessWindowStyle.Hidden,请

A window can be either visible or hidden. The system displays a hidden window by not drawing it. If a window is hidden, it is effectively disabled. A hidden window can process messages from the system or from other windows, but it cannot process input from the user or display output. Frequently, an application may keep a new window hidden while it customizes the window's appearance, and then make the window style Normal. To use ProcessWindowStyle.Hidden, the ProcessStartInfo.UseShellExecute property must be false.

当我测试它时,我不必设置 UseShellExecute = false .

When I tested it, I didn't have to set UseShellExecute = false.

这篇关于隐藏进程窗口,为什么它不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆