RealBUZZARD

Untitled

Jan 28th, 2022 (edited)
1,001
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ::------------------------------------------------------------------------------
  2. :: NAME
  3. ::     PinFav.bat
  4. ::
  5. :: DESCRIPTION
  6. ::     Pin your favorite window.
  7. ::
  8. :: KNOWN BUGS
  9. ::      Programs minimized in the notification area are ignored.
  10. ::
  11. :: AUTHOR
  12. ::     IB_U_Z_Z_A_R_Dl
  13. ::
  14. :: CREDITS
  15. ::     @Rosalyn - Original project idea, testing and ideas.
  16. ::     @Sintrode - Some code optimisation.
  17. ::
  18. ::     A project created in the "server.bat" Discord: https://discord.gg/GSVrHag
  19. ::------------------------------------------------------------------------------
  20. @echo off
  21. title PinFav  ^|  Pin your favorite window.
  22. setlocal DisableDelayedExpansion
  23. set "@CMDWIZ=cmdwiz.exe showwindow ? /n:"!executable!""
  24. setlocal EnableDelayedExpansion
  25.  
  26. if not exist "cmdwiz.exe" (
  27.     echo ERROR: PinFav can't start because "cmdwiz.exe" is missing.
  28.     echo Please reinstall PinFav and try again.
  29.     echo:
  30.     pause
  31.     exit /b 0
  32. )
  33.  
  34. set index=0
  35.  
  36. :MAIN_MENU
  37. cls
  38. set /a write_header=1, cn_memory=0, cn_loop=0
  39. if defined write_newline (
  40.     set write_newline=
  41. )
  42. >nul 2>&1 set memory_executable_ && (
  43.     for /l %%A in (1,1,!index!) do (
  44.         if defined memory_executable_[%%A] (
  45.             call :TASKLIST memory_executable_[%%A] && (
  46.                 set /a cn_memory+=1
  47.             ) || (
  48.                 set memory_executable_[%%A]=
  49.             )
  50.         )
  51.     )
  52. )
  53. >nul 2>&1 set memory_executable_ && (
  54.     for /l %%A in (1,1,!index!) do (
  55.         if defined memory_executable_[%%A] (
  56.             set /a cn_loop+=1
  57.             if !cn_loop! lss !cn_memory! (
  58.                 set "@delimiter=, "
  59.             ) else (
  60.                 set @delimiter=
  61.             )
  62.             if defined write_header (
  63.                 set write_header=
  64.                 echo:
  65.                 <nul set /p="Programs pinned: "
  66.             )
  67.             <nul set /p=""!memory_executable_[%%A]!"!@delimiter!"
  68.             if not defined write_newline (
  69.                 set write_newline=1
  70.             )
  71.         )
  72.     )
  73.     if defined write_newline (
  74.         echo:
  75.     )
  76. ) || (
  77.     set index=0
  78. )
  79. echo:
  80. echo [Warnings]:
  81. echo - Programs minimized in the notification area are ignored.
  82. echo - Some rare other programs are sometimes also ignored.
  83. echo:
  84. <nul set /p="> Do you want to [P]in or [R]estore your window? [P, R]: "
  85. choice /n /c PR
  86. if !errorlevel!==1 (
  87.     set display_action=Pin
  88.     set action=PIN
  89. ) else if !errorlevel!==2 (
  90.     set display_action=Restore
  91.     set action=RESTORE
  92. ) else (
  93.     exit /b
  94. )
  95.  
  96. :CHOOSE_EXECUTABLE
  97. if defined executable (
  98.     set executable=
  99. )
  100. set /p "executable=>> Enter the executable you want to !display_action!: "
  101. if not defined executable (
  102.     call :ERROR_WINDOW
  103.     goto :CHOOSE_EXECUTABLE
  104. ) else (
  105.     if not "!executable:~-4!"==".exe" (
  106.         set "executable=!executable!.exe"
  107.     )
  108. )
  109. call :TASKLIST executable || (
  110.     call :ERROR_WINDOW
  111.     goto :CHOOSE_EXECUTABLE
  112. )
  113. call :EXECUTABLE_!action!
  114. if not !errorlevel!==0 (
  115.     echo ERROR: Something wrong happened.
  116.     goto :CHOOSE_EXECUTABLE
  117. )
  118. if !action!==PIN (
  119.     for /l %%A in (1,1,!index!) do (
  120.         if defined memory_executable_[%%A] (
  121.             if "!memory_executable_[%%A]!"=="!executable!" (
  122.                 goto :MAIN_MENU
  123.             )
  124.         )
  125.     )
  126.     set /a index+=1
  127.     set "memory_executable_[!index!]=!executable!"
  128. ) else if !action!==RESTORE (
  129.     for /l %%A in (1,1,!index!) do (
  130.         if defined memory_executable_[%%A] (
  131.             if "!memory_executable_[%%A]!"=="!executable!" (
  132.                 set memory_executable_[%%A]=
  133.             )
  134.         )
  135.     )
  136. )
  137. goto :MAIN_MENU
  138.  
  139. :TASKLIST
  140. tasklist /v /fo csv /fi "imagename eq !%1!" | >nul find /i "!%1!" || (
  141.     exit /b 1
  142. )
  143. exit /b 0
  144.  
  145. :ERROR_WINDOW
  146. echo Error: Invalid window name or window is not currently running.
  147. exit /b
  148.  
  149. :EXECUTABLE_PIN
  150. %@CMDWIZ:?=minimize%
  151. %@CMDWIZ:?=restore%
  152. %@CMDWIZ:?=topmost%
  153. exit /b
  154.  
  155. :EXECUTABLE_RESTORE
  156. %@CMDWIZ:?=minimize%
  157. %@CMDWIZ:?=restore%
  158. %@CMDWIZ:?=top%
  159. exit /b
RAW Paste Data Copied