Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

Windows 10 Start Menu from Console

Aug
2,032
82
Demonstration of using Windows 10 Start Menus (System and User) from the Console

Code:
@SETLOCAL
@ECHO OFF
::    File: strtmnu.btm
:: _4ver:   32.10
:: _winver: 10.0
::
:: Viewer that I use for DebugString
:: https://learn.microsoft.com/en-us/sysinternals/downloads/debugview
::
:: To remove all lines containing the word DebugString,
::   type strtmnu.btm | find /v "DebugString" > newfile.btm
::   del strtmnu.btm
::   ren newfile.btm strtmnu.btm
pushd

iff %_x64 eq 1 then
    iff %_admin eq 1 then
        iff %_elevated eq 1 then
            :: NEXT SENTENCE
        else
          echo Note that this .BTM was tested on a 64-bit version of Windows,
          echo as Administrator,
          echo from an elevated process.
          echo.
          echo You are running the following;
          echo      _x64: %_x64
          echo    _admin: %_admin
          echo _elevated: %_elevated
          pause
        endiff
  endiff
endif

:: Make sure that character-mode popup windows are disabled.
::
iff %@option[ConsolePopupWindows] eq Yes then
  OPTION //ConsolePopupWindows=No
endiff

DebugString _batchline: %_batchline _batch: %_batch ConsolePopupWindows: %@option[ConsolePopupWindows]

:: Current batch file nesting level
iff %_batch eq 1 then
  Gosub ClearTmp9

  Gosub CreateMenu

  Gosub DisplayAcceptMenu

  switch %select_line
  case 1
    set theDir="%ProgramData%\Microsoft\Windows\Start Menu\Programs"
  case 2
    set theDir="%AppData%\Microsoft\Windows\Start Menu\Programs"
  endswitch

  DebugString _batchline: %_batchline theDir: %theDir
  DebugString _batchline: %_batchline _batch: %_batch

  cdd %theDir
endiff

:: Current batch file nesting level
iff %_batch gt 0 then
  DebugString _batchline: %_batchline Current Folder: %_cwd
  DebugString _batchline: %_batchline _batch: %_batch

  Gosub ClearTmp9
  ::
  :: Store dir /b results in temporary pseudo character device 9
  DebugString _batchline: %_batchline Current Folder: %_cwd
  ::
  :: dir /b displays an error if no files are found.
  :: So, I use dir to populate _dir_files first.
  dir > nul
  :: Now I can do a dir /b,
  ::   if files were found.
  if %_dir_files gt 0 dir /b > tmp9:

  iff %@lines[tmp9:] lt 0 then
    echo Nothing in folder %selected
    cancel
  endiff

  Gosub DisplayAcceptMenu
  :: If the filename extension is .lnk
  iff %@ext[%selected] eq lnk then
    :: Put quotes around filename,
    :: and launch filename
    ::
    "%selected"
    DebugString _batchline: %_batchline cancel
    cancel
  else
    DebugString _batchline: %_batchline cd %selected
    :: Change to the selected folder
    cd %selected
    DebugString _batchline: %_batchline Current Folder: %_cwd

    DebugString _batchline: %_batchline call %_batchname
    :: We are in a new folder.
    :: Start this .btm again
    call %_batchname
  endiff
endiff
popd
ENDLOCAL

:ClearTmp9
::
:: Clear temporary pseudo character device 9
tmp /c 9
Return

:CreateMenu
::
:: Store these selections in temporary pseudo character device 9
text > tmp9:
System Start Menu
User   Start Menu
endtext
Return

:DisplayAcceptMenu
:: Remove environment variable selected from the environment
unset selected
::
:: Display selections for user to select from
set selected=%@select[tmp9:,0,0,26,80,Press Enter To Select]
DebugString _batchline: %_batchline Select_Line: %select_line
DebugString _batchline: %_batchline selected: %selected

:: Environment variable selected does not exist.
:: Esc pressed.
iff not defined selected then
  DebugString _batchline: %_batchline Cancelling %_batchname
  cancel
endiff

Return
 
Last edited:
Hmmm! What about apps at the top level (alongside the "Programs" folder)? Except for the first of these (from the user start menu) I don't (can't) see these when I run the BTM using the system start menu.

1721314706533.webp


Except for the first one, those are in here.

1721315217077.webp
 
I have noticed that difference also.

