Skip navigation

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


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:\FolderInPath\cmdow.exe /RUN C:\FolderInParh\ALTTAB.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%\system32\SHELL32.dll, %SystemRoot%\system32\moricons.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:\WINDOWS\system32\cmd.exe
02 iexplore        SunTrust Online Banking - Jerry
03 POWERPNT        Microsoft PowerPoint - \[Presentation1\]
04 WINWORD         Document1 - Microsoft Word
05 MSACCESS        JSI Order Entry
06 MSACCESS        JSI_ORDERS : Database (Access 2002 file format)
07 OUTLOOK         Calendar - Microsoft Outlook
08 FRONTPG         Microsoft FrontPage
09 MSACCESS        Orders by Customer
10 notepad         tip_index.txt - Notepad
11 FRONTPG         Microsoft FrontPage
12 webcompiler     Windows NT Tips, Tricks and Registry Hacks. JSI, Inc is your Windows NT Resource
13 notepad         NewTips.txt - Notepad
14 explorer        C:\ZIPNEW
15 iexplore        Windows XP Pro/Server/2000/NT Support - Jerry
16 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 - Jerry
20 iexplore        Advanced Search Options - Jerry
21 notepad         Untitled - Notepad
22 EXCEL           Microsoft Excel - Book1
23 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 off
setlocal ENABLEDELAYEDEXPANSION
set /a cnt=0
for /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.
:enter
set /p ANS=\[Enter the application number, or 0 to exit\] 
if \{%ANS%\}

\{\} goto :enter if \{%ANS%\}

\{0\} endlocal&goto :EOF set /a number=100%ANS%%%100 set wrk=%number% if %number% LSS 10 set wrk=0%number% set /a number=%number% - 1 set /a number=%number% * 10 call set entry=%%table:~%number%^,10%% if "%entry:~0,2%" NEQ "%wrk%" @echo Invalid number.&goto enter set handle=%entry:~2,8% cmdow %handle% /ACT /VIS /RES endlocal



Hide comments

Comments

  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Publish