不启动控制台的.Net 控制台应用程序

发布于 2024-07-23 07:50:20 字数 102 浏览 3 评论 0 原文

我有一个控制台应用程序,用于通过 Windows 调度程序运行计划的作业。 与应用程序之间的所有通信均通过电子邮件、事件日志记录和数据库日志进行。 有什么办法可以抑制控制台窗口的出现吗?

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 logs. Is there any way I can suppress the console window from coming up?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

挖个坑埋了你 2024-07-30 07:50:20

当然。 将其构建为 winforms 应用程序,并且从不显示您的表单。

请小心,因为那样它就不再是真正的控制台应用程序,并且在某些环境中您将无法使用它。

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.

空气里的味道 2024-07-30 07:50:20

借自 MSDN(链接文本):

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
         }

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
         }
宣告ˉ结束 2024-07-30 07:50:20

这是一个黑客,但以下博客文章描述了如何隐藏控制台窗口:

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

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

卖梦商人 2024-07-30 07:50:20

安排任务以与您的帐户不同的用户身份运行,这样您就不会弹出窗口。 。 。

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

江南烟雨〆相思醉 2024-07-30 07:50:20

只需将计划任务配置为“无论用户是否登录都运行”。

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

度的依靠╰つ 2024-07-30 07:50:20

为什么不将应用程序设为 Windows 服务?

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文