JSI Tip 9168. ALTTAB.BAT is home grown replacement for the ALT+TAB function?

Jerold Schulman

March 17, 2005

3 Min Read
ITPro Today logo in a gray background | ITPro Today


Using CMDOW.EXE and SHELLESC.EXE, I have scripted ALTTAB.BAT to perform the ALT+TAB function.

The syntax for using ALTTAB.BAT is:

1. Create a shortcut on your desktop by right-clicking a blank area and pressing New / Shortcut.

2. Set the 'location of the item' to C:FolderInPathcmdow.exe /RUN C:FolderInParhALTTAB.BAT where C:FolderInPath is the name of a folder in your PATH were you keep your utility programs.

3. Type ALT+TAB into the 'name for this shortcut' and press Finish.

4. Right-click the new shortcut and set the 'Shortcut key'. I set mine to CTRL + ALT + A.

5. Press the Change Icon button and browse  %SystemRoot%system32SHELL32.dll, %SystemRoot%system32moricons.dll, or you favorite icon source, and select an icon.

When it is time to ALT+TAB:

1. Press the 'Shortcut key' you set in step 4 above.A Window will open and display your running applications, like:

01 cmd             C:WINDOWSsystem32cmd.exe02 iexplore        SunTrust Online Banking - Jerry03 POWERPNT        Microsoft PowerPoint - [Presentation1]04 WINWORD         Document1 - Microsoft Word05 MSACCESS        JSI Order Entry06 MSACCESS        JSI_ORDERS : Database (Access 2002 file format)07 OUTLOOK         Calendar - Microsoft Outlook08 FRONTPG         Microsoft FrontPage09 MSACCESS        Orders by Customer10 notepad         tip_index.txt - Notepad11 FRONTPG         Microsoft FrontPage12 webcompiler     Windows NT Tips, Tricks and Registry Hacks. JSI, Inc is your Windows NT Resource13 notepad         NewTips.txt - Notepad14 explorer        C:ZIPNEW15 iexplore        Windows XP Pro/Server/2000/NT Support - Jerry16 agent           WinNT Public - [IN_EMAIL]17 agent           WinNT Public - [microsoft.beta.srv2003sp1.general]18 agent           MVP - [microsoft.private.mvp.windows_server]19 iexplore        JSI, INC. - Tips & Tricks - Windows Server 2003 / Windows XP / Windows 2000 / Windows Server 20 - Jerry20 iexplore        Advanced Search Options - Jerry21 notepad         Untitled - Notepad22 EXCEL           Microsoft Excel - Book123 explorer        C:UTIL[Enter the application number, or 0 to exit]

2. Type the application number, or 0 to exit.

When I typed a 7 and pressed the Enter key, my Outlook Calendar received focus, and the ALTTAB.BAT window closed.

NOTE: If the ALTTAB.BAT window is not large enough:

1. Right-click the title bar and press Properties.

2. Select the Layout tab.

3. Increase the Window Size Width and Height.

4. If the Screen Buffer Size Width and/or Height is less than the Window Size values, increase them.

5. Press OK.

6. Check the Save properties for future windows with the same title.

7. Press OK.

NOTE: See How can I enlarge the ALT+TAB dialog to fit all the applications I have open?

NOTE: See the taskswitch.exe PowerToy for XP, which not only displays the icons of the application window, but lets you see a preview of the page which helps when you have multiple sessions of an application open.

NOTE: See How can I use Task Manager to emulate the ALT+TAB function?

ALTTAB.bat contains:

@echo offsetlocal ENABLEDELAYEDEXPANSIONset /a cnt=0for /f "tokens=1,8*" %%i in ('cmdow /T /B /F^|SHELLESC') do ( set handle=%%i set /a cnt=!cnt! + 1 set wrk=!cnt! if !cnt! LSS 10 set wrk=0!cnt! set table=!table!!wrk!!handle! for /f "Tokens=1*" %%a in ('@echo %%j %%k') do (  set app1=%%a                    #  set app2=!app1:~0,16!  set app3=%%b  @echo !wrk! !app2! !app3! ))@echo.:enterset /p ANS=[Enter the application number, or 0 to exit] if {%ANS%}
{} goto :enterif {%ANS%}
{0} endlocal&goto :EOFset /a number=100%ANS%%%100set wrk=%number%if %number% LSS 10 set wrk=0%number%set /a number=%number% - 1set /a number=%number% * 10call set entry=%%table:~%number%^,10%%if "%entry:~0,2%" NEQ "%wrk%" @echo Invalid number.&goto enterset handle=%entry:~2,8%cmdow %handle% /ACT /VIS /RESendlocal



Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.

You May Also Like