Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

In Windows, how can I view a list of all the titles of all Windows that are open.

(Preferably with some unique identifier like handle)

share|improve this question
There's a Windows API function to do that called EnumWindows() that has the core functionality required. I know of no existing program to do that, but you could probably write one in your favorite scripting language -- I personally prefer Python, which could certainly do something like this. VisualBasic probably could, too, as well as a number of others. – martineau Nov 17 '13 at 11:10

I took the PowerShell script from Enumerating all Windows-windows with a PowerShell function and a callback function and modified it slightly.

It print the window name and handle.

 Enumerieren der vorhandenen Fenster

$TypeDef = @"

using System;
using System.Text;
using System.Collections.Generic;
using System.Runtime.InteropServices;

namespace Api

 public class WinStruct
   public string WinTitle {get; set; }
   public int WinHwnd { get; set; }

 public class ApiDef
   private delegate bool CallBackPtr(int hwnd, int lParam);
   private static CallBackPtr callBackPtr = Callback;
   private static List<WinStruct> _WinStructList = new List<WinStruct>();

   [return: MarshalAs(UnmanagedType.Bool)]
   private static extern bool EnumWindows(CallBackPtr lpEnumFunc, IntPtr lParam);

   [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
   static extern int GetWindowText(IntPtr hWnd, StringBuilder lpString, int nMaxCount);

   private static bool Callback(int hWnd, int lparam)
       StringBuilder sb = new StringBuilder(256);
       int res = GetWindowText((IntPtr)hWnd, sb, 256);
      _WinStructList.Add(new WinStruct { WinHwnd = hWnd, WinTitle = sb.ToString() });
       return true;

   public static List<WinStruct> GetWindows()
      _WinStructList = new List<WinStruct>();
      EnumWindows(callBackPtr, IntPtr.Zero);
      return _WinStructList;


Add-Type -TypeDefinition $TypeDef -Language CSharpVersion3

[Api.Apidef]::GetWindows() | Where-Object { $_.WinTitle -ne "" } | Sort-Object -Property WinTitle | Select-Object WinTitle,@{Name="Handle"; Expression={"{0:X0}" -f $_.WinHwnd}}
share|improve this answer
Have you read the section about copyright on the site's imprint? It forbids copying, modifying and distributing all contents. You should at least consider giving fair attribution to the author. – ComFreek Nov 29 '13 at 16:25
@ComFreek: More fair than linking to the authors site? – Oliver Salzburg Nov 29 '13 at 17:04

Use the EnumWindows() Windows API function. It will invoke the application-defined callback function argument passed to it for all the top-level windows on the screen, passing it the handle of each one, until the callback returns FALSE.

Here's a simple Python 2.x console program I wrote that uses that function (and a few others to determine which windows might actually be visible on the desktop -- many of the "top-level" windows thatEnumWindows()enumerates over are invisible -- to accomplish what you want. It makes use of the win32guimodule included in the PyWin32 extension package to gain access to the Windows API. This can also be done at a lower, more direct, level using the built-inctypesmodule, but PyWin32 is a more advanced and convenient way to go about it, IMO.

You could redirect the output to a text file or the program could be modified to display the list in a window or dialog box using several different GUI modules available, including the tk/tcl interface module calledTkinter, which comes standard with the language.

import sys
import win32gui

def callback(hwnd, strings):
    if win32gui.IsWindowVisible(hwnd):
        window_title = win32gui.GetWindowText(hwnd)
        left, top, right, bottom = win32gui.GetWindowRect(hwnd)
        if window_title and right-left and bottom-top:
            strings.append('0x{:08x}: "{}"'.format(hwnd, window_title))
    return True

def main():
    win_list = []  # list of strings containing win handles and window titles
    win32gui.EnumWindows(callback, win_list)  # populate list

    for window in win_list:  # print results
        print window


if __name__ == '__main__':
share|improve this answer
a worthwhile thing for me to look into but your answer might be better as a comment, as that kind of answer is more for stackoverflow. So my question is looking more at programs already written that would. Sometimes people post bits of vbscript . I know a little vbscript but it doesn't have much in the way of ways to view things. To the point that while it has a msgbox function.. or some little box that displays info, it doesn't scroll.. and so the best way is to make the program run notepad and open the file.. I suppose that's doable – barlop Nov 17 '13 at 10:54
Sorry. Suggest you edit your question to be clearer about what you want. – martineau Nov 17 '13 at 11:01
thanks, I know a little python(more than powershell!) I will give this a go – barlop Nov 29 '13 at 15:41

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.