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?


Who is Participating?
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.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.