You can't change the window title using Process.MainWindowTitle
because the property is readonly.
In order to change the window title you will firstly need to obtain a handle to target window and then instruct the Operating System to change the title of the window associated with that handle using the Win32 API function SetWindowsText
like this
<DllImport("user32.dll")> _
Shared Function SetWindowText(ByVal hwnd As IntPtr, ByVal windowName As String) As Boolean
End Function
Once you have defined the function above you can proceed to manipulate the window title using the following code:
Dim process As New Process()
process.StartInfo.FileName = "notepad.exe"
process.Start()
Thread.Sleep(100)
SetWindowText(process.MainWindowHandle, "Fancy Notepad")
You need to wait a short few milliseconds before changing the window title otherwise the window title will not change.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…