Przeglądaj źródła

📰 Update Launcher.bat to v 1.0.3

VLADYSLAV BOBER 11 miesięcy temu
rodzic
commit
d9bf0a82e9
1 zmienionych plików z 86 dodań i 29 usunięć
  1. 86 29
      Launcher.bat

+ 86 - 29
Launcher.bat

@@ -23,8 +23,9 @@ pushd "%CD%"
 CD /D "%~dp0"
 
 :: ====================================================
-:: PowerShell Script Launcher for VS Telemetry Disable
+:: Visual Studio Telemetry Disable Launcher
 :: ====================================================
+
 title Visual Studio Telemetry Disable Launcher
 
 :: Set script directory
@@ -39,32 +40,30 @@ 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
+:: ====================================================
 
-:: Check for PowerShell 7 first (preferred)
 if exist "%PS7_PATH%" (
     set "PS_EXE=%PS7_PATH%"
-    set "PS_SCRIPT=%SCRIPT_DIR%script\off_telemetry_ps7.ps1"
     set "PS_VERSION=PowerShell 7"
     goto :found_powershell
 )
 
-:: Check for PowerShell 7 Preview
 if exist "%PS7_PREVIEW_PATH%" (
     set "PS_EXE=%PS7_PREVIEW_PATH%"
-    set "PS_SCRIPT=%SCRIPT_DIR%script\off_telemetry_ps7.ps1"
     set "PS_VERSION=PowerShell 7 Preview"
     goto :found_powershell
 )
 
-:: Check for PowerShell 5
 if exist "%PS5_PATH%" (
     set "PS_EXE=%PS5_PATH%"
-    set "PS_SCRIPT=%SCRIPT_DIR%script\off_telemetry_ps5.ps1"
     set "PS_VERSION=PowerShell 5"
     goto :found_powershell
 )
 
-:: No PowerShell found
 echo [ERROR] No compatible PowerShell version found!
 echo.
 echo Please install either:
@@ -75,33 +74,81 @@ pause
 exit /b 1
 
 :found_powershell
-:: Check if the corresponding PowerShell script exists
-if not exist "%PS_SCRIPT%" (
-    echo [ERROR] PowerShell script not found: %PS_SCRIPT%
-    echo.
-    if "%PS_VERSION%"=="PowerShell 7" (
-        echo Make sure off_telemetry_ps7.ps1 is in the 'script' subdirectory.
-    ) else if "%PS_VERSION%"=="PowerShell 7 Preview" (
-        echo Make sure off_telemetry_ps7.ps1 is in the 'script' subdirectory.
+
+:: ====================================================
+:: Detect Windows Version and PowerShell
+:: ====================================================
+for /f "tokens=4-5 delims=. " %%i in ('ver') do (
+    set "WIN_MAJOR=%%i"
+    set "WIN_MINOR=%%j"
+)
+
+:: Determine script based on Windows version and PowerShell version
+if !WIN_MAJOR! GEQ 10 (
+    if "%PS_VERSION%"=="PowerShell 5" (
+        set "SCRIPT_BASENAME=off_telemetry_ps5.ps1"
+        set "SCRIPT_TYPE=Windows 10/11 - PowerShell 5"
     ) else (
-        echo Make sure off_telemetry_ps5.ps1 is in the 'script' subdirectory.
+        set "SCRIPT_BASENAME=off_telemetry_ps7.ps1"
+        set "SCRIPT_TYPE=Windows 10/11 - PowerShell 7"
     )
-    echo.
-    pause
-    exit /b 1
+) else (
+    if "%PS_VERSION%"=="PowerShell 5" (
+        set "SCRIPT_BASENAME=off_telemetry_ps5_win7+.ps1"
+        set "SCRIPT_TYPE=Windows 7/8/8.1 - PowerShell 5"
+    ) else (
+        set "SCRIPT_BASENAME=off_telemetry_ps7_win7+.ps1"
+        set "SCRIPT_TYPE=Windows 7/8/8.1 - PowerShell 7"
+    )
+)
+
+:: ====================================================
+:: 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 aka BOBER
+echo                     by EXLOUD
 echo             https://github.com/EXLOUD
-echo.
 echo ====================================================
 echo.
-echo Using: %PS_VERSION%
-echo Script location: %PS_SCRIPT%
+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
@@ -112,10 +159,12 @@ 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
 
@@ -127,23 +176,31 @@ exit /b 0
 
 :proceed
 cls
+
 echo.
-echo [INFO] Launching script on %PS_VERSION% ...
+echo [INFO] Launching Visual Studio Telemetry Disabler...
+echo [INFO] PowerShell: %PS_VERSION%
+echo [INFO] Script: !SCRIPT_TYPE!
 echo.
 
-:: Change directory to script location
 cd /d "%SCRIPT_DIR%"
 
-:: Launch PowerShell script with execution policy bypass
-"%PS_EXE%" -ExecutionPolicy Bypass -NoProfile -File "%PS_SCRIPT%"
+"%PS_EXE%" -ExecutionPolicy Bypass -NoProfile -File "!PS_SCRIPT!"
 
-:: Check exit code
 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.