For example, from TCC, when I change to the folder;
Code:
"%AppData%\Microsoft\Windows\Start Menu\Programs"
...and compare it to the files in Windows Explorer for that folder,
there are differences.

Why does Windows Explorer see the folder differently than TCC?

Also, from TCC, when I change to the folder;
Code:
"%ProgramData%\Microsoft\Windows\Start Menu\Programs"
...and compare it to the files in Windows Explorer for that folder,
there are differences.

Why does Windows Explorer see the folder differently than TCC?

Also, I start strtmnu.btm in a TCC stand-alone window, running as;
Code:
     _x64: 1
   _admin: 1
_elevated: 1

Joe
 
I have edited the .btm code in post #1 to include the following;
Code:
iff %_x64 eq 1 then
    iff %_admin eq 1 then
        iff %_elevated eq 1 then
            :: NEXT SENTENCE
        else
          echo Note that this .BTM was tested on a 64-bit version of Windows,
          echo as Administrator,
          echo from an elevated process.
          echo.
          echo You are running the following;
          echo      _x64: %_x64
          echo    _admin: %_admin
          echo _elevated: %_elevated
          pause
        endiff
  endiff
endiff

Joe
 
Hey @vefatica, I've added a third folder,
Code:
"%userprofile%\AppData\Local\Microsoft\WindowsApps"
...and revised the .btm

Joe

Code:
@SETLOCAL
@ECHO OFF
::    File: strtmnu.btm
:: Created: 2024-07-12
::
:: Revised: 2024-07-18
:: - Added third folder,
::   "%userprofile%\AppData\Local\Microsoft\WindowsApps"
::
:: _4ver:   32.10
:: _winver: 10.0
::
:: Viewer that I use for DebugString
:: https://learn.microsoft.com/en-us/sysinternals/downloads/debugview
::
:: To remove all lines containing the word DebugString,
::   type strtmnu.btm | find /v "DebugString" > newfile.btm
::   del strtmnu.btm
::   ren newfile.btm strtmnu.btm
pushd

iff %_x64 eq 1 then
    iff %_admin eq 1 then
        iff %_elevated eq 1 then
            :: NEXT SENTENCE
        else
          echo Note that this .BTM was tested on a 64-bit version of Windows,
          echo as Administrator,
          echo from an elevated process.
          echo.
          echo You are running the following;
          echo      _x64: %_x64
          echo    _admin: %_admin
          echo _elevated: %_elevated
          pause
        endiff
  endiff
endiff

:: Make sure that character-mode popup windows are disabled.
::
iff %@option[ConsolePopupWindows] eq Yes then
  OPTION //ConsolePopupWindows=No
endiff

DebugString _batchline: %_batchline _batch: %_batch ConsolePopupWindows: %@option[ConsolePopupWindows]

:: Current batch file nesting level
iff %_batch eq 1 then
  Gosub ClearTmp9

  Gosub CreateMenu

  Gosub DisplayAcceptMenu

  switch %select_line
  case 1
    set theDir="%ProgramData%\Microsoft\Windows\Start Menu\Programs"
  case 2
    set theDir="%AppData%\Microsoft\Windows\Start Menu\Programs"
  case 3
    set theDir="%userprofile%\AppData\Local\Microsoft\WindowsApps"
  endswitch

  DebugString _batchline: %_batchline theDir: %theDir
  DebugString _batchline: %_batchline _batch: %_batch

  cdd %theDir
endiff

