Launcher.bat 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  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_DIR=%~dp0"
  26. set "PS7_PATH=C:\Program Files\PowerShell\7\pwsh.exe"
  27. set "PS7_PREVIEW_PATH=C:\Program Files\PowerShell\7-preview\pwsh.exe"
  28. set "PS5_PATH=C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe"
  29. set "PS_EXE="
  30. set "PS_SCRIPT="
  31. set "PS_VERSION="
  32. set "SCRIPT_TYPE="
  33. :: ====================================================
  34. :: Find PowerShell Executable
  35. :: ====================================================
  36. if exist "%PS7_PATH%" (
  37. set "PS_EXE=%PS7_PATH%"
  38. set "PS_VERSION=PowerShell 7"
  39. goto :found_powershell
  40. )
  41. if exist "%PS7_PREVIEW_PATH%" (
  42. set "PS_EXE=%PS7_PREVIEW_PATH%"
  43. set "PS_VERSION=PowerShell 7 Preview"
  44. goto :found_powershell
  45. )
  46. if exist "%PS5_PATH%" (
  47. set "PS_EXE=%PS5_PATH%"
  48. set "PS_VERSION=PowerShell 5"
  49. goto :found_powershell
  50. )
  51. echo [ERROR] No compatible PowerShell version found!
  52. echo.
  53. echo Please install either:
  54. echo - PowerShell 7 (recommended)
  55. echo - PowerShell 5 (Windows PowerShell)
  56. echo.
  57. pause
  58. exit /b 1
  59. :found_powershell
  60. :: ====================================================
  61. :: Detect Windows Version
  62. :: ====================================================
  63. for /f "tokens=4-5 delims=. " %%i in ('ver') do (
  64. set "WIN_MAJOR=%%i"
  65. set "WIN_MINOR=%%j"
  66. )
  67. :: Select appropriate script
  68. if "%PS_VERSION%"=="PowerShell 5" (
  69. set "SCRIPT_BASENAME=off_telemetry_ps5_win7+.ps1"
  70. set "SCRIPT_TYPE=PowerShell 5 (Windows 7+)"
  71. ) else (
  72. set "SCRIPT_BASENAME=off_telemetry_ps7.ps1"
  73. set "SCRIPT_TYPE=PowerShell 7 (all Windows versions)"
  74. )
  75. :: ====================================================
  76. :: Locate Script
  77. :: ====================================================
  78. set "SCRIPT_FOUND="
  79. set "TEST_SCRIPT=%SCRIPT_DIR%!SCRIPT_BASENAME!"
  80. if exist "!TEST_SCRIPT!" (
  81. set "PS_SCRIPT=!TEST_SCRIPT!"
  82. set "SCRIPT_FOUND=YES"
  83. goto :script_found
  84. )
  85. set "TEST_SCRIPT=%SCRIPT_DIR%script\!SCRIPT_BASENAME!"
  86. if exist "!TEST_SCRIPT!" (
  87. set "PS_SCRIPT=!TEST_SCRIPT!"
  88. set "SCRIPT_FOUND=YES"
  89. set "SCRIPT_TYPE=!SCRIPT_TYPE! (from script folder)"
  90. goto :script_found
  91. )
  92. echo [ERROR] Expected script !SCRIPT_BASENAME! not found!
  93. echo.
  94. echo Please make sure this script exists:
  95. echo - !SCRIPT_BASENAME!
  96. echo Either in the same folder as this launcher or in the 'script' subfolder.
  97. echo.
  98. pause
  99. exit /b 1
  100. :script_found
  101. :: ====================================================
  102. :: Display Information
  103. :: ====================================================
  104. echo.
  105. echo ====================================================
  106. echo Visual Studio Telemetry Disable Script Launcher
  107. echo.
  108. echo by EXLOUD
  109. echo https://github.com/EXLOUD
  110. echo ====================================================
  111. echo.
  112. echo System Information:
  113. echo - PowerShell: %PS_VERSION%
  114. echo - Script: !SCRIPT_TYPE!
  115. echo - Location: !PS_SCRIPT!
  116. echo.
  117. echo This will disable telemetry for:
  118. echo - Visual Studio 2015-2022
  119. echo - Visual Studio Code
  120. echo - .NET CLI
  121. echo - NuGet
  122. echo.
  123. :confirmation
  124. set /p "CONFIRM=Do you want to continue? (Y/N): "
  125. if /i "!CONFIRM!"=="y" goto :proceed
  126. if /i "!CONFIRM!"=="yes" goto :proceed
  127. if /i "!CONFIRM!"=="n" goto :cancel
  128. if /i "!CONFIRM!"=="no" goto :cancel
  129. echo Invalid input. Please enter Y or N.
  130. goto :confirmation
  131. :cancel
  132. echo.
  133. echo Operation cancelled by user.
  134. pause
  135. exit /b 0
  136. :proceed
  137. cls
  138. echo.
  139. echo [INFO] Launching Visual Studio Telemetry Disabler...
  140. echo [INFO] PowerShell: %PS_VERSION%
  141. echo [INFO] Script: !SCRIPT_TYPE!
  142. echo.
  143. cd /d "%SCRIPT_DIR%"
  144. "%PS_EXE%" -ExecutionPolicy Bypass -NoProfile -File "!PS_SCRIPT!"
  145. if %errorLevel% == 0 (
  146. echo.
  147. echo [SUCCESS] Script completed successfully!
  148. echo.
  149. echo Visual Studio telemetry settings have been disabled.
  150. echo Some changes may require restarting Visual Studio.
  151. ) else (
  152. echo.
  153. echo [ERROR] Script encountered errors. Exit code: %errorLevel%
  154. echo.
  155. echo This may happen if:
  156. echo - Visual Studio is not installed
  157. echo - Administrator rights are required
  158. echo - Registry access is restricted
  159. )
  160. echo.
  161. echo Press any key to exit...
  162. pause >nul
  163. exit /b 0