using System; using System.Text; using System.Runtime.InteropServices; namespace ConsoleApplication2 { class Program { // 导入 读取窗口标题所需的DLL [DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)] internal static extern int GetConsoleTitle(StringBuilder sb, int capacity); static void Main(string[] args) { try { string cmdline = Environment.CommandLine; // Read the full window title string windowTitle = GetWindowTitle(); // Display the window title Console.WriteLine(windowTitle); } catch (Exception e) { } } public static string GetWindowTitle() { const int nChars = 256; IntPtr handle = IntPtr.Zero; StringBuilder Buff = new StringBuilder(nChars); if (GetConsoleTitle(Buff, nChars) > 0) { return Buff.ToString(); } return string.Empty; } } }
日期:2020-04-11 22:50:23 来源:oir作者:oir