0

When a Windows batch file is launched via a shortcut (from the Start Menu, for example), its window will typically receive the title of the shortcut.

Is it possible for the batch file to determine the name of its own window?

This question is related to Can a Windows batch file determine its own file name?, but that question asks if the batch file can determine its own filename. I am asking if a batch file can determine its own window name.

  • I think this has been answered here already: [How to get the window title text from batch file](https://superuser.com/questions/1155853/how-to-get-the-window-title-text-from-batch-file) – QcFe Dec 09 '20 at 12:05
  • @QcFe Ah, thank you. I searched all over StackOverflow for an answer, and used a search engine, but I didn't think of manually checking Superuser. I just read that QA, and I'm going to see if any of the answers work well for my situation. If it's a dupe, but on a different SE site, how do we handle that? – RockPaperLz- Mask it or Casket Dec 09 '20 at 12:14

1 Answers1

0

StackOverflow user QcFe lent a kind hand by finding this QA on Superuser: https://superuser.com/questions/1155853/how-to-get-the-window-title-text-from-batch-file

The short answer is that Windows provides no simple and direct way for batch files to accomplish this task.

Windows provides the internal title command to set the window title, but no way to retrieve it. (Which is disappointing, because it would be such a simple addition to the title command.)

The functionality can be attained using PowerShell or possibly tasklist, but for the latter, there are issues that need to be addressed if there are more than one command shell window open.

I elected to force the window to have a unique name using the Title command. That way I could reference it correctly for tools that need to know the window title, such as NirSoft's excellent nircmd utility.