简体   繁体   English

C#启动应用程序 - 流程而不会窃取焦点

[英]C# Start Application-Process without stealing focus

I´m started learning C# and now I´m wondering if there is a way to start a third-party-application without stealing focus or just always display the windows of this application/process in the background. 我开始学习C#,现在我想知道是否有办法在没有窃取焦点的情况下启动第三方应用程序,或者只是总是在后台显示此应用程序/进程的窗口。

To be more specific: I have written an application that can start a Steam-Client with parameters like login-data. 更具体一点:我编写了一个可以使用login-data等参数启动Steam-Client的应用程序。 As far as I know the Steam-Client is written in Java and maybe thats one of my problems. 据我所知,Steam-Client是用Java编写的,也许这就是我的一个问题。 I also know that you can start the Steam-Client in "Silent-Mode" like this: 我也知道你可以在“静音模式”下启动Steam-Client,如下所示:

"C:\Programs\Steam\Steam.exe" -silent -login user password

But this won´t help if I don´t want the Steam-Client to steal the focus. 但如果我不希望Steam-Client窃取焦点,这将无济于事。 There are two windows that appear in the foreground: Login-Window and Loading-Window . 前景中有两个窗口: Login-WindowLoading-Window

I searched on stackoverflow and with google for a solution, but none worked for me. 我在stackoverflow上搜索并使用谷歌搜索解决方案,但没有一个对我有效。 One possible solution would be, but doesn´t work for me: 一种可能的解决方案是,但对我不起作用:

Process startsteam = new Process();
startsteam.StartInfo.FileName = cursteampath;
startsteam.StartInfo.Arguments = "-silent -login " + user + " " + password;
startsteam.StartInfo.CreateNoWindow = true;
startsteam.StartInfo.ErrorDialog = false;
startsteam.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
startsteam.Start();

Like I wrote before, this wouldn´t hide the Login-Window (Form) and the Loading-Window . 就像我之前写的那样,这不会隐藏Login-Window (Form)和Loading-Window I also noticed that Steam is starting subprocesses like steamwebhelper.exe . 我还注意到Steam正在启动像steamwebhelper.exe这样的子steamwebhelper.exe

My question is: Is there any way in C# to start a process of a third-party-application and prevent it and its sub-processes from stealing focus or just force all windows to display in the background? 我的问题是:在C#中是否有任何方法可以启动第三方应用程序的进程并阻止它及其子进程窃取焦点或仅强制所有窗口在后台显示?

Edit: This solution also doesn´t work for me stackoverflow user32.dll 编辑:此解决方案也不适用于stackoverflow user32.dll

I think, what you are looking at here, is the result of an arms race. 我想,你在这里看到的是军备竞赛的结果。 The windows developers added a way for applications to be launched in the background: Pass a don't show / hidden flag to the process launch structure. Windows开发人员添加了一种在后台启动应用程序的方法:将一个不显示/隐藏标志传递给流程启动结构。

Developers then decided that they would like to ignore that flag, and show in the foreground anyway. 开发人员然后决定他们想忽略那个标志,并且无论如何都要显示在前台。 Those developers are bad people. 那些开发人员是坏人。

Rather than escalating the arms race and introducing a "don't show the window I really mean it flag" for applications to try and work around, Microsoft sensibly just stopped right there. 对于试图和解决的应用程序而言,微软明智地停在那里,而不是升级军备竞赛并引入“不显示窗口我真的意味着它标志”。

As such, if an application is written by bad people, there is really nothing you can simply do to force it. 因此,如果一个应用程序是由坏人编写的,那么你真的没有什么可以简单地强迫它。 Short of injecting hook dll's and other such invasive techniques to try and force them to honor the bloody contract. 没有注入钩子dll和其他这样的侵入性技术,试图强迫他们兑现血腥的合同。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM