3

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.

To be more specific: I have written an application that can start a Steam-Client with parameters like login-data. As far as I know the Steam-Client is written in Java and maybe thats one of my problems. I also know that you can start the Steam-Client in "Silent-Mode" like this:

"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. There are two windows that appear in the foreground: Login-Window and Loading-Window.

I searched on stackoverflow and with google for a solution, but none worked for me. 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. I also noticed that Steam is starting subprocesses like 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?

Edit: This solution also doesn´t work for me stackoverflow user32.dll

Community
  • 1
  • 1
Pandora
  • 361
  • 3
  • 14

1 Answers1

-1

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.

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.

Chris Becke
  • 750
  • 4
  • 10
  • This doesn´t answers my question, but I agree with you. I searched for hours now to get a solution. I ended up creating a Virtual Desktop (Win 10) and tried to start the Client only on that desktop. However, the program starts where your mouse(?) have its focus and this way I can´t force to show the Client, started by my C#-App, to stay on the Virtual Desktop. Theres also a Wrapper for C# [VD-Wrapper](https://github.com/Grabacr07/VirtualDesktop) but it can´t move windows of other processes. I´m lost. :( – Pandora Oct 29 '15 at 18:45