Launcher.bat 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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. :: PowerShell Script Launcher for VS Telemetry Disable
  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. :: Check for PowerShell 7 first (preferred)
  36. if exist "%PS7_PATH%" (
  37. set "PS_EXE=%PS7_PATH%"
  38. set "PS_SCRIPT=%SCRIPT_DIR%script\off_telemetry_ps7.ps1"
  39. set "PS_VERSION=PowerShell 7"
  40. goto :found_powershell
  41. )
  42. :: Check for PowerShell 7 Preview
  43. if exist "%PS7_PREVIEW_PATH%" (
  44. set "PS_EXE=%PS7_PREVIEW_PATH%"
  45. set "PS_SCRIPT=%SCRIPT_DIR%script\off_telemetry_ps7.ps1"
  46. set "PS_VERSION=PowerShell 7 Preview"
  47. goto :found_powershell
  48. )
  49. :: Check for PowerShell 5
  50. if exist "%PS5_PATH%" (
  51. set "PS_EXE=%PS5_PATH%"
  52. set "PS_SCRIPT=%SCRIPT_DIR%script\off_telemetry_ps5.ps1"
  53. set "PS_VERSION=PowerShell 5"
  54. goto :found_powershell
  55. )
  56. :: No PowerShell found
  57. echo [ERROR] No compatible PowerShell version found!
  58. echo.
  59. echo Please install either:
  60. echo - PowerShell 7 (recommended)
  61. echo - PowerShell 5 (Windows PowerShell)
  62. echo.
  63. pause
  64. exit /b 1
  65. :found_powershell
  66. :: Check if the corresponding PowerShell script exists
  67. if not exist "%PS_SCRIPT%" (
  68. echo [ERROR] PowerShell script not found: %PS_SCRIPT%
  69. echo.
  70. if "%PS_VERSION%"=="PowerShell 7" (
  71. echo Make sure off_telemetry_ps7.ps1 is in the 'script' subdirectory.
  72. ) else if "%PS_VERSION%"=="PowerShell 7 Preview" (
  73. echo Make sure off_telemetry_ps7.ps1 is in the 'script' subdirectory.
  74. ) else (
  75. echo Make sure off_telemetry_ps5.ps1 is in the 'script' subdirectory.
  76. )
  77. echo.
  78. pause
  79. exit /b 1
  80. )
  81. echo.
  82. echo ====================================================
  83. echo Visual Studio Telemetry Disable Script Launcher
  84. echo.
  85. echo by EXLOUD aka BOBER
  86. echo https://github.com/EXLOUD
  87. echo.
  88. echo ====================================================
  89. echo.
  90. echo Using: %PS_VERSION%
  91. echo Script location: %PS_SCRIPT%
  92. echo.
  93. echo This will disable telemetry for:
  94. echo - Visual Studio 2015-2022
  95. echo - Visual Studio Code
  96. echo - .NET CLI
  97. echo - NuGet
  98. echo.
  99. :confirmation
  100. set /p "CONFIRM=Do you want to continue? (Y/N): "
  101. if /i "!CONFIRM!"=="y" goto :proceed
  102. if /i "!CONFIRM!"=="yes" goto :proceed
  103. if /i "!CONFIRM!"=="n" goto :cancel
  104. if /i "!CONFIRM!"=="no" goto :cancel
  105. echo Invalid input. Please enter Y or N.
  106. goto :confirmation
  107. :cancel
  108. echo.
  109. echo Operation cancelled by user.
  110. pause
  111. exit /b 0
  112. :proceed
  113. cls
  114. echo.
  115. echo [INFO] Launching script on %PS_VERSION% ...
  116. echo.
  117. :: Change directory to script location
  118. cd /d "%SCRIPT_DIR%"
  119. :: Launch PowerShell script with execution policy bypass
  120. "%PS_EXE%" -ExecutionPolicy Bypass -NoProfile -File "%PS_SCRIPT%"
  121. :: Check exit code
  122. if %errorLevel% == 0 (
  123. echo.
  124. echo [SUCCESS] Script completed successfully!
  125. ) else (
  126. echo.
  127. echo [ERROR] Script encountered errors. Exit code: %errorLevel%
  128. )
  129. echo.
  130. echo Press any key to exit...
  131. pause >nul
  132. exit /b 0