1. Welcome to TechPowerUp Forums, Guest! Please check out our forum guidelines for info related to our community.

Command windows opening behind other windows

Discussion in 'Programming & Webmastering' started by ste2425, Aug 5, 2013.

  1. ste2425

    ste2425

    Joined:
    May 27, 2008
    Messages:
    3,414 (1.49/day)
    Thanks Received:
    376
    Location:
    Huddersfield, uk
    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
  2. newtekie1

    newtekie1 Semi-Retired Folder

    Joined:
    Nov 22, 2005
    Messages:
    19,828 (6.19/day)
    Thanks Received:
    5,939
    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
    ste2425 says thanks.
    Crunching for Team TPU More than 25k PPD
  3. FordGT90Concept

    FordGT90Concept "I go fast!1!11!1!"

    Joined:
    Oct 13, 2008
    Messages:
    13,445 (6.27/day)
    Thanks Received:
    3,415
    Location:
    IA, USA
    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
    Last edited: Aug 5, 2013
    ste2425 says thanks.
    Crunching for Team TPU
  4. ste2425

    ste2425

    Joined:
    May 27, 2008
    Messages:
    3,414 (1.49/day)
    Thanks Received:
    376
    Location:
    Huddersfield, uk
    Thanks all the cmd.exe method worked a treat

Currently Active Users Viewing This Thread: 1 (0 members and 1 guest)

Share This Page