Launcher.bat 5.3 KB

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