展示从C#窗口停止进程 [英] Stop a process from showing a window from C#
问题描述
我想自动执行上没有用户交互启动创建GUI窗口的应用程序,但我无法弄清楚如何隐藏实际的窗口。
我试着使用的ProcessStartInfo这样的:
的Process.Start(新的ProcessStartInfo {
UseShellExecute =假,
CreateNoWindow = TRUE,
WindowStyle = ProcessWindowStyle.Hidden,
//其他属性在这里
});
但窗口仍显示。
我也试过自旋等待存在的窗口,然后隐藏它:
而(process.MainWindowHandle = = IntPtr.Zero){}
ShowWindowAsync(process.MainWindowHandle,SW_HIDE);
这很不幸,使得一秒钟左右的约1/16号窗口一闪,我倒要避免它,如果在所有可能的。
我现在的想法是一起创建的勾,但我不确定是什么钩抢,也不如果它甚至会工作。
$ b $任何提示?
所需的工艺窗口样式(实际上映射到单一的b
的 SW _
常量)被传递到其它应用程序的的WinMain
的功能,但并不意味着粗鲁的应用程序韩元T不理你发送的任何值。
您可以通过创建另一个虚拟桌面 User32.CreateDesktop
,然后用 Kernel32.CreateProcess
,确保传递正确的桌面名称为的StartInfo
结构的一部分。
I'm trying to automate an application that creates a GUI window on startup that has no user interaction, but I can't figure out how to hide the actual window.
I've tried using ProcessStartInfo thus:
Process.Start(new ProcessStartInfo {
UseShellExecute = false,
CreateNoWindow = true,
WindowStyle = ProcessWindowStyle.Hidden,
// other properties here
});
But the window still shows up.
I've also tried spin-waiting for the window to exist, and then hiding it:
while (process.MainWindowHandle == IntPtr.Zero) {}
ShowWindowAsync(process.MainWindowHandle, SW_HIDE);
This, unfortunately, makes the window flash for about 1/16th of a second or so, and I'd like to avoid it if at all possible.
My current thoughts are along the line of creating a hook, but am unsure of what hooks to grab, nor if it will even work.
Any tips?
The desired process window style (actually mapped to one of the SW_
constants) is passed to the other application's WinMain
function, but that doesn't mean a rude application won't just ignore whatever value you send.
You can pull it off by creating another virtual desktop using User32.CreateDesktop
, then use Kernel32.CreateProcess
, making sure to pass the correct desktop name as part of the STARTINFO
structure.
这篇关于展示从C#窗口停止进程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!