- 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: