0

I have this batch file script.
It runs multiple instances of the same program with slightly different settings.
The program isn't notepad btw and the parameters aren't those, it's just here to make it clearer.

timeout /t 0
start cmd /k "title My Title 1 & cd C:\Windows && C: & notepad -noforcemparms & echo note1"
timeout /t 5
start cmd /k "title My Title 2 & cd C:\Windows && C: & notepad -noforcemaccel & echo note2"
timeout /t 5
start cmd /k "title My Title 3 & cd C:\Windows && C: & notepad -noforcemspd -noforcemaccel & echo note3"

The issue is that the title of the window becomes "My Title 1 - notepad -noforcemparms".
What I expected was the window to only be "My Title 1".

The reason I need this in batch:
I have this in powershell, and it changes the title properly, but due to some policies I'm unable to run the ps script on the machine I need it to run on. So I had to convert those to batch.

Is it even possible to change the title like that in batch?

4
  • 1
    start "My Title 1" /k "cd C:\Windows && C: & notepad -noforcemparms & echo note1"
    – DavidPostill
    Commented May 23, 2021 at 17:09
  • See Start - Start a program - Windows CMD - SS64.com
    – DavidPostill
    Commented May 23, 2021 at 17:09
  • @DavidPostill it's still the same, the "-notepad" part is still added in the title while it's running
    – user1368528
    Commented May 23, 2021 at 17:33
  • 1
    I don't think it's possible in cmd
    – DavidPostill
    Commented May 23, 2021 at 19:10

2 Answers 2

0

This worked for me:

start "My Title 3" cmd /k cd /d C:\Windows & notepad -noforcemparms & echo note3

The notepad command here doesn't make sense, but I suppose it's only for illustration.

0

      It's a simple question...

           Is it even possible to change the title like that in batch?

           - The answer is no



Changing title of an application when launching from command prompt
Note: linked to question 39021975 on StackOverflow

You need to make a program to do this.

You need to call the Windows' API. This is how to make a title bar changing program.

Create a file using notepad and call it SetText.bas. Store it on your desktop.

Paste this into it. ‍

Imports System
Imports System.Runtime.InteropServices
Imports Microsoft.Win32
‍    
Public Module MyApplication  
‍
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Declare Function SetWindowText Lib "user32" Alias "SetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String) As Long
‍   
Sub Main()
  On Error Resume Next
  Dim CmdLine As String
  Dim Ret as Long
  Dim A() as String
  Dim hwindows as long
  ‍ 
  CmdLine = Command()
  If Left(CmdLine, 2) = "/?" Then
     MsgBox("Usage:" & vbCrLf & vbCrLf & "ChangeTitleBar Oldname NewName")
  Else
     A = Split(CmdLine, Chr(34), -1, vbBinaryCompare)
     hwindows = FindWindow(vbNullString, A(1))
     Ret = SetWindowText(hwindows, A(3))    
  End If
   ̹
End Sub
End Module

Then type in a command prompt window.

"C:\Windows\Microsoft.NET\Framework\v4.0.30319\vbc.exe" /target:winexe /out:"%userprofile%\desktop\SetText.exe" "%userprofile%\desktop\settext.bas" /verbose

A program has been created on your desktop called settext.exe. To use

"%userprofile%\desktop\settext" "Untitled - Notepad" "A Renamed Notepad"

You must log in to answer this question.