6

I am starting a new instance of a console application from my .NET code using the Process.Start() method. I was wondering if I can specify the title of the console window hosting the spawned process. Could not find anything suitable in ProcessStartInfo.

As a last resort I can P/Invoke to talk to Win32 API directly, but I'd rather not.

Any ideas?

Thanks.

4

3 回答 3

3

在 powershell 的 eg 脚本中,我确实使用了:

# Set the Window Title as a reference
[System.Console]::Title = "Main title of the window"

从这里得到它,也许有用:http: //blogs.msdn.com/b/rob/archive/2012/08/21/setting-the-title-of-the-command-prompt-window.aspx

于 2015-10-12T16:26:49.713 回答
2

我能想到的最简单的方法是创建一个设置标题的批处理文件(使用 title 命令),然后执行应用程序。然后改为启动 .bat 文件。

于 2009-12-10T11:31:38.230 回答
2

我知道听起来你知道 P/Invoke 这样做的方式,但对于其他人来说,这就是你的方式

[DllImport("User32.dll")]
public static extern bool SetWindowText(IntPtr hwnd, string title);


SetWindowText(myProcess.MainWindowHandle, "my new title");
于 2011-07-22T09:59:20.997 回答