diff --git a/Netch/NativeMethods.cs b/Netch/NativeMethods.cs index c1c521ba..cf5e888d 100644 --- a/Netch/NativeMethods.cs +++ b/Netch/NativeMethods.cs @@ -66,5 +66,11 @@ namespace Netch [DllImport("dnsapi", EntryPoint = "DnsFlushResolverCache")] public static extern uint FlushDNSResolverCache(); + + [DllImport("kernel32.dll")] + public static extern bool AllocConsole(); + + [DllImport("kernel32.dll")] + public static extern bool AttachConsole(int dwProcessId); } } \ No newline at end of file diff --git a/Netch/Netch.cs b/Netch/Netch.cs index 221508a8..3cefe6f5 100644 --- a/Netch/Netch.cs +++ b/Netch/Netch.cs @@ -1,5 +1,6 @@ using System; using System.IO; +using System.Linq; using System.Threading; using System.Threading.Tasks; using System.Windows.Forms; @@ -17,6 +18,12 @@ namespace Netch [STAThread] public static void Main(string[] args) { + if (args.Contains("-console")) + { + NativeMethods.AllocConsole(); + NativeMethods.AttachConsole(-1); + } + // 创建互斥体防止多次运行 using (var mutex = new Mutex(false, "Global\\Netch")) {