Launcher.bat 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. @echo off
  2. setlocal enabledelayedexpansion
  3. :: ====================================================
  4. :: Define PowerShell paths
  5. :: ====================================================
  6. set "PS5_PATH=%systemdrive%\Windows\System32\WindowsPowerShell\v1.0\powershell.exe"
  7. set "PS7_PATH=%ProgramFiles%\PowerShell\7\pwsh.exe"
  8. set "PS7_PREVIEW_PATH=%ProgramFiles%\PowerShell\7-preview\pwsh.exe"
  9. :: Find best PowerShell for admin elevation
  10. set "ELEVATION_PS="
  11. if exist "%PS7_PREVIEW_PATH%" (
  12. set "ELEVATION_PS=%PS7_PREVIEW_PATH%"
  13. ) else if exist "%PS7_PATH%" (
  14. set "ELEVATION_PS=%PS7_PATH%"
  15. ) else if exist "%PS5_PATH%" (
  16. set "ELEVATION_PS=%PS5_PATH%"
  17. ) else (
  18. echo [ERROR] No PowerShell found for elevation!
  19. pause
  20. exit /b 1
  21. )
  22. :: ====================================================
  23. :: Launch with admin rights
  24. :: ====================================================
  25. if "%1"=="admin" goto :AdminMode
  26. echo [INFO] Launch with admin rights...
  27. "%ELEVATION_PS%" -Command "Start-Process cmd -ArgumentList '/c \"%~f0\" admin' -Verb RunAs"
  28. exit /B
  29. :AdminMode
  30. pushd "%CD%"
  31. CD /D "%~dp0"
  32. :: ====================================================
  33. :: Visual Studio Telemetry Disable Launcher
  34. :: ====================================================
  35. title Visual Studio Telemetry Disable Launcher
  36. :: Set script directory
  37. set "SCRIPT_DIR=%~dp0"
  38. :: Initialize variables
  39. set "PS_EXE="
  40. set "PS_SCRIPT="
  41. set "PS_VERSION="
  42. set "SCRIPT_TYPE="
  43. :: ====================================================
  44. :: Find PowerShell Executable (пріоритет: Preview > 7 > 5)
  45. :: ====================================================
  46. if exist "%PS7_PREVIEW_PATH%" (
  47. set "PS_EXE=%PS7_PREVIEW_PATH%"
  48. set "PS_VERSION=PowerShell 7 Preview"
  49. set "PS_MAJOR=7"
  50. goto :found_powershell
  51. )
  52. if exist "%PS7_PATH%" (
  53. set "PS_EXE=%PS7_PATH%"
  54. set "PS_VERSION=PowerShell 7"
  55. set "PS_MAJOR=7"
  56. goto :found_powershell
  57. )
  58. if exist "%PS5_PATH%" (
  59. set "PS_EXE=%PS5_PATH%"
  60. set "PS_VERSION=PowerShell 5"
  61. set "PS_MAJOR=5"
  62. goto :found_powershell
  63. )
  64. echo [ERROR] No compatible PowerShell version found!
  65. echo.
  66. echo Please install either:
  67. echo - PowerShell 7 Preview (recommended)
  68. echo - PowerShell 7
  69. echo - PowerShell 5 (Windows PowerShell)
  70. echo.
  71. pause
  72. exit /b 1
  73. :found_powershell
  74. :: ====================================================
  75. :: Detect Windows Version
  76. :: ====================================================
  77. for /f "tokens=4-5 delims=. " %%i in ('ver') do (
  78. set "WIN_MAJOR=%%i"
  79. set "WIN_MINOR=%%j"
  80. )
  81. :: ====================================================
  82. :: Choose Script Based on Windows Version AND PowerShell Version
  83. :: ====================================================
  84. if !WIN_MAJOR! GEQ 10 (
  85. if !PS_MAJOR!==5 (
  86. set "SCRIPT_BASENAME=off_telemetry_ps5_win7+.ps1"
  87. set "SCRIPT_TYPE=Windows 10/11 with PowerShell 5"
  88. ) else (
  89. set "SCRIPT_BASENAME=off_telemetry_ps7.ps1"
  90. set "SCRIPT_TYPE=Windows 10/11 with PowerShell 7"
  91. )
  92. ) else (
  93. set "SCRIPT_BASENAME=off_telemetry_ps5_win7+.ps1"
  94. set "SCRIPT_TYPE=Windows 7/8/8.1"
  95. )
  96. :: ====================================================
  97. :: Locate Script
  98. :: ====================================================
  99. set "SCRIPT_FOUND="
  100. set "TEST_SCRIPT=%SCRIPT_DIR%!SCRIPT_BASENAME!"
  101. if exist "!TEST_SCRIPT!" (
  102. set "PS_SCRIPT=!TEST_SCRIPT!"
  103. set "SCRIPT_FOUND=YES"
  104. goto :script_found
  105. )
  106. set "TEST_SCRIPT=%SCRIPT_DIR%script\!SCRIPT_BASENAME!"
  107. if exist "!TEST_SCRIPT!" (
  108. set "PS_SCRIPT=!TEST_SCRIPT!"
  109. set "SCRIPT_FOUND=YES"
  110. set "SCRIPT_TYPE=!SCRIPT_TYPE! (from script folder)"
  111. goto :script_found
  112. )
  113. echo [ERROR] Expected script !SCRIPT_BASENAME! not found!
  114. echo.
  115. echo Please make sure this script exists:
  116. echo - !SCRIPT_BASENAME!
  117. echo Either in the same folder as this launcher or in the 'script' subfolder.
  118. echo.
  119. pause
  120. exit /b 1
  121. :script_found
  122. :: ====================================================
  123. :: Display Information
  124. :: ====================================================
  125. echo.
  126. echo ====================================================
  127. echo Visual Studio Telemetry Disable Script Launcher
  128. echo.
  129. echo by EXLOUD
  130. echo https://github.com/EXLOUD
  131. echo ====================================================
  132. echo.
  133. echo System Information:
  134. echo - PowerShell: %PS_VERSION%
  135. echo - Script: !SCRIPT_TYPE!
  136. echo - Location: !PS_SCRIPT!
  137. echo.
  138. echo This will disable telemetry for:
  139. echo - Visual Studio 2015-2022
  140. echo - Visual Studio Code
  141. echo - .NET CLI
  142. echo - NuGet
  143. echo.
  144. :confirmation
  145. set /p "CONFIRM=Do you want to continue? (Y/N): "
  146. if /i "!CONFIRM!"=="y" goto :proceed
  147. if /i "!CONFIRM!"=="yes" goto :proceed
  148. if /i "!CONFIRM!"=="n" goto :cancel
  149. if /i "!CONFIRM!"=="no" goto :cancel
  150. echo Invalid input. Please enter Y or N.
  151. goto :confirmation
  152. :cancel
  153. echo.
  154. echo Operation cancelled by user.
  155. pause
  156. exit /b 0
  157. :proceed
  158. cls
  159. echo.
  160. echo [INFO] Launching Visual Studio Telemetry Disabler...
  161. echo [INFO] PowerShell: %PS_VERSION%
  162. echo [INFO] Script: !SCRIPT_TYPE!
  163. echo.
  164. echo [WARNING] Administrator rights may be required for some registry changes.
  165. echo.
  166. cd /d "%SCRIPT_DIR%"
  167. "%PS_EXE%" -ExecutionPolicy Bypass -NoProfile -File "!PS_SCRIPT!"
  168. if %errorLevel% == 0 (
  169. echo.
  170. echo [SUCCESS] Script completed successfully!
  171. echo.
  172. echo Visual Studio telemetry settings have been disabled.
  173. echo Some changes may require restarting Visual Studio.
  174. ) else (
  175. echo.
  176. echo [ERROR] Script encountered errors. Exit code: %errorLevel%
  177. echo.
  178. echo This may happen if:
  179. echo - Visual Studio is not installed
  180. echo - Administrator rights are required
  181. echo - Registry access is restricted
  182. )
  183. echo.
  184. echo Press any key to exit...
  185. pause >nul
  186. exit /b 0