如何为通过 System.Diagnostics.Process.Start() 启动的控制台应用程序指定窗口标题?

发布于 2024-08-13 09:02:36 字数 223 浏览 6 评论 0原文

我正在使用 Process.Start() 方法从 .NET 代码启动控制台应用程序的新实例。我想知道是否可以指定托管生成进程的控制台窗口的标题。在 ProcessStartInfo 中找不到任何合适的内容。

作为最后的手段,我可​​以 P/Invoke 直接与 Win32 API 对话,但我宁愿不这样做。

有什么想法吗?

谢谢。

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.

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

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

发布评论

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

评论(3

天荒地未老 2024-08-20 09:02:36

我知道听起来您知道 P/Invoke 的做法,但对于其他人来说,这就是您的做法

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


SetWindowText(myProcess.MainWindowHandle, "my new title");

I know it sounds like you know the P/Invoke way of doing this, but for anyone else this is how you do it

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


SetWindowText(myProcess.MainWindowHandle, "my new title");
乖乖 2024-08-20 09:02:36

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

The easiest way I can think of is to create a batch file that sets the title (using the title command) and then executes the application. Then Start the .bat file instead.

你对谁都笑 2024-08-20 09:02:36

在 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

Inside the e.g. script of powershell I do use:

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

Got it from here, maybe useful:
http://blogs.msdn.com/b/rob/archive/2012/08/21/setting-the-title-of-the-command-prompt-window.aspx

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