Search code examples
.netprocessstartinfo

How can one specify the window title for a console application started with System.Diagnostics.Process.Start()?


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.


Solution

  • 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");