| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196 |
- @echo off
- setlocal enabledelayedexpansion
- :: ====================================================
- :: Check for admin rights
- :: ====================================================
- >nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system"
- if '%errorlevel%' NEQ '0' (
- echo Requesting elevation...
- goto UACPrompt
- )
- goto Admin
- :UACPrompt
- echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadmin.vbs"
- echo UAC.ShellExecute "%~s0", "", "", "runas", 1 >> "%temp%\getadmin.vbs"
- "%temp%\getadmin.vbs"
- del "%temp%\getadmin.vbs"
- exit /B
- :Admin
- pushd "%CD%"
- CD /D "%~dp0"
- :: ====================================================
- :: Visual Studio Telemetry Disable Launcher
- :: ====================================================
- title Visual Studio Telemetry Disable Launcher
- set "SCRIPT_DIR=%~dp0"
- set "PS7_PATH=C:\Program Files\PowerShell\7\pwsh.exe"
- set "PS7_PREVIEW_PATH=C:\Program Files\PowerShell\7-preview\pwsh.exe"
- set "PS5_PATH=C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe"
- set "PS_EXE="
- set "PS_SCRIPT="
- set "PS_VERSION="
- set "SCRIPT_TYPE="
- :: ====================================================
- :: Find PowerShell Executable
- :: ====================================================
- if exist "%PS7_PATH%" (
- set "PS_EXE=%PS7_PATH%"
- set "PS_VERSION=PowerShell 7"
- goto :found_powershell
- )
- if exist "%PS7_PREVIEW_PATH%" (
- set "PS_EXE=%PS7_PREVIEW_PATH%"
- set "PS_VERSION=PowerShell 7 Preview"
- goto :found_powershell
- )
- if exist "%PS5_PATH%" (
- set "PS_EXE=%PS5_PATH%"
- set "PS_VERSION=PowerShell 5"
- goto :found_powershell
- )
- echo [ERROR] No compatible PowerShell version found!
- echo.
- echo Please install either:
- echo - PowerShell 7 (recommended)
- echo - PowerShell 5 (Windows PowerShell)
- echo.
- pause
- exit /b 1
- :found_powershell
- :: ====================================================
- :: Detect Windows Version
- :: ====================================================
- for /f "tokens=4-5 delims=. " %%i in ('ver') do (
- set "WIN_MAJOR=%%i"
- set "WIN_MINOR=%%j"
- )
- :: Select appropriate script
- if "%PS_VERSION%"=="PowerShell 5" (
- set "SCRIPT_BASENAME=off_telemetry_ps5_win7+.ps1"
- set "SCRIPT_TYPE=PowerShell 5 (Windows 7+)"
- ) else (
- set "SCRIPT_BASENAME=off_telemetry_ps7.ps1"
- set "SCRIPT_TYPE=PowerShell 7 (all Windows versions)"
- )
- :: ====================================================
- :: Locate Script
- :: ====================================================
- set "SCRIPT_FOUND="
- set "TEST_SCRIPT=%SCRIPT_DIR%!SCRIPT_BASENAME!"
- if exist "!TEST_SCRIPT!" (
- set "PS_SCRIPT=!TEST_SCRIPT!"
- set "SCRIPT_FOUND=YES"
- goto :script_found
- )
- set "TEST_SCRIPT=%SCRIPT_DIR%script\!SCRIPT_BASENAME!"
- if exist "!TEST_SCRIPT!" (
- set "PS_SCRIPT=!TEST_SCRIPT!"
- set "SCRIPT_FOUND=YES"
- set "SCRIPT_TYPE=!SCRIPT_TYPE! (from script folder)"
- goto :script_found
- )
- echo [ERROR] Expected script !SCRIPT_BASENAME! not found!
- echo.
- echo Please make sure this script exists:
- echo - !SCRIPT_BASENAME!
- echo Either in the same folder as this launcher or in the 'script' subfolder.
- echo.
- pause
- exit /b 1
- :script_found
- :: ====================================================
- :: Display Information
- :: ====================================================
- echo.
- echo ====================================================
- echo Visual Studio Telemetry Disable Script Launcher
- echo.
- echo by EXLOUD
- echo https://github.com/EXLOUD
- echo ====================================================
- echo.
- echo System Information:
- echo - PowerShell: %PS_VERSION%
- echo - Script: !SCRIPT_TYPE!
- echo - Location: !PS_SCRIPT!
- echo.
- echo This will disable telemetry for:
- echo - Visual Studio 2015-2022
- echo - Visual Studio Code
- echo - .NET CLI
- echo - NuGet
- echo.
- :confirmation
- set /p "CONFIRM=Do you want to continue? (Y/N): "
- if /i "!CONFIRM!"=="y" goto :proceed
- if /i "!CONFIRM!"=="yes" goto :proceed
- if /i "!CONFIRM!"=="n" goto :cancel
- if /i "!CONFIRM!"=="no" goto :cancel
- echo Invalid input. Please enter Y or N.
- goto :confirmation
- :cancel
- echo.
- echo Operation cancelled by user.
- pause
- exit /b 0
- :proceed
- cls
- echo.
- echo [INFO] Launching Visual Studio Telemetry Disabler...
- echo [INFO] PowerShell: %PS_VERSION%
- echo [INFO] Script: !SCRIPT_TYPE!
- echo.
- cd /d "%SCRIPT_DIR%"
- "%PS_EXE%" -ExecutionPolicy Bypass -NoProfile -File "!PS_SCRIPT!"
- if %errorLevel% == 0 (
- echo.
- echo [SUCCESS] Script completed successfully!
- echo.
- echo Visual Studio telemetry settings have been disabled.
- echo Some changes may require restarting Visual Studio.
- ) else (
- echo.
- echo [ERROR] Script encountered errors. Exit code: %errorLevel%
- echo.
- echo This may happen if:
- echo - Visual Studio is not installed
- echo - Administrator rights are required
- echo - Registry access is restricted
- )
- echo.
- echo Press any key to exit...
- pause >nul
- exit /b 0
|