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

Posted on 2006-05-27
Last Modified: 2007-12-19
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?


Question by:FarkMortier
    LVL 44

    Accepted 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
    LVL 5

    Expert Comment

    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.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Normally a window is moved by clicking on the caption bar and dragging. You may want your user to be able to move borderless forms or move a form by clicking anywhere in the form without the limitation to the caption bar. There are many ways to do i…
    Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

    758 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    9 Experts available now in Live!

    Get 1:1 Help Now