• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2143
  • Last Modified:

Console Application.... How do I minimize it?

Hi eveyone...

I have a console application which runs as a Scheduled Task on an XP workstation which runs every hour.

Unfortunately when the program executes it interupts the user from what he is doing.  Is there a way that I can tell the console application to minimze that window that it is in?


1 Solution
Hi FarkMortier,

you could start with this post

as the author said it does work to hide the window while the process is running and is displayed when done
but you can always choose to hide the window and let the program run without restoring the window when done the program simply ends

tested with this, it flashes on the start but then its gone

using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
namespace ConsoleApplication1

    class Program

        #region Console Window property stuff
        [DllImport("kernel32.dll", ExactSpelling=true)]
        private static extern IntPtr GetConsoleWindow();

        private static IntPtr ThisConsole=GetConsoleWindow();
        [DllImport("user32.dll",CharSet=CharSet.Auto, SetLastError=true)]
        private static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
        private const int HIDE=0;
        private const int MAXIMIZE=3;
        private const int MINIMIZE=6;
        private const int RESTORE=9;

        static void Main(string[] args)
            ShowWindow(ThisConsole, HIDE); //Hides Console Window
            Console.WriteLine("\r\nExecuting at: " + System.DateTime.Now.ToString());

            // do other processing here
            //Console.WriteLine("\r\nExecution completed.\r\n");
            //ShowWindow(ThisConsole, RESTORE); //Restores Console Window

share what you know, learn what you don't
If you use the windows task-scheduler, try the following: Instead of referencing
to the executable, create a link to the it an let the scheduler call this link. By
opening the properties-page of that link you can choose "Execute: Minimized"
in the property window.

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now