:: Current batch file nesting level
iff %_batch gt 0 then
  DebugString _batchline: %_batchline Current Folder: %_cwd
  DebugString _batchline: %_batchline _batch: %_batch

  Gosub ClearTmp9
  ::
  :: Store dir /b results in temporary pseudo character device 9
  DebugString _batchline: %_batchline Current Folder: %_cwd
  ::
  :: dir /b displays an error if no files are found.
  :: So, I use dir to populate _dir_files first.
  dir > nul
  :: Now I can do a dir /b,
  ::   if files were found.
  if %_dir_files gt 0 dir /b > tmp9:

  iff %@lines[tmp9:] lt 0 then
    echo Nothing in folder %selected
    cancel
  endiff

  Gosub DisplayAcceptMenu
  :: If the filename extension is .lnk
  iff %@ext[%selected] eq lnk then
    :: Put quotes around filename,
    :: and launch filename
    ::
    :: 2024-07-18
    :: Added start /pgm
    DebugString _batchline: %_batchline Start /pgm "%selected"
    start /pgm "%selected"
    DebugString _batchline: %_batchline cancel
    cancel
  else
    DebugString _batchline: %_batchline cd %selected
    
    :: 2024-07-18
    :: After adding Windows Apps Menu,
    :: "%userprofile%\AppData\Local\Microsoft\WindowsApps"
    :: I now check to see if selected is a folder,
    ::  or if selected is a file
    iff isfile %selected then
      DebugString _batchline: %_batchline Start /pgm "%selected"
      :: Added start /pgm
      start /pgm "%selected"
      cancel
    else
      :: Change to the selected folder
      iff isdir %selected then
        cdd %selected
      else
        echo %selected is not a folder
        cancel
      endiff
    endiff
    DebugString _batchline: %_batchline Current Folder: %_cwd

    DebugString _batchline: %_batchline call %_batchname
    :: We are in a new folder.
    :: Start this .btm again
    call %_batchname
  endiff
endiff
popd
ENDLOCAL

:ClearTmp9
::
:: Clear temporary pseudo character device 9
tmp /c 9
Return

:CreateMenu
::
:: Store these selections in temporary pseudo character device 9
text > tmp9:
System Start Menu
User   Start Menu
Windows Apps Menu 
endtext
Return

:DisplayAcceptMenu
:: Remove environment variable selected from the environment
unset selected
::
:: Display selections for user to select from
set selected=%@select[tmp9:,0,0,26,80,Press Enter To Select]
DebugString _batchline: %_batchline Select_Line: %select_line
DebugString _batchline: %_batchline selected: %selected

:: Environment variable selected does not exist.
:: Esc pressed.
iff not defined selected then
  DebugString _batchline: %_batchline Cancelling %_batchname
  cancel
endiff

Return
 
Revised to use @Shfolder function,
instead of folders as constants.

Exception: %userprofile%\AppData\Local\Microsoft\WindowsApps
which cannot be accessed via @Shfolder function.

Joe

Code:
@SETLOCAL
@ECHO OFF
::    File: strtmnu.btm
:: Created: 2024-07-12
::
:: Revised: 2024-07-19
:: - Now using @Shfolder function for folder names.
::
:: _4ver:   32.10
:: _winver: 10.0
::
:: Viewer that I use for DebugString
:: https://learn.microsoft.com/en-us/sysinternals/downloads/debugview
::
:: To remove all lines containing the word DebugString,
::   type strtmnu.btm | find /v "DebugString" > newfile.btm
::   del strtmnu.btm
::   ren newfile.btm strtmnu.btm
pushd

iff %_x64 eq 1 then
    iff %_admin eq 1 then
        iff %_elevated eq 1 then
            :: NEXT SENTENCE
        else
          echo Note that this .BTM was tested on a 64-bit version of Windows,
          echo as Administrator,
          echo from an elevated process.
          echo.
          echo You are running the following;
          echo      _x64: %_x64
          echo    _admin: %_admin
          echo _elevated: %_elevated
          pause
        endiff
  endiff
endiff

:: Make sure that character-mode popup windows are disabled.
::
iff %@option[ConsolePopupWindows] eq Yes then
  OPTION //ConsolePopupWindows=No
endiff

DebugString _batchline: %_batchline _batch: %_batch ConsolePopupWindows: %@option[ConsolePopupWindows]

:: Current batch file nesting level
iff %_batch eq 1 then
  Gosub ClearTmp9

  Gosub CreateMenu

  Gosub DisplayAcceptMenu

  switch %select_line
  :: @shfolder[2]  C:\Users\%username%\AppData\Roaming\Microsoft\Windows\Start Menu\Programs
  ::
  :: @shfolder[11] <user name>\Start Menu
  ::
  :: @shfolder[22] C:\ProgramData\Microsoft\Windows\Start Menu
  :: cdd :CommonStartMenu
  ::
  :: @shfolder[23] C:\ProgramData\Microsoft\Windows\Start Menu\Programs
  case 1
    :: 2024-07-19
    set theDir=%@shfolder[2]
  case 2
    :: 2024-07-19
    set theDir=%@shfolder[11]
  case 3
    :: 2024-07-19
    set theDir=%@shfolder[22]
  case 4
    :: 2024-07-19
    set theDir="%userprofile%\AppData\Local\Microsoft\WindowsApps"
  endswitch

  DebugString _batchline: %_batchline theDir: %theDir
  DebugString _batchline: %_batchline _batch: %_batch

  cdd %theDir
