فهرست منبع

📰 Update off_telemetry_ps7.ps1

VLADYSLAV BOBER 11 ماه پیش
والد
کامیت
1994af2c61
1فایلهای تغییر یافته به همراه64 افزوده شده و 99 حذف شده
  1. 64 99
      script/off_telemetry_ps7.ps1

+ 64 - 99
script/off_telemetry_ps7.ps1

@@ -206,18 +206,22 @@ function Set-RegistryValue {
     )
 
     try {
+        # Створити ключ, якщо його немає
         if (!(Test-Path $Path)) {
-            Write-Host "Registry path not found, skipping: $Path" -ForegroundColor $Colors.Gray
-            return $false
+            New-Item -Path $Path -Force | Out-Null
+            Write-Host "→ Created registry path: $Path" -ForegroundColor $Colors.Info
         }
 
-        $currentValue = Get-ItemProperty -Path $Path -Name $Name -ErrorAction SilentlyContinue
-        if ($null -ne $currentValue -and $currentValue.$Name -eq $Value) {
+        # Отримати поточне значення
+        $current = Get-ItemProperty -Path $Path -Name $Name -ErrorAction SilentlyContinue
+
+        if ($null -ne $current -and $current.$Name -eq $Value) {
             Write-Host "✓ $Name already set to $Value in $Path" -ForegroundColor $Colors.Success
             return $true
         }
 
-        $null = Set-ItemProperty -Path $Path -Name $Name -Value $Value -Type $Type -Force -ErrorAction Stop
+        # Встановити або оновити значення
+        Set-ItemProperty -Path $Path -Name $Name -Value $Value -Type $Type -Force
         Write-Host "✓ Set $Name to $Value in $Path" -ForegroundColor $Colors.Success
         return $true
     }
@@ -920,135 +924,96 @@ Write-Host "(processed)" -ForegroundColor $Colors.Success
 # =======================================================
 Write-Host "`n--- Optional: Additional Features and Environment Variables ---" -ForegroundColor $Colors.Section
 
-Write-Host "This will perform additional configuration:" -ForegroundColor $Colors.Info
-Write-Host "• Disable Visual Studio Settings Synchronization" -ForegroundColor $Colors.Info
-Write-Host "• Disable Live Share" -ForegroundColor $Colors.Info
-Write-Host "• Disable IntelliCode" -ForegroundColor $Colors.Info
-Write-Host "• Disable CodeLens" -ForegroundColor $Colors.Info
-Write-Host "• Set additional environment variables (INTELLICODE_TELEMETRY_OPTOUT, LIVESHARE_TELEMETRY_OPTOUT, VSSDK_TELEMETRY_OPTOUT)" -ForegroundColor $Colors.Info
+# Only offer extra tweaks if at least one VS version is installed
+if ($installedVersions.Count -eq 0) {
+    Write-Host "→ No Visual Studio installations detected – skipping additional configuration" -ForegroundColor $Colors.Gray
+}
+else {
+    Write-Host "This will perform additional configuration:" -ForegroundColor $Colors.Info
+    Write-Host "• Disable Visual Studio Settings Synchronization" -ForegroundColor $Colors.Info
+    Write-Host "• Disable Live Share" -ForegroundColor $Colors.Info
+    Write-Host "• Disable IntelliCode" -ForegroundColor $Colors.Info
+    Write-Host "• Disable CodeLens" -ForegroundColor $Colors.Info
+    Write-Host "• Set additional environment variables:" -ForegroundColor $Colors.Info
+    Write-Host "  - INTELLICODE_TELEMETRY_OPTOUT" -ForegroundColor $Colors.Info
+    Write-Host "  - LIVESHARE_TELEMETRY_OPTOUT" -ForegroundColor $Colors.Info
+    Write-Host "  - VSSDK_TELEMETRY_OPTOUT" -ForegroundColor $Colors.Info
 
-$enableAdditional = Read-Host "`nEnable additional configuration? (y/n)"
+    $enableAdditional = Read-Host "`nEnable additional configuration? (y/n)"
+
+    if ($enableAdditional -match '^y(es)?$') {
+
+        # === Disabling Additional Visual Studio Features ===
+        Write-Host "`n--- Disabling Additional Visual Studio Features ---" -ForegroundColor $Colors.Section
 
-if ($enableAdditional -eq 'y' -or $enableAdditional -eq 'Y' -or $enableAdditional -eq 'yes' -or $enableAdditional -eq 'Yes' -or $enableAdditional -eq 'YES') {
-    
-    # =======================================================
-    # VISUAL STUDIO ADDITIONAL FEATURES DISABLE
-    # =======================================================
-    Write-Host "`n--- Disabling Additional Visual Studio Features ---" -ForegroundColor $Colors.Section
-    
-    if ($installedVersions.Count -gt 0) {
         foreach ($version in $installedVersions) {
             $vsName = $vsVersions[$version]
             Write-Host "`n--- Processing Additional Features for $vsName (version $version) ---" -ForegroundColor $Colors.Info
-            
-            # =======================================================
-            # SETTINGS SYNCHRONIZATION
-            # =======================================================
-            Write-Host "→ Disabling Settings Synchronization..." -ForegroundColor $Colors.Info
-            
+
+            # Settings Sync
             $settingsPaths = @(
                 "HKCU:\Software\Microsoft\VisualStudio\$version\Settings",
                 "HKCU:\Software\Microsoft\VisualStudio\$version\ApplicationPrivateSettings\Microsoft\VisualStudio\Settings"
             )
-            
             foreach ($path in $settingsPaths) {
-                Set-RegistryValue -Path $path -Name "SyncSettings" -Value 0
-                Set-RegistryValue -Path $path -Name "EnableRoaming" -Value 0
-                Set-RegistryValue -Path $path -Name "EnableSync" -Value 0
-                Set-RegistryValue -Path $path -Name "DisableSync" -Value 1
+                Set-RegistryValue -Path $path -Name "SyncSettings"      -Value 0
+                Set-RegistryValue -Path $path -Name "EnableRoaming"     -Value 0
+                Set-RegistryValue -Path $path -Name "EnableSync"        -Value 0
+                Set-RegistryValue -Path $path -Name "DisableSync"       -Value 1
             }
-            
-            # Additional settings sync paths
-            $syncPath = "HKCU:\Software\Microsoft\VisualStudio\$version\ApplicationPrivateSettings\Microsoft\VisualStudio\ConnectedServices"
-            Set-RegistryValue -Path $syncPath -Name "Provider.Enabled" -Value 0
-            
-            # =======================================================
-            # LIVE SHARE
-            # =======================================================
-            Write-Host "→ Disabling Live Share..." -ForegroundColor $Colors.Info
-            
+
+            # Live Share
             $liveSharePaths = @(
                 "HKCU:\Software\Microsoft\VisualStudio\$version\LiveShare",
                 "HKCU:\Software\Microsoft\VisualStudio\$version\ApplicationPrivateSettings\Microsoft\VisualStudio\LiveShare"
             )
-            
             foreach ($path in $liveSharePaths) {
-                Set-RegistryValue -Path $path -Name "Enabled" -Value 0
-                Set-RegistryValue -Path $path -Name "EnableTelemetry" -Value 0
-                Set-RegistryValue -Path $path -Name "DisableTelemetry" -Value 1
-                Set-RegistryValue -Path $path -Name "OptedIn" -Value 0
+                Set-RegistryValue -Path $path -Name "Enabled"           -Value 0
+                Set-RegistryValue -Path $path -Name "EnableTelemetry"   -Value 0
+                Set-RegistryValue -Path $path -Name "DisableTelemetry"  -Value 1
+                Set-RegistryValue -Path $path -Name "OptedIn"           -Value 0
             }
-            
-            # Live Share telemetry
-            $liveShareTelemetryPath = "HKCU:\Software\Microsoft\VisualStudio\$version\LiveShare\Telemetry"
-            Set-RegistryValue -Path $liveShareTelemetryPath -Name "Enabled" -Value 0
-            Set-RegistryValue -Path $liveShareTelemetryPath -Name "OptOut" -Value 1
-            
-            # =======================================================
-            # INTELLICODE
-            # =======================================================
-            Write-Host "→ Disabling IntelliCode..." -ForegroundColor $Colors.Info
-            
+
+            # IntelliCode
             $intelliCodePaths = @(
                 "HKCU:\Software\Microsoft\VisualStudio\$version\IntelliCode",
                 "HKCU:\Software\Microsoft\VisualStudio\$version\IntelliSense\IntelliCode",
                 "HKCU:\Software\Microsoft\VisualStudio\$version\ApplicationPrivateSettings\Microsoft\VisualStudio\IntelliCode"
             )
-            
             foreach ($path in $intelliCodePaths) {
-                Set-RegistryValue -Path $path -Name "DisableTelemetry" -Value 1
-                Set-RegistryValue -Path $path -Name "EnableTelemetry" -Value 0
-                Set-RegistryValue -Path $path -Name "OptedIn" -Value 0
-                Set-RegistryValue -Path $path -Name "Enabled" -Value 0
+                Set-RegistryValue -Path $path -Name "DisableTelemetry"  -Value 1
+                Set-RegistryValue -Path $path -Name "EnableTelemetry"   -Value 0
+                Set-RegistryValue -Path $path -Name "OptedIn"           -Value 0
+                Set-RegistryValue -Path $path -Name "Enabled"           -Value 0
                 Set-RegistryValue -Path $path -Name "ModelDownloadEnabled" -Value 0
             }
-            
-            # IntelliCode privacy settings
-            $intelliCodePrivacyPath = "HKCU:\Software\Microsoft\VisualStudio\$version\IntelliCode\Privacy"
-            Set-RegistryValue -Path $intelliCodePrivacyPath -Name "TelemetryOptOut" -Value 1
-            Set-RegistryValue -Path $intelliCodePrivacyPath -Name "DataCollection" -Value 0
-            Set-RegistryValue -Path $intelliCodePrivacyPath -Name "UsageDataOptOut" -Value 1
-            
-            # =======================================================
-            # CODELENS
-            # =======================================================
-            Write-Host "→ Disabling CodeLens..." -ForegroundColor $Colors.Info
-            
+
+            # CodeLens
             $codeLensPaths = @(
                 "HKCU:\Software\Microsoft\VisualStudio\$version\CodeLens",
                 "HKCU:\Software\Microsoft\VisualStudio\$version\TextEditor\CodeLens",
                 "HKCU:\Software\Microsoft\VisualStudio\$version\ApplicationPrivateSettings\Microsoft\VisualStudio\CodeLens"
             )
-            
             foreach ($path in $codeLensPaths) {
-                Set-RegistryValue -Path $path -Name "Disabled" -Value 1
-                Set-RegistryValue -Path $path -Name "ShowAuthorCodeLens" -Value 0
+                Set-RegistryValue -Path $path -Name "Disabled"              -Value 1
+                Set-RegistryValue -Path $path -Name "ShowAuthorCodeLens"    -Value 0
                 Set-RegistryValue -Path $path -Name "ShowReferencesCodeLens" -Value 0
-                Set-RegistryValue -Path $path -Name "ShowTestCodeLens" -Value 0
-                Set-RegistryValue -Path $path -Name "Enabled" -Value 0
+                Set-RegistryValue -Path $path -Name "ShowTestCodeLens"      -Value 0
+                Set-RegistryValue -Path $path -Name "Enabled"               -Value 0
             }
-            
-            # CodeLens telemetry
-            $codeLensTelemetryPath = "HKCU:\Software\Microsoft\VisualStudio\$version\CodeLens\Telemetry"
-            Set-RegistryValue -Path $codeLensTelemetryPath -Name "Enabled" -Value 0
-            Set-RegistryValue -Path $codeLensTelemetryPath -Name "OptOut" -Value 1
         }
-    } else {
-        Write-Host "→ No Visual Studio installations detected, skipping additional features" -ForegroundColor $Colors.Gray
+
+        # Additional environment variables
+        Write-Host "`n--- Setting Additional Environment Variables ---" -ForegroundColor $Colors.Section
+        Set-EnvironmentVariableIfNeeded -Name 'INTELLICODE_TELEMETRY_OPTOUT' -Value '1' -Target 'User'
+        Set-EnvironmentVariableIfNeeded -Name 'LIVESHARE_TELEMETRY_OPTOUT'   -Value '1' -Target 'User'
+        Set-EnvironmentVariableIfNeeded -Name 'VSSDK_TELEMETRY_OPTOUT'       -Value '1' -Target 'User'
+
+        Write-Host "`n✓ Additional configuration completed" -ForegroundColor $Colors.Success
+    }
+    else {
+        Write-Host "→ Skipping additional configuration" -ForegroundColor $Colors.Info
     }
-    
-    # =======================================================
-    # ADDITIONAL ENVIRONMENT VARIABLES
-    # =======================================================
-    Write-Host "`n--- Setting Additional Environment Variables ---" -ForegroundColor $Colors.Section
-    
-    Set-EnvironmentVariableIfNeeded -Name 'INTELLICODE_TELEMETRY_OPTOUT' -Value '1' -Target 'User'
-    Set-EnvironmentVariableIfNeeded -Name 'LIVESHARE_TELEMETRY_OPTOUT' -Value '1' -Target 'User'
-    Set-EnvironmentVariableIfNeeded -Name 'VSSDK_TELEMETRY_OPTOUT' -Value '1' -Target 'User'
-    
-    Write-Host "`n✓ Additional configuration completed" -ForegroundColor $Colors.Success
-} else {
-    Write-Host "→ Skipping additional configuration" -ForegroundColor $Colors.Info
 }
 
 Write-Host "`nLegend:" -ForegroundColor $Colors.White