Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Get the title of a batch window

2,729 views
Skip to first unread message

Arno

unread,
Feb 15, 2011, 3:05:39 AM2/15/11
to
Hi all,

I know, that I can set the title of my window with the title command,
but is there a way in a batch, to find out my aktual window title?

regards
Arno

foxidrive

unread,
Feb 15, 2011, 3:20:07 AM2/15/11
to

Why do you need to? You can set it and then you know what it is.

If you explain why the title is unknown then maybe someone can offer a
suggestion.


--
Regards,
Mic

I'm_HERE

unread,
Feb 15, 2011, 3:30:24 AM2/15/11
to
----------8<--------------
@echo off & Set title=my title
title %title%
tasklist /fi "imagename eq cmd.exe" ^
/fi "Windowtitle eq %title%"^
/fo list /v
pause
-----------8<-------------

Arno

unread,
Feb 15, 2011, 3:38:29 AM2/15/11
to
Hi Mic,

to control batch Windows, I want to store their PID in some file.
To get the PID I modify the title to an unique one and filter it
through the tasklist command.
To repair the title I want to set it back after I have made it unique,
therfore I want to read it, before I set it. Mostly it will be
'cmd.exe'
but I prefer to do it in a more generic way.

Perhaps you have an other easy way, getting my own PID without
external or third party tools, than I can leave the title untouched,
but at least I also want to know if this is possible.

regards
Arno

Arno

unread,
Feb 15, 2011, 3:54:44 AM2/15/11
to

but this doesn't help, if someone has started the batch over the start
command with his own title, or does it?

regards
Arno

I'm_HERE

unread,
Feb 15, 2011, 4:23:22 AM2/15/11
to

c:$$> type f1.bat
@title mytitle1
@echo test1
pause

c:$$> type f2.bat
@title mytitle2
@echo test1
pause

c:$$> start "" f1.bat
c:$$> start "" f2.bat

c:$$> tasklist /fi "imagename eq cmd.exe" /fo list /v

Nom de l'image: cmd.exe
PID : 164
Nom de la session: Console
Numéro de session: 0
Utilisation mémoire: 92 Ko
État : En service
Nom d'utilisateur : WALID2MI\Administrateur
Temps processeur: 0:00:00
Titre de la fenêtre : Administrateur

Nom de l'image: cmd.exe
PID : 1856
Nom de la session: Console
Numéro de session: 0
Utilisation mémoire: 1 448 Ko
État : En service
Nom d'utilisateur : WALID2MI\walid
Temps processeur: 0:00:00
Titre de la fenêtre : mytitle1 <--

Nom de l'image: cmd.exe
PID : 596
Nom de la session: Console
Numéro de session: 0
Utilisation mémoire: 1 448 Ko
État : En service
Nom d'utilisateur : WALID2MI\walid
Temps processeur: 0:00:00
Titre de la fenêtre : mytitle2 <---

foxidrive

unread,
Feb 15, 2011, 4:30:56 AM2/15/11
to
On 15/02/2011 19:38, Arno wrote:

> to control batch Windows, I want to store their PID in some file.
> To get the PID I modify the title to an unique one and filter it
> through the tasklist command.

That's the only way to get the PID with tasklist if there are several
CMD windows open at the time.

> To repair the title I want to set it back after I have made it unique,
> therfore I want to read it, before I set it. Mostly it will be
> 'cmd.exe'
> but I prefer to do it in a more generic way.
>
> Perhaps you have an other easy way, getting my own PID without
> external or third party tools, than I can leave the title untouched,
> but at least I also want to know if this is possible.


handle.exe from PStools will show the CMD.EXE and the PID and also the
current folder

You can change to a specific (temp?) folder, test for it and get the pid
from that instance of cmd.exe


c:\WINDOWS\Util\Pstools>handle -p cmd.exe

Handle v3.42
Copyright (C) 1997-2008 Mark Russinovich
Sysinternals - www.sysinternals.com

------------------------------------------------------------------------------
cmd.exe pid: 4932 MM\MM
C: File (RW-) C:\WINDOWS\Util\Pstools
6C: File (RW-)
C:\WINDOWS\WinSxS\x86_Microsoft.Windows.Common-Controls_659
5b64144ccf1df_6.0.2600.6028_x-ww_61e65202
------------------------------------------------------------------------------
cmd.exe pid: 2640 MM\MM
C: File (RW-) C:\Documents and Settings
6C: File (RW-)
C:\WINDOWS\WinSxS\x86_Microsoft.Windows.Common-Controls_659
5b64144ccf1df_6.0.2600.6028_x-ww_61e65202


--
Regards,
Mic

foxidrive

unread,
Feb 15, 2011, 4:39:01 AM2/15/11
to

Arno doesn't know what the title is, and doesn't want to change it
unnecessarily, but wants the PID of the current batch file.


--
Regards,
Mic

Arno

unread,
Feb 15, 2011, 5:19:59 AM2/15/11
to
Hi Mic,

thanks for your hints. Now I know what I will do.
First I capture a list with all processes, where the
image name is 'cmd.exe' (I hope this is language
independend),
second I calculate my PID, like I have done it before
and last I pick the title from the initial list with my
calculated PID and reset it.

many thanks for the discussion,
best regards
Arno

0 new messages