endiff

:: Current batch file nesting level
iff %_batch gt 0 then
  DebugString _batchline: %_batchline Current Folder: %_cwd
  DebugString _batchline: %_batchline _batch: %_batch

  Gosub ClearTmp9
  ::
  :: Store dir /b results in temporary pseudo character device 9
  DebugString _batchline: %_batchline Current Folder: %_cwd
  ::
  :: dir /b displays an error if no files are found.
  :: So, I use dir to populate _dir_files first.
  dir > nul
  :: Now I can do a dir /b,
  ::   if files were found.
  if %_dir_files gt 0 dir /b > tmp9:
  
  :: 2024-07-19
  :: Even though there may be zero files,
  ::  there may be folders
  iff %@lines[tmp9:] gt 0 then
    :: NEXT SENTENCE
  else
    :: If there are folders,
    ::  send listing to tmp9:
    if %_dir_dirs gt 0 dir /b > tmp9:
  endiff

  iff %@lines[tmp9:] lt 0 then
    echo Nothing in folder %selected
    cancel
  endiff

  Gosub DisplayAcceptMenu
  :: If the filename extension is .lnk
  iff %@ext[%selected] eq lnk then
    :: Put quotes around filename,
    :: and launch filename
    ::
    :: 2024-07-18
    :: Added start /pgm
    DebugString _batchline: %_batchline Start /pgm "%selected"
    start /pgm "%selected"
    DebugString _batchline: %_batchline cancel
    cancel
  else
    DebugString _batchline: %_batchline cd %selected
    
    :: 2024-07-18
    :: After adding Windows Apps Menu,
    :: "%userprofile%\AppData\Local\Microsoft\WindowsApps"
    :: I now check to see if selected is a folder,
    ::  or if selected is a file
    iff isfile %selected then
      DebugString _batchline: %_batchline Start /pgm "%selected"
      :: Added start /pgm
      start /pgm "%selected"
      cancel
    else
      :: Change to the selected folder
      iff isdir %selected then
        cdd %selected
      else
        echo %selected is not a folder
        cancel
      endiff
    endiff
    DebugString _batchline: %_batchline Current Folder: %_cwd

    DebugString _batchline: %_batchline call %_batchname
    :: We are in a new folder.
    :: Start this .btm again
    call %_batchname
  endiff
endiff
popd
ENDLOCAL

:ClearTmp9
::
:: Clear temporary pseudo character device 9
tmp /c 9
Return

:CreateMenu
::
:: Store these selections in temporary pseudo character device 9
text > tmp9:
 2 Start Menu\Programs
11 user name\Start Menu
22 All Users\Start Menu
   Windows Apps
endtext
Return

:DisplayAcceptMenu
:: Remove environment variable selected from the environment
unset selected
::
:: Display selections for user to select from
set selected=%@select[tmp9:,0,0,26,80,Press Enter To Select]
DebugString _batchline: %_batchline Select_Line: %select_line
DebugString _batchline: %_batchline selected: %selected

:: Environment variable selected does not exist.
:: Esc pressed.
iff not defined selected then
  DebugString _batchline: %_batchline Cancelling %_batchname
  cancel
endiff

Return
 
Do you have any idea what the file-like things in that WindowsApps directory actually are? They have "Properties" dialogs containing nothing interesting. You can't use @INODE[] on them.

I have WinDbgX.exe (0 bytes) in there. If I execute it by name, I get

Code:
07/19  12:46:13.579    2572        6.016     181.2  DbgX.Shell.exe
07/19  12:46:17.080    8580        0.031      10.1  EngHost.exe

and a debugging UI that I have never seen before.

Do the things in WindowsApps actually show up anywhere in the start menu?
 
I found a discussion of that directory here. It's not particularly satisfying.
 
Hey @vefatica,
I use the Sysinternals Suite, which I installed with Winget.

The WindowsApps folder is where the Sysinternals programs are launched.

For example, from the Start Menu,
1721409244468.webp

Note well the App settings.

When I click App settings, I am taken to...
1721409334405.webp

...the settings page for the Sysinternals Suite.

From my strtmnu.btm,
1721409436274.webp

...from which I can launch DebugView.exe

Same thing for other Microsoft Apps,
for example,
ClipChamp.
1721410082696.webp

