.Net Console Application that Doesn't Bring up a Console

前端 未结 6 898
闹比i
闹比i 2020-12-11 00:10

I have a console application I\'m using to run scheduled jobs through windows scheduler. All the communication to/from the application is in email, event logging, database l

相关标签:
6条回答
  • 2020-12-11 00:49

    Why don't you make the application a Windows Service?

    0 讨论(0)
  • 2020-12-11 00:52

    Simply configure the Scheduled Task as "Run whether user is logged on or not".

    0 讨论(0)
  • 2020-12-11 00:55

    Schedule the task to run as a different user than your account and you won't get a window popping up . . .

    0 讨论(0)
  • 2020-12-11 01:02

    It's a hack, but the following blog post describes how you can hide the console window:

    http://expsharing.blogspot.com/2008/03/hideshow-console-window-in-net-black.html

    0 讨论(0)
  • 2020-12-11 01:05

    Sure. Build it as a winforms app and never show your form.

    Just be careful, because then it's not really a console app anymore, and there are some environments where you won't be able to use it.

    0 讨论(0)
  • 2020-12-11 01:09

    Borrowed from MSDN (link text):

    using System.Runtime.InteropServices;
    
    ...
          [DllImport("user32.dll")]
          public static extern IntPtr FindWindow(string lpClassName,string lpWindowName);
    
          [DllImport("user32.dll")]
          static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
    
    ...
    
             //Sometimes System.Windows.Forms.Application.ExecutablePath works for the caption depending on the system you are running under.
             IntPtr hWnd = FindWindow(null, "Your console windows caption"); //put your console window caption here
             if(hWnd != IntPtr.Zero)
             {
                //Hide the window
                ShowWindow(hWnd, 0); // 0 = SW_HIDE
             }
    
    
             if(hWnd != IntPtr.Zero)
             {
                //Show window again
                ShowWindow(hWnd, 1); //1 = SW_SHOWNORMA
             }
    
    0 讨论(0)
提交回复
热议问题