# Command windows opening behind other windows



## ste2425 (Aug 5, 2013)

Hi all,

Hopefully a quick one here.

Ive made a small application to poll TeamCity build monitor take data about current and past builds and store them in a data base. Its only a very small application and im using windows task scheduler to run it every five minuets. Its working grand and does everything its meant to however when it runs it open a command window. Im not displaying anything nor taking user input and its finished and closed in under half a minuet but it opens on top of any windows I already have open. Control is still focused on the window I was working in before the command window opened. What id like to know is there a way within either task scheduler or something I can programme within the application to either stop the command window opening up but the application still run as its not needed or to make it automatically open behind all other open windows?

Thanks all


----------



## newtekie1 (Aug 5, 2013)

How is your program being called?  Does the program run inside the command prompt?

If so you can create the scheduled task pointing to cmd.exe and use the following arguments

 /c start /min [yourprogram] ^& exit


----------



## FordGT90Concept (Aug 5, 2013)

If it is a .NET program, you need to create a ProcessStartInfo instance and set CreateNoWindow to false, WindowStyle to hidden, and set UseShellExecute to false.  Pass it to Process.Start(startinfo).

If using something other than .NET, use cmd.exe.

If you want to just set focus, use SetFocus in user32.dll.  Examples here:
http://www.pinvoke.net/default.aspx/user32.setfocus

You can also hide a window of another application using user32.dll's showwindow command (set it to false):
http://www.pinvoke.net/default.aspx/user32.showwindow


----------



## ste2425 (Aug 5, 2013)

Thanks all the cmd.exe method worked a treat


----------