1721410138755.webp


Joe
 
Do you have any idea what the file-like things in that WindowsApps directory actually are? They have "Properties" dialogs containing nothing interesting. You can't use @INODE[] on them.

I believe they are AppX aliases:

Code:
C:\>for %f in ( "%localappdata\microsoft\windowsapps\*.exe" ) echo %@filename[%f] - %@rptarget[%f]
clipchamp.exe - C:\Program Files\WindowsApps\Clipchamp.Clipchamp_3.1.10920.0_neutral__yxz26nhyzhsrt\Clipchamp.CLI\Clipchamp.CLI.exe
GameBarElevatedFT_Alias.exe - C:\Program Files\WindowsApps\Microsoft.XboxGamingOverlay_7.124.5142.0_x64__8wekyb3d8bbwe\GameBarElevatedFT.exe
GetHelp.exe - C:\Program Files\WindowsApps\Microsoft.GetHelp_10.2403.20861.0_x64__8wekyb3d8bbwe\GetHelp.exe
ICD.exe - C:\Program Files\WindowsApps\Microsoft.WindowsConfigurationDesigner_2024.613.0.0_x86__8wekyb3d8bbwe\ICD\ICD.exe
MediaPlayer.exe - C:\WINDOWS\system32\SystemUWPLauncher.exe
MicrosoftWindows.DesktopStickerEditorCentennial.exe - C:\WINDOWS\SystemApps\MicrosoftWindows.Client.CBS_cw5n1h2txyewy\DesktopStickerEditorWin32Exe\Des
ktopStickerEditorWin32Exe.exe
mspaint.exe - C:\Program Files\WindowsApps\Microsoft.Paint_11.2404.1020.0_x64__8wekyb3d8bbwe\PaintApp\mspaint.exe
msteams.exe - C:\Program Files\WindowsApps\MicrosoftTeams_24165.1306.2986.9504_x64__8wekyb3d8bbwe\msteams.exe
msteamsupdate.exe - C:\Program Files\WindowsApps\MicrosoftTeams_24165.1306.2986.9504_x64__8wekyb3d8bbwe\msteamsupdate.exe
msteams_autostarter.exe - C:\Program Files\WindowsApps\MicrosoftTeams_24165.1306.2986.9504_x64__8wekyb3d8bbwe\msteams_autostarter.exe
notepad.exe - C:\Program Files\WindowsApps\Microsoft.WindowsNotepad_11.2405.13.0_x64__8wekyb3d8bbwe\Notepad\Notepad.exe
pbrush.exe - C:\Program Files\WindowsApps\Microsoft.Paint_11.2404.1020.0_x64__8wekyb3d8bbwe\PaintApp\mspaint.exe
python.exe - C:\Program Files\WindowsApps\Microsoft.DesktopAppInstaller_1.23.1911.0_x64__8wekyb3d8bbwe\AppInstallerPythonRedirector.exe
python3.exe - C:\Program Files\WindowsApps\Microsoft.DesktopAppInstaller_1.23.1911.0_x64__8wekyb3d8bbwe\AppInstallerPythonRedirector.exe
Skype.exe - C:\Program Files\WindowsApps\Microsoft.SkypeApp_15.123.3203.0_x64__kzf8qxf38zg5c\Skype\Skype.exe
SnippingTool.exe - C:\Program Files\WindowsApps\Microsoft.ScreenSketch_11.2405.32.0_x64__8wekyb3d8bbwe\SnippingTool\SnippingTool.exe
WindowsPackageManagerServer.exe - C:\Program Files\WindowsApps\Microsoft.DesktopAppInstaller_1.23.1911.0_x64__8wekyb3d8bbwe\WindowsPackageManagerServe
r.exe
winget.exe - C:\Program Files\WindowsApps\Microsoft.DesktopAppInstaller_1.23.1911.0_x64__8wekyb3d8bbwe\winget.exe
wt.exe - C:\Program Files\WindowsApps\Microsoft.WindowsTerminal_1.20.11781.0_x64__8wekyb3d8bbwe\wt.exe
XboxPcAppAdminServer.exe - C:\Program Files\WindowsApps\Microsoft.GamingApp_2407.1001.1.0_x64__8wekyb3d8bbwe\XboxPcAppAdminServer.exe

C:\>
 
Back
Top
[FOX] Ultimate Translator
Translate