off_telemetry_ps7.ps1 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044
  1. using namespace System.Collections.Generic
  2. <#
  3. .SYNOPSIS
  4. Enhanced comprehensive script to disable telemetry in Microsoft development tools with backup/restore functionality
  5. .DESCRIPTION
  6. This script disables telemetry, crash reporting, and data collection for:
  7. - Visual Studio 2015-2022 (only if installed)
  8. - Visual Studio Code (only if installed)
  9. - Visual Studio Background Download ( OFF automatic component downloads)
  10. - .NET CLI
  11. - NuGet
  12. - Various Visual Studio services
  13. .NOTES
  14. Must be run as Administrator
  15. Only modifies existing registry paths - does not create new ones
  16. Requires PowerShell 7.0+
  17. Includes comprehensive backup and restore functionality
  18. .PARAMETER CreateBackup
  19. Creates registry backup before making changes
  20. .PARAMETER RestoreBackup
  21. Restores registry from backup file
  22. .PARAMETER BackupPath
  23. Path for backup file (default: Desktop with timestamp)
  24. .PARAMETER DisableBackgroundDownload
  25. Specifically disable Visual Studio Background Download feature
  26. .EXAMPLE
  27. .\off_telemetry_ps7.ps1 -CreateBackup
  28. .\off_telemetry_ps7.ps1 -RestoreBackup -BackupPath "C:\Backup\registry_backup.reg"
  29. .\off_telemetry_ps7.ps1 -CreateBackup -BackupPath "C:\MyBackups\telemetry_backup.reg"
  30. .\off_telemetry_ps7.ps1 -DisableBackgroundDownload
  31. #>
  32. param(
  33. [switch]$CreateBackup,
  34. [switch]$RestoreBackup,
  35. [string]$BackupPath = "$env:USERPROFILE\Desktop\telemetry_backup_$(Get-Date -Format 'yyyyMMdd_HHmmss').reg",
  36. [switch]$DisableBackgroundDownload
  37. )
  38. # Color scheme for consistent output
  39. $Colors = @{
  40. Title = 'Cyan'
  41. Section = 'Yellow'
  42. Success = 'Green'
  43. Info = 'Blue'
  44. Warning = 'Yellow'
  45. Error = 'Red'
  46. Gray = 'Gray'
  47. White = 'White'
  48. }
  49. Write-Host "======================================================" -ForegroundColor $Colors.Title
  50. Write-Host " by EXLOUD" -ForegroundColor $Colors.Title
  51. Write-Host "======================================================" -ForegroundColor $Colors.Title
  52. # =======================================================
  53. # BACKUP AND RESTORE FUNCTIONS
  54. # =======================================================
  55. function New-RegistryBackup {
  56. <#
  57. .SYNOPSIS
  58. Creates backup of telemetry-related registry keys
  59. .PARAMETER BackupFile
  60. Path where backup file will be created
  61. #>
  62. param([string]$BackupFile)
  63. Write-Host "`n--- Creating Registry Backup ---" -ForegroundColor $Colors.Section
  64. try {
  65. # Ensure backup directory exists
  66. $backupDir = Split-Path -Path $BackupFile -Parent
  67. if (!(Test-Path $backupDir)) {
  68. New-Item -Path $backupDir -ItemType Directory -Force | Out-Null
  69. Write-Host "→ Created backup directory: $backupDir" -ForegroundColor $Colors.Info
  70. }
  71. # Registry keys to backup
  72. $backupKeys = [ordered]@{
  73. "VSCommon_x64" = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VSCommon"
  74. "VSCommon_x86" = "HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\VSCommon"
  75. "VSPolicies" = "HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\VisualStudio"
  76. "VSUser" = "HKEY_CURRENT_USER\Software\Microsoft\VisualStudio"
  77. "SQMClient_x64" = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\SQMClient"
  78. "SQMClient_x86" = "HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\SQMClient"
  79. "VSSetup_x64" = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\Setup"
  80. "VSSetup_x86" = "HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\VisualStudio\Setup"
  81. }
  82. $backupCount = 0
  83. $backupContent = @()
  84. # Add header to backup file
  85. $backupContent += "Windows Registry Editor Version 5.00"
  86. $backupContent += ""
  87. $backupContent += "; Telemetry Registry Backup created on $(Get-Date -Format 'yyyy-MM-dd HH:mm:ss')"
  88. $backupContent += "; Generated by Enhanced Telemetry Manager for PowerShell 7.0+"
  89. $backupContent += ""
  90. foreach ($keyInfo in $backupKeys.GetEnumerator()) {
  91. $keyName = $keyInfo.Key
  92. $keyPath = $keyInfo.Value
  93. Write-Host "→ Checking registry key: $keyName" -ForegroundColor $Colors.Info
  94. # Use reg.exe to export individual keys
  95. $tempFile = [System.IO.Path]::GetTempFileName() + ".reg"
  96. try {
  97. $process = Start-Process -FilePath "reg.exe" -ArgumentList @("export", $keyPath, $tempFile, "/y") -Wait -PassThru -NoNewWindow -RedirectStandardOutput $null -RedirectStandardError $null
  98. if ($process.ExitCode -eq 0 -and (Test-Path $tempFile)) {
  99. $keyContent = Get-Content -Path $tempFile -Encoding Unicode | Where-Object { $_ -notmatch "^Windows Registry Editor" -and $_ -ne "" }
  100. if ($keyContent) {
  101. $backupContent += ""
  102. $backupContent += "; === $keyName ==="
  103. $backupContent += $keyContent
  104. $backupCount++
  105. Write-Host "✓ Backed up: $keyName" -ForegroundColor $Colors.Success
  106. } else {
  107. Write-Host "→ Key exists but is empty: $keyName" -ForegroundColor $Colors.Gray
  108. }
  109. } else {
  110. Write-Host "→ Key not found (will be skipped): $keyName" -ForegroundColor $Colors.Gray
  111. }
  112. }
  113. finally {
  114. if (Test-Path $tempFile) {
  115. Remove-Item -Path $tempFile -Force -ErrorAction SilentlyContinue
  116. }
  117. }
  118. }
  119. # Save consolidated backup file
  120. if ($backupCount -gt 0) {
  121. $backupContent | Out-File -FilePath $BackupFile -Encoding Unicode -Force
  122. Write-Host "✓ Registry backup completed: $BackupFile" -ForegroundColor $Colors.Success
  123. Write-Host "→ Backed up $backupCount registry sections" -ForegroundColor $Colors.Info
  124. return $true
  125. } else {
  126. Write-Host "→ No registry keys found to backup" -ForegroundColor $Colors.Warning
  127. return $false
  128. }
  129. }
  130. catch {
  131. Write-Host "✗ Failed to create backup: $_" -ForegroundColor $Colors.Error
  132. return $false
  133. }
  134. }
  135. function Restore-RegistryBackup {
  136. <#
  137. .SYNOPSIS
  138. Restores registry from backup file
  139. .PARAMETER BackupFile
  140. Path to backup file to restore from
  141. #>
  142. param([string]$BackupFile)
  143. Write-Host "`n--- Restoring Registry Backup ---" -ForegroundColor $Colors.Section
  144. if (!(Test-Path $BackupFile)) {
  145. Write-Host "✗ Backup file not found: $BackupFile" -ForegroundColor $Colors.Error
  146. return $false
  147. }
  148. try {
  149. Write-Host "→ Validating backup file format..." -ForegroundColor $Colors.Info
  150. # Validate backup file
  151. $content = Get-Content -Path $BackupFile -TotalCount 5
  152. if ($content[0] -notmatch "Windows Registry Editor") {
  153. Write-Host "✗ Invalid backup file format" -ForegroundColor $Colors.Error
  154. return $false
  155. }
  156. Write-Host "→ Importing registry backup..." -ForegroundColor $Colors.Info
  157. $process = Start-Process -FilePath "reg.exe" -ArgumentList @("import", $BackupFile) -Wait -PassThru -NoNewWindow
  158. if ($process.ExitCode -eq 0) {
  159. Write-Host "✓ Registry restored successfully from: $BackupFile" -ForegroundColor $Colors.Success
  160. Write-Host "→ Restart may be required for changes to take effect" -ForegroundColor $Colors.Warning
  161. return $true
  162. } else {
  163. Write-Host "✗ Failed to restore registry (Exit code: $($process.ExitCode))" -ForegroundColor $Colors.Error
  164. return $false
  165. }
  166. }
  167. catch {
  168. Write-Host "✗ Error restoring backup: $_" -ForegroundColor $Colors.Error
  169. return $false
  170. }
  171. }
  172. # =======================================================
  173. # ENHANCED REGISTRY FUNCTIONS
  174. # =======================================================
  175. function Set-RegistryValue {
  176. param(
  177. [string]$Path,
  178. [string]$Name,
  179. [object]$Value,
  180. [Microsoft.Win32.RegistryValueKind]$Type = [Microsoft.Win32.RegistryValueKind]::DWord
  181. )
  182. try {
  183. # Створити ключ, якщо його немає
  184. if (!(Test-Path $Path)) {
  185. New-Item -Path $Path -Force | Out-Null
  186. Write-Host "→ Created registry path: $Path" -ForegroundColor $Colors.Info
  187. }
  188. # Отримати поточне значення
  189. $current = Get-ItemProperty -Path $Path -Name $Name -ErrorAction SilentlyContinue
  190. if ($null -ne $current -and $current.$Name -eq $Value) {
  191. Write-Host "✓ $Name already set to $Value in $Path" -ForegroundColor $Colors.Success
  192. return $true
  193. }
  194. # Встановити або оновити значення
  195. Set-ItemProperty -Path $Path -Name $Name -Value $Value -Type $Type -Force
  196. Write-Host "✓ Set $Name to $Value in $Path" -ForegroundColor $Colors.Success
  197. return $true
  198. }
  199. catch {
  200. Write-Host "✗ Failed to set $Name in $Path : $_" -ForegroundColor $Colors.Error
  201. return $false
  202. }
  203. }
  204. function Remove-TelemetryDirectory {
  205. param([string]$Path)
  206. if (Test-Path $Path) {
  207. try {
  208. $itemCount = (Get-ChildItem -Path $Path -Recurse -ErrorAction SilentlyContinue | Measure-Object).Count
  209. if ($itemCount -gt 0) {
  210. Remove-Item -Path $Path -Recurse -Force -Verbose:$false -ErrorAction Stop
  211. Write-Host "✓ Removed telemetry directory: $Path ($itemCount items)" -ForegroundColor $Colors.Success
  212. } else {
  213. Write-Host "→ Telemetry directory already empty: $Path" -ForegroundColor $Colors.Info
  214. }
  215. }
  216. catch {
  217. Write-Host "✗ Failed to remove: $Path - $_" -ForegroundColor $Colors.Error
  218. }
  219. } else {
  220. Write-Host "→ Telemetry directory not found: $Path" -ForegroundColor $Colors.Gray
  221. }
  222. }
  223. function Disable-BackgroundDownloadTasks {
  224. Write-Host "→ Checking for Visual Studio BackgroundDownload scheduled tasks..." -ForegroundColor $Colors.Info
  225. try {
  226. $tasks = Get-ScheduledTask -ErrorAction SilentlyContinue | Where-Object {
  227. $_.TaskName -like "*BackgroundDownload*" -or
  228. ($_.TaskPath -like "*VisualStudio*" -and $_.TaskName -like "*BackgroundDownload*")
  229. }
  230. if ($tasks) {
  231. foreach ($task in $tasks) {
  232. Write-Host "→ Found task: $($task.TaskName) at $($task.TaskPath)" -ForegroundColor $Colors.Info
  233. if ($task.State -eq "Ready") {
  234. try {
  235. Disable-ScheduledTask -TaskName $task.TaskName -TaskPath $task.TaskPath -Confirm:$false -ErrorAction Stop
  236. Write-Host "✓ Disabled task: $($task.TaskName)" -ForegroundColor $Colors.Success
  237. }
  238. catch {
  239. Write-Host "✗ Could not disable task $($task.TaskName): $_" -ForegroundColor $Colors.Error
  240. }
  241. } else {
  242. Write-Host "✓ Task already disabled: $($task.TaskName)" -ForegroundColor $Colors.Success
  243. }
  244. }
  245. return $true
  246. } else {
  247. Write-Host "→ No Visual Studio BackgroundDownload tasks found" -ForegroundColor $Colors.Gray
  248. return $false
  249. }
  250. } catch {
  251. Write-Host "✗ Error checking scheduled tasks: $_" -ForegroundColor $Colors.Error
  252. return $false
  253. }
  254. }
  255. function Stop-BackgroundDownloadProcesses {
  256. Write-Host "→ Checking for running BackgroundDownload processes..." -ForegroundColor $Colors.Info
  257. try {
  258. $processes = Get-Process -Name "BackgroundDownload" -ErrorAction SilentlyContinue
  259. if ($processes) {
  260. foreach ($process in $processes) {
  261. try {
  262. Stop-Process -Id $process.Id -Force -ErrorAction Stop
  263. Write-Host "✓ Stopped process: BackgroundDownload.exe (PID: $($process.Id))" -ForegroundColor $Colors.Success
  264. }
  265. catch {
  266. Write-Host "✗ Could not stop process PID $($process.Id): $_" -ForegroundColor $Colors.Error
  267. }
  268. }
  269. return $true
  270. } else {
  271. Write-Host "→ No BackgroundDownload processes currently running" -ForegroundColor $Colors.Gray
  272. return $false
  273. }
  274. } catch {
  275. Write-Host "✗ Error checking processes: $_" -ForegroundColor $Colors.Error
  276. return $false
  277. }
  278. }
  279. function Remove-BackgroundDownloadTempFolders {
  280. Write-Host "→ Cleaning BackgroundDownload temporary folders..." -ForegroundColor $Colors.Info
  281. try {
  282. $tempPaths = @(
  283. "$env:TEMP",
  284. "$env:LOCALAPPDATA\Temp"
  285. )
  286. $foldersRemoved = 0
  287. foreach ($tempPath in $tempPaths) {
  288. if (Test-Path $tempPath) {
  289. $folders = Get-ChildItem -Path $tempPath -Directory -ErrorAction SilentlyContinue |
  290. Where-Object { $_.Name -match "^[a-zA-Z0-9]{8}\." }
  291. foreach ($folder in $folders) {
  292. $bgDownloadPath = Join-Path $folder.FullName "resources\app\ServiceHub\Services\Microsoft.VisualStudio.Setup.Service\BackgroundDownload.exe"
  293. if (Test-Path $bgDownloadPath) {
  294. try {
  295. Remove-Item -Path $folder.FullName -Recurse -Force -ErrorAction Stop
  296. Write-Host "✓ Removed temp folder: $($folder.Name)" -ForegroundColor $Colors.Success
  297. $foldersRemoved++
  298. }
  299. catch {
  300. Write-Host "✗ Could not remove folder $($folder.Name): $_" -ForegroundColor $Colors.Error
  301. }
  302. }
  303. }
  304. }
  305. }
  306. if ($foldersRemoved -eq 0) {
  307. Write-Host "→ No BackgroundDownload temp folders found" -ForegroundColor $Colors.Gray
  308. }
  309. return $foldersRemoved -gt 0
  310. } catch {
  311. Write-Host "✗ Error cleaning temp folders: $_" -ForegroundColor $Colors.Error
  312. return $false
  313. }
  314. }
  315. function Set-EnvironmentVariableIfNeeded {
  316. param(
  317. [string]$Name,
  318. [string]$Value,
  319. [string]$Target = 'User'
  320. )
  321. try {
  322. $currentValue = [Environment]::GetEnvironmentVariable($Name, $Target)
  323. if ($currentValue -eq $Value) {
  324. Write-Host "✓ " -NoNewline -ForegroundColor $Colors.Success
  325. Write-Host "$Name " -NoNewline -ForegroundColor $Colors.Info
  326. Write-Host "already set to " -NoNewline -ForegroundColor $Colors.White
  327. Write-Host "$Value" -ForegroundColor $Colors.Success
  328. } else {
  329. [Environment]::SetEnvironmentVariable($Name, $Value, $Target)
  330. Write-Host "✓ " -NoNewline -ForegroundColor $Colors.Success
  331. Write-Host "Set " -NoNewline -ForegroundColor $Colors.White
  332. Write-Host "$Name " -NoNewline -ForegroundColor $Colors.Info
  333. Write-Host "to " -NoNewline -ForegroundColor $Colors.White
  334. Write-Host "$Value" -ForegroundColor $Colors.Success
  335. }
  336. return $true
  337. }
  338. catch {
  339. Write-Host "✗ Failed to set environment variable $Name : $_" -ForegroundColor $Colors.Error
  340. return $false
  341. }
  342. }
  343. # =======================================================
  344. # MAIN SCRIPT LOGIC - HANDLE BACKUP/RESTORE OPERATIONS
  345. # =======================================================
  346. # Handle restore operation first
  347. if ($RestoreBackup) {
  348. $restored = Restore-RegistryBackup -BackupFile $BackupPath
  349. if ($restored) {
  350. Write-Host "`n✓ Restore operation completed successfully!" -ForegroundColor $Colors.Success
  351. Write-Host "→ Your telemetry settings have been restored from backup" -ForegroundColor $Colors.Info
  352. } else {
  353. Write-Host "`n✗ Restore operation failed!" -ForegroundColor $Colors.Error
  354. }
  355. Write-Host "`nPress Enter to exit..." -ForegroundColor $Colors.White
  356. Read-Host
  357. exit
  358. }
  359. # Handle backup creation
  360. if ($CreateBackup) {
  361. $backupCreated = New-RegistryBackup -BackupFile $BackupPath
  362. if ($backupCreated) {
  363. Write-Host "`n✓ Backup created successfully at: $BackupPath" -ForegroundColor $Colors.Success
  364. Write-Host "→ You can restore with: .\off_telemetry_ps7.ps1 -RestoreBackup -BackupPath '$BackupPath'" -ForegroundColor $Colors.Info
  365. } else {
  366. Write-Host "`n→ Backup creation completed (no existing telemetry settings found)" -ForegroundColor $Colors.Warning
  367. }
  368. Write-Host "`nOptions:" -ForegroundColor $Colors.White
  369. Write-Host "1. Continue with telemetry disable (recommended)" -ForegroundColor $Colors.Info
  370. Write-Host "2. Exit and run backup restore later" -ForegroundColor $Colors.Info
  371. $choice = Read-Host "`nContinue with telemetry disable? (y/n)"
  372. if ($choice -ne 'y' -and $choice -ne 'Y' -and $choice -ne '1') {
  373. Write-Host "Exiting. Run the script again without -CreateBackup to disable telemetry." -ForegroundColor $Colors.Info
  374. exit
  375. }
  376. Write-Host ""
  377. }
  378. # =======================================================
  379. # VISUAL STUDIO VERSIONS DETECTION AND PROCESSING
  380. # =======================================================
  381. Write-Host "--- Checking and Disabling Visual Studio Telemetry (Existing Paths Only) ---" -ForegroundColor $Colors.Section
  382. # Visual Studio versions to check
  383. $vsVersions = @{
  384. "14.0" = "Visual Studio 2015"
  385. "15.0" = "Visual Studio 2017"
  386. "16.0" = "Visual Studio 2019"
  387. "17.0" = "Visual Studio 2022"
  388. }
  389. # Track which versions are actually installed
  390. $installedVersions = @()
  391. foreach ($version in $vsVersions.Keys) {
  392. $vsName = $vsVersions[$version]
  393. Write-Host "`n--- Checking $vsName (version $version) ---" -ForegroundColor $Colors.Info
  394. $foundVersion = $false
  395. # Check 64-bit paths
  396. if ([Environment]::Is64BitOperatingSystem) {
  397. $path64 = "HKLM:\SOFTWARE\Wow6432Node\Microsoft\VSCommon\$version\SQM"
  398. Write-Host "→ " -NoNewline -ForegroundColor $Colors.Info
  399. Write-Host "Checking 64-bit path for " -NoNewline -ForegroundColor $Colors.White
  400. Write-Host "$vsName" -ForegroundColor $Colors.Info
  401. $result64 = Set-RegistryValue -Path $path64 -Name "OptIn" -Value 0
  402. if ($result64) {
  403. $foundVersion = $true
  404. }
  405. }
  406. # Check 32-bit paths
  407. $path32 = "HKLM:\SOFTWARE\Microsoft\VSCommon\$version\SQM"
  408. Write-Host "→ " -NoNewline -ForegroundColor $Colors.Info
  409. Write-Host "Checking 32-bit path for " -NoNewline -ForegroundColor $Colors.White
  410. Write-Host "$vsName" -ForegroundColor $Colors.Info
  411. $result32 = Set-RegistryValue -Path $path32 -Name "OptIn" -Value 0
  412. if ($result32) {
  413. $foundVersion = $true
  414. }
  415. # Track if this version was found
  416. if ($foundVersion) {
  417. $installedVersions += $version
  418. Write-Host "✓ Found $vsName installation" -ForegroundColor $Colors.Success
  419. }
  420. }
  421. # =======================================================
  422. # VISUAL STUDIO POLICY SETTINGS (Only if they exist)
  423. # =======================================================
  424. Write-Host "`n--- Checking Visual Studio Policy Settings ---" -ForegroundColor $Colors.Section
  425. # Base policy paths
  426. $policyBase = "HKLM:\SOFTWARE\Policies\Microsoft\VisualStudio"
  427. $feedbackPath = "$policyBase\Feedback"
  428. $sqmPath = "$policyBase\SQM"
  429. $telemetryPath = "HKCU:\Software\Microsoft\VisualStudio\Telemetry"
  430. Write-Host "→ " -NoNewline -ForegroundColor $Colors.Info
  431. Write-Host "Checking Visual Studio Policy paths..." -ForegroundColor $Colors.White
  432. # Feedback settings
  433. Set-RegistryValue -Path $feedbackPath -Name "DisableFeedbackDialog" -Value 1
  434. Set-RegistryValue -Path $feedbackPath -Name "DisableEmailInput" -Value 1
  435. Set-RegistryValue -Path $feedbackPath -Name "DisableScreenshotCapture" -Value 1
  436. # SQM and telemetry settings
  437. Set-RegistryValue -Path $sqmPath -Name "OptIn" -Value 0
  438. Set-RegistryValue -Path $telemetryPath -Name "TurnOffSwitch" -Value 1
  439. # =======================================================
  440. # ADDITIONAL VISUAL STUDIO REGISTRY PATHS
  441. # =======================================================
  442. Write-Host "`n--- Checking Additional Visual Studio Registry Paths ---" -ForegroundColor $Colors.Section
  443. # Additional paths that might exist
  444. $additionalPaths = @(
  445. "HKCU:\Software\Microsoft\VisualStudio\14.0\General",
  446. "HKCU:\Software\Microsoft\VisualStudio\15.0\General",
  447. "HKCU:\Software\Microsoft\VisualStudio\16.0\General",
  448. "HKCU:\Software\Microsoft\VisualStudio\17.0\General"
  449. )
  450. foreach ($path in $additionalPaths) {
  451. Write-Host "→ " -NoNewline -ForegroundColor $Colors.Info
  452. Write-Host "Checking additional path..." -ForegroundColor $Colors.White
  453. Set-RegistryValue -Path $path -Name "EnableSQM" -Value 0
  454. }
  455. # Check Experience Improvement Program paths
  456. $experiencePaths = @(
  457. "HKLM:\SOFTWARE\Microsoft\SQMClient",
  458. "HKLM:\SOFTWARE\Wow6432Node\Microsoft\SQMClient"
  459. )
  460. foreach ($path in $experiencePaths) {
  461. Write-Host "→ " -NoNewline -ForegroundColor $Colors.Info
  462. Write-Host "Checking SQM Client path..." -ForegroundColor $Colors.White
  463. Set-RegistryValue -Path $path -Name "CEIPEnable" -Value 0
  464. }
  465. # =======================================================
  466. # TELEMETRY DIRECTORIES CLEANUP
  467. # =======================================================
  468. Write-Host "`n--- Checking Telemetry Directories ---" -ForegroundColor $Colors.Section
  469. $telemetryDirs = @(
  470. "$env:APPDATA\vstelemetry",
  471. "$env:LOCALAPPDATA\Microsoft\VSApplicationInsights",
  472. "$env:PROGRAMDATA\Microsoft\VSApplicationInsights",
  473. "$env:TEMP\Microsoft\VSApplicationInsights",
  474. "$env:TEMP\VSFaultInfo",
  475. "$env:TEMP\VSFeedbackIntelliCodeLogs",
  476. "$env:TEMP\VSFeedbackPerfWatsonData",
  477. "$env:TEMP\VSFeedbackVSRTCLogs",
  478. "$env:TEMP\VSRemoteControl",
  479. "$env:TEMP\VSTelem",
  480. "$env:TEMP\VSTelem.Out"
  481. )
  482. foreach ($dir in $telemetryDirs) {
  483. Remove-TelemetryDirectory -Path $dir
  484. }
  485. # =======================================================
  486. # .NET AND NUGET TELEMETRY DISABLE
  487. # =======================================================
  488. Write-Host "`n--- Disabling .NET and NuGet Telemetry ---" -ForegroundColor $Colors.Section
  489. # Check and set .NET CLI telemetry
  490. Set-EnvironmentVariableIfNeeded -Name 'DOTNET_CLI_TELEMETRY_OPTOUT' -Value '1' -Target 'User'
  491. # Check and set NuGet telemetry
  492. Set-EnvironmentVariableIfNeeded -Name 'NUGET_TELEMETRY_OPTOUT' -Value 'true' -Target 'User'
  493. # =======================================================
  494. # VISUAL STUDIO STANDARD COLLECTOR SERVICE
  495. # =======================================================
  496. Write-Host "`n--- Managing VS Standard Collector Service ---" -ForegroundColor $Colors.Section
  497. $serviceName = 'VSStandardCollectorService150'
  498. $service = Get-Service -Name $serviceName -ErrorAction SilentlyContinue
  499. if ($service) {
  500. Write-Host "→ Found service: $serviceName" -ForegroundColor $Colors.Info
  501. # Check and stop service if running
  502. if ($service.Status -eq 'Running') {
  503. try {
  504. Stop-Service -Name $serviceName -Force -ErrorAction Stop
  505. Write-Host "✓ Stopped $serviceName" -ForegroundColor $Colors.Success
  506. }
  507. catch {
  508. Write-Host "✗ Could not stop $serviceName : $_" -ForegroundColor $Colors.Error
  509. }
  510. } else {
  511. Write-Host "→ Service $serviceName is already stopped (Status: $($service.Status))" -ForegroundColor $Colors.Info
  512. }
  513. # Check and disable service
  514. if ($service.StartType -eq 'Disabled') {
  515. Write-Host "✓ $serviceName already disabled" -ForegroundColor $Colors.Success
  516. } else {
  517. try {
  518. Set-Service -Name $serviceName -StartupType Disabled -Confirm:$false -ErrorAction Stop
  519. Write-Host "✓ Disabled $serviceName" -ForegroundColor $Colors.Success
  520. }
  521. catch {
  522. Write-Host "✗ Could not disable $serviceName : $_" -ForegroundColor $Colors.Error
  523. }
  524. }
  525. } else {
  526. Write-Host "→ $serviceName not found (already removed or not installed)" -ForegroundColor $Colors.Gray
  527. }
  528. # =======================================================
  529. # VISUAL STUDIO CODE SETTINGS
  530. # =======================================================
  531. Write-Host "`n--- Configuring Visual Studio Code Settings ---" -ForegroundColor $Colors.Section
  532. $vscodeSettings = "$env:APPDATA\Code\User\settings.json"
  533. $vscodeUserDir = "$env:APPDATA\Code\User"
  534. $vscodeDetected = $false
  535. if (!(Test-Path "$env:APPDATA\Code")) {
  536. Write-Host "→ Visual Studio Code not detected" -ForegroundColor $Colors.Gray
  537. } else {
  538. Write-Host "→ Visual Studio Code detected" -ForegroundColor $Colors.Info
  539. $vscodeDetected = $true
  540. # Create User directory if needed
  541. if (!(Test-Path $vscodeUserDir)) {
  542. try {
  543. $null = New-Item -Path $vscodeUserDir -ItemType Directory -Force
  544. Write-Host "→ Created VS Code User directory" -ForegroundColor $Colors.Info
  545. } catch {
  546. Write-Host "✗ Failed to create VS Code User directory: $_" -ForegroundColor $Colors.Error
  547. }
  548. }
  549. # Privacy settings
  550. $privacyConfig = @{
  551. "telemetry.enableTelemetry" = $false
  552. "telemetry.enableCrashReporter" = $false
  553. "workbench.enableExperiments" = $false
  554. "update.mode" = "manual"
  555. "update.showReleaseNotes" = $false
  556. "extensions.autoCheckUpdates" = $false
  557. "extensions.showRecommendationsOnlyOnDemand" = $true
  558. "git.autofetch" = $false
  559. "npm.fetchOnlinePackageInfo" = $false
  560. }
  561. try {
  562. # Load existing settings
  563. $settings = @{}
  564. if (Test-Path $vscodeSettings) {
  565. $content = Get-Content $vscodeSettings -Raw -ErrorAction SilentlyContinue
  566. if ($content -and $content.Trim()) {
  567. try {
  568. # Use PowerShell's built-in JSON cmdlets
  569. $settingsObj = $content | ConvertFrom-Json
  570. # Convert PSCustomObject to hashtable for easier manipulation
  571. $settings = @{}
  572. $settingsObj.PSObject.Properties | ForEach-Object {
  573. $settings[$_.Name] = $_.Value
  574. }
  575. Write-Host "→ Found existing VS Code settings file" -ForegroundColor $Colors.Info
  576. }
  577. catch {
  578. Write-Host "→ Could not parse existing settings, creating new ones" -ForegroundColor $Colors.Warning
  579. $settings = @{}
  580. }
  581. }
  582. }
  583. # Update settings
  584. $changesMade = $false
  585. foreach ($key in $privacyConfig.Keys) {
  586. $value = $privacyConfig[$key]
  587. if ($settings.ContainsKey($key) -and $settings[$key] -eq $value) {
  588. Write-Host "✓ " -NoNewline -ForegroundColor $Colors.Success
  589. Write-Host "$key " -NoNewline -ForegroundColor $Colors.Info
  590. Write-Host "already set to " -NoNewline -ForegroundColor $Colors.White
  591. Write-Host "$value" -ForegroundColor $Colors.Success
  592. } else {
  593. $settings[$key] = $value
  594. Write-Host "✓ " -NoNewline -ForegroundColor $Colors.Success
  595. Write-Host "Updated " -NoNewline -ForegroundColor $Colors.White
  596. Write-Host "$key " -NoNewline -ForegroundColor $Colors.Info
  597. Write-Host "to " -NoNewline -ForegroundColor $Colors.White
  598. Write-Host "$value" -ForegroundColor $Colors.Success
  599. $changesMade = $true
  600. }
  601. }
  602. # Save settings if changes were made
  603. if ($changesMade -or !(Test-Path $vscodeSettings)) {
  604. $json = $settings | ConvertTo-Json -Depth 10
  605. $json | Out-File -FilePath $vscodeSettings -Encoding UTF8
  606. Write-Host "✓ Saved VS Code privacy settings" -ForegroundColor $Colors.Success
  607. } else {
  608. Write-Host "→ No changes needed for VS Code settings" -ForegroundColor $Colors.Info
  609. }
  610. }
  611. catch {
  612. Write-Host "✗ Failed to update VS Code settings: $_" -ForegroundColor $Colors.Error
  613. }
  614. }
  615. # =======================================================
  616. # VISUAL STUDIO BACKGROUND DOWNLOAD DISABLE
  617. # =======================================================
  618. Write-Host "`n--- Disabling Visual Studio Background Download ---" -ForegroundColor $Colors.Section
  619. $backgroundDownloadProcessed = $false
  620. # Check if any Visual Studio versions are installed before proceeding
  621. if ($installedVersions.Count -gt 0) {
  622. Write-Host "→ Visual Studio detected, processing BackgroundDownload settings..." -ForegroundColor $Colors.Info
  623. # 1. Disable scheduled tasks
  624. $tasksProcessed = Disable-BackgroundDownloadTasks
  625. # 2. Set registry keys to disable background downloads
  626. Write-Host "→ Setting registry keys to disable background downloads..." -ForegroundColor $Colors.Info
  627. $regPaths = @(
  628. "HKLM:\SOFTWARE\Microsoft\VisualStudio\Setup",
  629. "HKLM:\SOFTWARE\Wow6432Node\Microsoft\VisualStudio\Setup"
  630. )
  631. $regKeysSet = $false
  632. foreach ($regPath in $regPaths) {
  633. # Check if this registry path should exist (based on architecture)
  634. $shouldProcess = $true
  635. if ($regPath -like "*Wow6432Node*" -and ![Environment]::Is64BitOperatingSystem) {
  636. $shouldProcess = $false
  637. }
  638. if ($shouldProcess) {
  639. # Create the registry path if it doesn't exist (since we're configuring VS Setup)
  640. if (!(Test-Path $regPath)) {
  641. try {
  642. $null = New-Item -Path $regPath -Force -ErrorAction Stop
  643. Write-Host "→ Created registry path: $regPath" -ForegroundColor $Colors.Info
  644. }
  645. catch {
  646. Write-Host "✗ Could not create registry path $regPath : $_" -ForegroundColor $Colors.Error
  647. continue
  648. }
  649. }
  650. # Set the registry values
  651. $regSettings = @{
  652. "BackgroundDownloadDisabled" = 1
  653. "DisableBackgroundDownloads" = 1
  654. "DisableAutomaticUpdates" = 1
  655. }
  656. foreach ($setting in $regSettings.GetEnumerator()) {
  657. $success = Set-RegistryValue -Path $regPath -Name $setting.Key -Value $setting.Value -Type 'DWord'
  658. if ($success) {
  659. $regKeysSet = $true
  660. }
  661. }
  662. }
  663. }
  664. # 3. Stop running processes
  665. $processesProcessed = Stop-BackgroundDownloadProcesses
  666. # 4. Clean temporary folders
  667. $tempFoldersProcessed = Remove-BackgroundDownloadTempFolders
  668. # 5. Verification
  669. Write-Host "→ Verifying BackgroundDownload configuration..." -ForegroundColor $Colors.Info
  670. try {
  671. $verificationSuccess = $false
  672. # Check registry settings
  673. foreach ($regPath in $regPaths) {
  674. if (Test-Path $regPath) {
  675. $regValues = Get-ItemProperty -Path $regPath -ErrorAction SilentlyContinue
  676. if ($regValues -and $regValues.BackgroundDownloadDisabled -eq 1) {
  677. Write-Host "✓ Registry verification: BackgroundDownloadDisabled = 1 in $regPath" -ForegroundColor $Colors.Success
  678. $verificationSuccess = $true
  679. }
  680. }
  681. }
  682. if (!$verificationSuccess) {
  683. Write-Host "→ Could not verify registry settings" -ForegroundColor $Colors.Warning
  684. }
  685. } catch {
  686. Write-Host "→ Verification error: $_" -ForegroundColor $Colors.Warning
  687. }
  688. # Set processed flag if any operation was successful
  689. $backgroundDownloadProcessed = $tasksProcessed -or $regKeysSet -or $processesProcessed -or $tempFoldersProcessed
  690. } else {
  691. Write-Host "→ No Visual Studio installations detected, skipping BackgroundDownload configuration" -ForegroundColor $Colors.Gray
  692. }
  693. # =======================================================
  694. # ADDITIONAL POWERSHELL 7 TELEMETRY CHECKS
  695. # =======================================================
  696. Write-Host "`n--- PowerShell 7 Telemetry Checks ---" -ForegroundColor $Colors.Section
  697. # Check if PowerShell telemetry is disabled
  698. try {
  699. $psDataCollection = [Microsoft.PowerShell.Telemetry.ApplicationInsightsTelemetry]::Enabled -eq $false
  700. if ($psDataCollection) {
  701. Write-Host "✓ PowerShell telemetry already disabled" -ForegroundColor $Colors.Success
  702. } else {
  703. Write-Host "→ PowerShell telemetry status:" -ForegroundColor $Colors.Info
  704. }
  705. } catch {
  706. Write-Host "→ Could not check PowerShell telemetry status" -ForegroundColor $Colors.Gray
  707. }
  708. # Check PowerShell environment variables
  709. Set-EnvironmentVariableIfNeeded -Name 'POWERSHELL_TELEMETRY_OPTOUT' -Value '1' -Target 'User'
  710. # =======================================================
  711. # SUMMARY
  712. # =======================================================
  713. Write-Host "`n========================================" -ForegroundColor $Colors.Title
  714. Write-Host "TELEMETRY DISABLE COMPLETE" -ForegroundColor $Colors.Title
  715. Write-Host "========================================" -ForegroundColor $Colors.Title
  716. Write-Host "`nProcessed telemetry settings for:" -ForegroundColor $Colors.White
  717. # Visual Studio versions with status colors
  718. if ($installedVersions.Count -gt 0) {
  719. foreach ($version in $installedVersions) {
  720. Write-Host "✓ " -NoNewline -ForegroundColor $Colors.Success
  721. Write-Host "$($vsVersions[$version]) " -NoNewline -ForegroundColor $Colors.Info
  722. Write-Host "(detected and processed)" -ForegroundColor $Colors.Success
  723. }
  724. } else {
  725. Write-Host "→ " -NoNewline -ForegroundColor $Colors.Gray
  726. Write-Host "No Visual Studio versions detected" -ForegroundColor $Colors.Gray
  727. }
  728. # Visual Studio Code with status colors
  729. if ($vscodeDetected) {
  730. Write-Host "✓ " -NoNewline -ForegroundColor $Colors.Success
  731. Write-Host "Visual Studio Code " -NoNewline -ForegroundColor $Colors.Info
  732. Write-Host "(detected and configured)" -ForegroundColor $Colors.Success
  733. } else {
  734. Write-Host "→ " -NoNewline -ForegroundColor $Colors.Gray
  735. Write-Host "Visual Studio Code " -NoNewline -ForegroundColor $Colors.Info
  736. Write-Host "(not found)" -ForegroundColor $Colors.Gray
  737. }
  738. # .NET CLI status
  739. Write-Host "✓ " -NoNewline -ForegroundColor $Colors.Success
  740. Write-Host ".NET CLI " -NoNewline -ForegroundColor $Colors.Info
  741. Write-Host "(telemetry disabled)" -ForegroundColor $Colors.Success
  742. # NuGet status
  743. Write-Host "✓ " -NoNewline -ForegroundColor $Colors.Success
  744. Write-Host "NuGet " -NoNewline -ForegroundColor $Colors.Info
  745. Write-Host "(telemetry disabled)" -ForegroundColor $Colors.Success
  746. # VS Standard Collector Service status
  747. if ($null -ne $service) {
  748. Write-Host "✓ " -NoNewline -ForegroundColor $Colors.Success
  749. Write-Host "VS Standard Collector Service " -NoNewline -ForegroundColor $Colors.Info
  750. Write-Host "(processed)" -ForegroundColor $Colors.Success
  751. } else {
  752. Write-Host "→ " -NoNewline -ForegroundColor $Colors.Gray
  753. Write-Host "VS Standard Collector Service " -NoNewline -ForegroundColor $Colors.Info
  754. Write-Host "(not found)" -ForegroundColor $Colors.Gray
  755. }
  756. # PowerShell 7 status
  757. $psTelemetryOptOut = [Environment]::GetEnvironmentVariable('POWERSHELL_TELEMETRY_OPTOUT', 'User')
  758. if ($psTelemetryOptOut -eq '1') {
  759. Write-Host "✓ " -NoNewline -ForegroundColor $Colors.Success
  760. Write-Host "PowerShell 7 telemetry " -NoNewline -ForegroundColor $Colors.Info
  761. Write-Host "(opt-out configured via environment variable)" -ForegroundColor $Colors.Success
  762. } else {
  763. Write-Host "→ " -NoNewline -ForegroundColor $Colors.Gray
  764. Write-Host "PowerShell 7 telemetry " -NoNewline -ForegroundColor $Colors.Info
  765. Write-Host "(opt-out not configured; current value: $($psTelemetryOptOut ?? 'not set'))" -ForegroundColor $Colors.Gray
  766. }
  767. # Visual Studio Background Download status
  768. if ($backgroundDownloadProcessed) {
  769. Write-Host "✓ " -NoNewline -ForegroundColor $Colors.Success
  770. Write-Host "Visual Studio Background Download " -NoNewline -ForegroundColor $Colors.Info
  771. Write-Host "(disabled)" -ForegroundColor $Colors.Success
  772. } else {
  773. Write-Host "→ " -NoNewline -ForegroundColor $Colors.Gray
  774. Write-Host "Visual Studio Background Download " -NoNewline -ForegroundColor $Colors.Info
  775. Write-Host "(not processed)" -ForegroundColor $Colors.Gray
  776. }
  777. # Customer Experience Improvement Program status
  778. $experienceDisabled = $true
  779. foreach ($path in $experiencePaths) {
  780. $value = Get-ItemProperty -Path $path -Name "CEIPEnable" -ErrorAction SilentlyContinue
  781. if ($value -and $value.CEIPEnable -ne 0) {
  782. $experienceDisabled = $false
  783. break
  784. }
  785. }
  786. if ($experienceDisabled) {
  787. Write-Host "✓ " -NoNewline -ForegroundColor $Colors.Success
  788. Write-Host "Customer Experience Improvement Program " -NoNewline -ForegroundColor $Colors.Info
  789. Write-Host "(disabled)" -ForegroundColor $Colors.Success
  790. } else {
  791. Write-Host "→ " -NoNewline -ForegroundColor $Colors.Gray
  792. Write-Host "Customer Experience Improvement Program " -NoNewline -ForegroundColor $Colors.Info
  793. Write-Host "(not fully disabled)" -ForegroundColor $Colors.Gray
  794. }
  795. # Telemetry Directories Cleanup status
  796. Write-Host "✓ " -NoNewline -ForegroundColor $Colors.Success
  797. Write-Host "Telemetry Directories Cleanup " -NoNewline -ForegroundColor $Colors.Info
  798. Write-Host "(processed)" -ForegroundColor $Colors.Success
  799. # =======================================================
  800. # ADDITIONAL FEATURES AND ENVIRONMENT VARIABLES
  801. # =======================================================
  802. Write-Host "`n--- Optional: Additional Features and Environment Variables ---" -ForegroundColor $Colors.Section
  803. # Only offer extra tweaks if at least one VS version is installed
  804. if ($installedVersions.Count -eq 0) {
  805. Write-Host "→ No Visual Studio installations detected – skipping additional configuration" -ForegroundColor $Colors.Gray
  806. }
  807. else {
  808. Write-Host "This will perform additional configuration:" -ForegroundColor $Colors.Info
  809. Write-Host "• Disable Visual Studio Settings Synchronization" -ForegroundColor $Colors.Info
  810. Write-Host "• Disable Live Share" -ForegroundColor $Colors.Info
  811. Write-Host "• Disable IntelliCode" -ForegroundColor $Colors.Info
  812. Write-Host "• Disable CodeLens" -ForegroundColor $Colors.Info
  813. Write-Host "• Set additional environment variables:" -ForegroundColor $Colors.Info
  814. Write-Host " - INTELLICODE_TELEMETRY_OPTOUT" -ForegroundColor $Colors.Info
  815. Write-Host " - LIVESHARE_TELEMETRY_OPTOUT" -ForegroundColor $Colors.Info
  816. Write-Host " - VSSDK_TELEMETRY_OPTOUT" -ForegroundColor $Colors.Info
  817. $enableAdditional = Read-Host "`nEnable additional configuration? (y/n)"
  818. if ($enableAdditional -match '^y(es)?$') {
  819. # === Disabling Additional Visual Studio Features ===
  820. Write-Host "`n--- Disabling Additional Visual Studio Features ---" -ForegroundColor $Colors.Section
  821. foreach ($version in $installedVersions) {
  822. $vsName = $vsVersions[$version]
  823. Write-Host "`n--- Processing Additional Features for $vsName (version $version) ---" -ForegroundColor $Colors.Info
  824. # Settings Sync
  825. $settingsPaths = @(
  826. "HKCU:\Software\Microsoft\VisualStudio\$version\Settings",
  827. "HKCU:\Software\Microsoft\VisualStudio\$version\ApplicationPrivateSettings\Microsoft\VisualStudio\Settings"
  828. )
  829. foreach ($path in $settingsPaths) {
  830. Set-RegistryValue -Path $path -Name "SyncSettings" -Value 0
  831. Set-RegistryValue -Path $path -Name "EnableRoaming" -Value 0
  832. Set-RegistryValue -Path $path -Name "EnableSync" -Value 0
  833. Set-RegistryValue -Path $path -Name "DisableSync" -Value 1
  834. }
  835. # Live Share
  836. $liveSharePaths = @(
  837. "HKCU:\Software\Microsoft\VisualStudio\$version\LiveShare",
  838. "HKCU:\Software\Microsoft\VisualStudio\$version\ApplicationPrivateSettings\Microsoft\VisualStudio\LiveShare"
  839. )
  840. foreach ($path in $liveSharePaths) {
  841. Set-RegistryValue -Path $path -Name "Enabled" -Value 0
  842. Set-RegistryValue -Path $path -Name "EnableTelemetry" -Value 0
  843. Set-RegistryValue -Path $path -Name "DisableTelemetry" -Value 1
  844. Set-RegistryValue -Path $path -Name "OptedIn" -Value 0
  845. }
  846. # IntelliCode
  847. $intelliCodePaths = @(
  848. "HKCU:\Software\Microsoft\VisualStudio\$version\IntelliCode",
  849. "HKCU:\Software\Microsoft\VisualStudio\$version\IntelliSense\IntelliCode",
  850. "HKCU:\Software\Microsoft\VisualStudio\$version\ApplicationPrivateSettings\Microsoft\VisualStudio\IntelliCode"
  851. )
  852. foreach ($path in $intelliCodePaths) {
  853. Set-RegistryValue -Path $path -Name "DisableTelemetry" -Value 1
  854. Set-RegistryValue -Path $path -Name "EnableTelemetry" -Value 0
  855. Set-RegistryValue -Path $path -Name "OptedIn" -Value 0
  856. Set-RegistryValue -Path $path -Name "Enabled" -Value 0
  857. Set-RegistryValue -Path $path -Name "ModelDownloadEnabled" -Value 0
  858. }
  859. # CodeLens
  860. $codeLensPaths = @(
  861. "HKCU:\Software\Microsoft\VisualStudio\$version\CodeLens",
  862. "HKCU:\Software\Microsoft\VisualStudio\$version\TextEditor\CodeLens",
  863. "HKCU:\Software\Microsoft\VisualStudio\$version\ApplicationPrivateSettings\Microsoft\VisualStudio\CodeLens"
  864. )
  865. foreach ($path in $codeLensPaths) {
  866. Set-RegistryValue -Path $path -Name "Disabled" -Value 1
  867. Set-RegistryValue -Path $path -Name "ShowAuthorCodeLens" -Value 0
  868. Set-RegistryValue -Path $path -Name "ShowReferencesCodeLens" -Value 0
  869. Set-RegistryValue -Path $path -Name "ShowTestCodeLens" -Value 0
  870. Set-RegistryValue -Path $path -Name "Enabled" -Value 0
  871. }
  872. }
  873. # Additional environment variables
  874. Write-Host "`n--- Setting Additional Environment Variables ---" -ForegroundColor $Colors.Section
  875. Set-EnvironmentVariableIfNeeded -Name 'INTELLICODE_TELEMETRY_OPTOUT' -Value '1' -Target 'User'
  876. Set-EnvironmentVariableIfNeeded -Name 'LIVESHARE_TELEMETRY_OPTOUT' -Value '1' -Target 'User'
  877. Set-EnvironmentVariableIfNeeded -Name 'VSSDK_TELEMETRY_OPTOUT' -Value '1' -Target 'User'
  878. Write-Host "`n✓ Additional configuration completed" -ForegroundColor $Colors.Success
  879. }
  880. else {
  881. Write-Host "→ Skipping additional configuration" -ForegroundColor $Colors.Info
  882. }
  883. }
  884. Write-Host "`nLegend:" -ForegroundColor $Colors.White
  885. Write-Host "✓ " -NoNewline -ForegroundColor $Colors.Success; Write-Host "Action completed successfully" -ForegroundColor $Colors.Gray
  886. Write-Host "→ " -NoNewline -ForegroundColor $Colors.Info; Write-Host "Information or preparatory action" -ForegroundColor $Colors.Gray
  887. Write-Host "→ " -NoNewline -ForegroundColor $Colors.Gray; Write-Host "Component not found or not processed" -ForegroundColor $Colors.Gray
  888. Write-Host "✗ " -NoNewline -ForegroundColor $Colors.Error; Write-Host "Error occurred" -ForegroundColor $Colors.Gray
  889. Write-Host "`nUsage Examples:" -ForegroundColor $Colors.White
  890. Write-Host "→ " -NoNewline -ForegroundColor $Colors.Info
  891. Write-Host "Create backup first: " -NoNewline -ForegroundColor $Colors.White
  892. Write-Host ".\off_telemetry_ps7.ps1 -CreateBackup" -ForegroundColor $Colors.Info
  893. Write-Host "→ " -NoNewline -ForegroundColor $Colors.Info
  894. Write-Host "Restore from backup: " -NoNewline -ForegroundColor $Colors.White
  895. Write-Host ".\off_telemetry_ps7.ps1 -RestoreBackup -BackupPath 'path\to\backup.reg'" -ForegroundColor $Colors.Info
  896. Write-Host "→ " -NoNewline -ForegroundColor $Colors.Info
  897. Write-Host "Run without backup: " -NoNewline -ForegroundColor $Colors.White
  898. Write-Host ".\off_telemetry_ps7.ps1" -ForegroundColor $Colors.Info
  899. if (!$CreateBackup) {
  900. Write-Host "`n⚠ " -NoNewline -ForegroundColor $Colors.Warning
  901. Write-Host "Tip: Run with -CreateBackup parameter to create registry backup first" -ForegroundColor $Colors.Warning
  902. }
  903. Write-Host "`n⚠ " -NoNewline -ForegroundColor $Colors.Warning
  904. Write-Host "Restart may be required for all changes to take effect." -ForegroundColor $Colors.Warning
  905. Write-Host "`nPress Enter to exit..." -ForegroundColor $Colors.White
  906. $null = Read-Host