off_telemetry_ps7.ps1 46 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079
  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. if (!(Test-Path $Path)) {
  184. Write-Host "Registry path not found, skipping: $Path" -ForegroundColor $Colors.Gray
  185. return $false
  186. }
  187. $currentValue = Get-ItemProperty -Path $Path -Name $Name -ErrorAction SilentlyContinue
  188. if ($null -ne $currentValue -and $currentValue.$Name -eq $Value) {
  189. Write-Host "✓ $Name already set to $Value in $Path" -ForegroundColor $Colors.Success
  190. return $true
  191. }
  192. $null = Set-ItemProperty -Path $Path -Name $Name -Value $Value -Type $Type -Force -ErrorAction Stop
  193. Write-Host "✓ Set $Name to $Value in $Path" -ForegroundColor $Colors.Success
  194. return $true
  195. }
  196. catch {
  197. Write-Host "✗ Failed to set $Name in $Path : $_" -ForegroundColor $Colors.Error
  198. return $false
  199. }
  200. }
  201. function Remove-TelemetryDirectory {
  202. param([string]$Path)
  203. if (Test-Path $Path) {
  204. try {
  205. $itemCount = (Get-ChildItem -Path $Path -Recurse -ErrorAction SilentlyContinue | Measure-Object).Count
  206. if ($itemCount -gt 0) {
  207. Remove-Item -Path $Path -Recurse -Force -Verbose:$false -ErrorAction Stop
  208. Write-Host "✓ Removed telemetry directory: $Path ($itemCount items)" -ForegroundColor $Colors.Success
  209. } else {
  210. Write-Host "→ Telemetry directory already empty: $Path" -ForegroundColor $Colors.Info
  211. }
  212. }
  213. catch {
  214. Write-Host "✗ Failed to remove: $Path - $_" -ForegroundColor $Colors.Error
  215. }
  216. } else {
  217. Write-Host "→ Telemetry directory not found: $Path" -ForegroundColor $Colors.Gray
  218. }
  219. }
  220. function Disable-BackgroundDownloadTasks {
  221. Write-Host "→ Checking for Visual Studio BackgroundDownload scheduled tasks..." -ForegroundColor $Colors.Info
  222. try {
  223. $tasks = Get-ScheduledTask -ErrorAction SilentlyContinue | Where-Object {
  224. $_.TaskName -like "*BackgroundDownload*" -or
  225. ($_.TaskPath -like "*VisualStudio*" -and $_.TaskName -like "*BackgroundDownload*")
  226. }
  227. if ($tasks) {
  228. foreach ($task in $tasks) {
  229. Write-Host "→ Found task: $($task.TaskName) at $($task.TaskPath)" -ForegroundColor $Colors.Info
  230. if ($task.State -eq "Ready") {
  231. try {
  232. Disable-ScheduledTask -TaskName $task.TaskName -TaskPath $task.TaskPath -Confirm:$false -ErrorAction Stop
  233. Write-Host "✓ Disabled task: $($task.TaskName)" -ForegroundColor $Colors.Success
  234. }
  235. catch {
  236. Write-Host "✗ Could not disable task $($task.TaskName): $_" -ForegroundColor $Colors.Error
  237. }
  238. } else {
  239. Write-Host "✓ Task already disabled: $($task.TaskName)" -ForegroundColor $Colors.Success
  240. }
  241. }
  242. return $true
  243. } else {
  244. Write-Host "→ No Visual Studio BackgroundDownload tasks found" -ForegroundColor $Colors.Gray
  245. return $false
  246. }
  247. } catch {
  248. Write-Host "✗ Error checking scheduled tasks: $_" -ForegroundColor $Colors.Error
  249. return $false
  250. }
  251. }
  252. function Stop-BackgroundDownloadProcesses {
  253. Write-Host "→ Checking for running BackgroundDownload processes..." -ForegroundColor $Colors.Info
  254. try {
  255. $processes = Get-Process -Name "BackgroundDownload" -ErrorAction SilentlyContinue
  256. if ($processes) {
  257. foreach ($process in $processes) {
  258. try {
  259. Stop-Process -Id $process.Id -Force -ErrorAction Stop
  260. Write-Host "✓ Stopped process: BackgroundDownload.exe (PID: $($process.Id))" -ForegroundColor $Colors.Success
  261. }
  262. catch {
  263. Write-Host "✗ Could not stop process PID $($process.Id): $_" -ForegroundColor $Colors.Error
  264. }
  265. }
  266. return $true
  267. } else {
  268. Write-Host "→ No BackgroundDownload processes currently running" -ForegroundColor $Colors.Gray
  269. return $false
  270. }
  271. } catch {
  272. Write-Host "✗ Error checking processes: $_" -ForegroundColor $Colors.Error
  273. return $false
  274. }
  275. }
  276. function Remove-BackgroundDownloadTempFolders {
  277. Write-Host "→ Cleaning BackgroundDownload temporary folders..." -ForegroundColor $Colors.Info
  278. try {
  279. $tempPaths = @(
  280. "$env:TEMP",
  281. "$env:LOCALAPPDATA\Temp"
  282. )
  283. $foldersRemoved = 0
  284. foreach ($tempPath in $tempPaths) {
  285. if (Test-Path $tempPath) {
  286. $folders = Get-ChildItem -Path $tempPath -Directory -ErrorAction SilentlyContinue |
  287. Where-Object { $_.Name -match "^[a-zA-Z0-9]{8}\." }
  288. foreach ($folder in $folders) {
  289. $bgDownloadPath = Join-Path $folder.FullName "resources\app\ServiceHub\Services\Microsoft.VisualStudio.Setup.Service\BackgroundDownload.exe"
  290. if (Test-Path $bgDownloadPath) {
  291. try {
  292. Remove-Item -Path $folder.FullName -Recurse -Force -ErrorAction Stop
  293. Write-Host "✓ Removed temp folder: $($folder.Name)" -ForegroundColor $Colors.Success
  294. $foldersRemoved++
  295. }
  296. catch {
  297. Write-Host "✗ Could not remove folder $($folder.Name): $_" -ForegroundColor $Colors.Error
  298. }
  299. }
  300. }
  301. }
  302. }
  303. if ($foldersRemoved -eq 0) {
  304. Write-Host "→ No BackgroundDownload temp folders found" -ForegroundColor $Colors.Gray
  305. }
  306. return $foldersRemoved -gt 0
  307. } catch {
  308. Write-Host "✗ Error cleaning temp folders: $_" -ForegroundColor $Colors.Error
  309. return $false
  310. }
  311. }
  312. function Set-EnvironmentVariableIfNeeded {
  313. param(
  314. [string]$Name,
  315. [string]$Value,
  316. [string]$Target = 'User'
  317. )
  318. try {
  319. $currentValue = [Environment]::GetEnvironmentVariable($Name, $Target)
  320. if ($currentValue -eq $Value) {
  321. Write-Host "✓ " -NoNewline -ForegroundColor $Colors.Success
  322. Write-Host "$Name " -NoNewline -ForegroundColor $Colors.Info
  323. Write-Host "already set to " -NoNewline -ForegroundColor $Colors.White
  324. Write-Host "$Value" -ForegroundColor $Colors.Success
  325. } else {
  326. [Environment]::SetEnvironmentVariable($Name, $Value, $Target)
  327. Write-Host "✓ " -NoNewline -ForegroundColor $Colors.Success
  328. Write-Host "Set " -NoNewline -ForegroundColor $Colors.White
  329. Write-Host "$Name " -NoNewline -ForegroundColor $Colors.Info
  330. Write-Host "to " -NoNewline -ForegroundColor $Colors.White
  331. Write-Host "$Value" -ForegroundColor $Colors.Success
  332. }
  333. return $true
  334. }
  335. catch {
  336. Write-Host "✗ Failed to set environment variable $Name : $_" -ForegroundColor $Colors.Error
  337. return $false
  338. }
  339. }
  340. # =======================================================
  341. # MAIN SCRIPT LOGIC - HANDLE BACKUP/RESTORE OPERATIONS
  342. # =======================================================
  343. # Handle restore operation first
  344. if ($RestoreBackup) {
  345. $restored = Restore-RegistryBackup -BackupFile $BackupPath
  346. if ($restored) {
  347. Write-Host "`n✓ Restore operation completed successfully!" -ForegroundColor $Colors.Success
  348. Write-Host "→ Your telemetry settings have been restored from backup" -ForegroundColor $Colors.Info
  349. } else {
  350. Write-Host "`n✗ Restore operation failed!" -ForegroundColor $Colors.Error
  351. }
  352. Write-Host "`nPress Enter to exit..." -ForegroundColor $Colors.White
  353. Read-Host
  354. exit
  355. }
  356. # Handle backup creation
  357. if ($CreateBackup) {
  358. $backupCreated = New-RegistryBackup -BackupFile $BackupPath
  359. if ($backupCreated) {
  360. Write-Host "`n✓ Backup created successfully at: $BackupPath" -ForegroundColor $Colors.Success
  361. Write-Host "→ You can restore with: .\off_telemetry_ps7.ps1 -RestoreBackup -BackupPath '$BackupPath'" -ForegroundColor $Colors.Info
  362. } else {
  363. Write-Host "`n→ Backup creation completed (no existing telemetry settings found)" -ForegroundColor $Colors.Warning
  364. }
  365. Write-Host "`nOptions:" -ForegroundColor $Colors.White
  366. Write-Host "1. Continue with telemetry disable (recommended)" -ForegroundColor $Colors.Info
  367. Write-Host "2. Exit and run backup restore later" -ForegroundColor $Colors.Info
  368. $choice = Read-Host "`nContinue with telemetry disable? (y/n)"
  369. if ($choice -ne 'y' -and $choice -ne 'Y' -and $choice -ne '1') {
  370. Write-Host "Exiting. Run the script again without -CreateBackup to disable telemetry." -ForegroundColor $Colors.Info
  371. exit
  372. }
  373. Write-Host ""
  374. }
  375. # =======================================================
  376. # VISUAL STUDIO VERSIONS DETECTION AND PROCESSING
  377. # =======================================================
  378. Write-Host "--- Checking and Disabling Visual Studio Telemetry (Existing Paths Only) ---" -ForegroundColor $Colors.Section
  379. # Visual Studio versions to check
  380. $vsVersions = @{
  381. "14.0" = "Visual Studio 2015"
  382. "15.0" = "Visual Studio 2017"
  383. "16.0" = "Visual Studio 2019"
  384. "17.0" = "Visual Studio 2022"
  385. }
  386. # Track which versions are actually installed
  387. $installedVersions = @()
  388. foreach ($version in $vsVersions.Keys) {
  389. $vsName = $vsVersions[$version]
  390. Write-Host "`n--- Checking $vsName (version $version) ---" -ForegroundColor $Colors.Info
  391. $foundVersion = $false
  392. # Check 64-bit paths
  393. if ([Environment]::Is64BitOperatingSystem) {
  394. $path64 = "HKLM:\SOFTWARE\Wow6432Node\Microsoft\VSCommon\$version\SQM"
  395. Write-Host "→ " -NoNewline -ForegroundColor $Colors.Info
  396. Write-Host "Checking 64-bit path for " -NoNewline -ForegroundColor $Colors.White
  397. Write-Host "$vsName" -ForegroundColor $Colors.Info
  398. $result64 = Set-RegistryValue -Path $path64 -Name "OptIn" -Value 0
  399. if ($result64) {
  400. $foundVersion = $true
  401. }
  402. }
  403. # Check 32-bit paths
  404. $path32 = "HKLM:\SOFTWARE\Microsoft\VSCommon\$version\SQM"
  405. Write-Host "→ " -NoNewline -ForegroundColor $Colors.Info
  406. Write-Host "Checking 32-bit path for " -NoNewline -ForegroundColor $Colors.White
  407. Write-Host "$vsName" -ForegroundColor $Colors.Info
  408. $result32 = Set-RegistryValue -Path $path32 -Name "OptIn" -Value 0
  409. if ($result32) {
  410. $foundVersion = $true
  411. }
  412. # Track if this version was found
  413. if ($foundVersion) {
  414. $installedVersions += $version
  415. Write-Host "✓ Found $vsName installation" -ForegroundColor $Colors.Success
  416. }
  417. }
  418. # =======================================================
  419. # VISUAL STUDIO POLICY SETTINGS (Only if they exist)
  420. # =======================================================
  421. Write-Host "`n--- Checking Visual Studio Policy Settings ---" -ForegroundColor $Colors.Section
  422. # Base policy paths
  423. $policyBase = "HKLM:\SOFTWARE\Policies\Microsoft\VisualStudio"
  424. $feedbackPath = "$policyBase\Feedback"
  425. $sqmPath = "$policyBase\SQM"
  426. $telemetryPath = "HKCU:\Software\Microsoft\VisualStudio\Telemetry"
  427. Write-Host "→ " -NoNewline -ForegroundColor $Colors.Info
  428. Write-Host "Checking Visual Studio Policy paths..." -ForegroundColor $Colors.White
  429. # Feedback settings
  430. Set-RegistryValue -Path $feedbackPath -Name "DisableFeedbackDialog" -Value 1
  431. Set-RegistryValue -Path $feedbackPath -Name "DisableEmailInput" -Value 1
  432. Set-RegistryValue -Path $feedbackPath -Name "DisableScreenshotCapture" -Value 1
  433. # SQM and telemetry settings
  434. Set-RegistryValue -Path $sqmPath -Name "OptIn" -Value 0
  435. Set-RegistryValue -Path $telemetryPath -Name "TurnOffSwitch" -Value 1
  436. # =======================================================
  437. # ADDITIONAL VISUAL STUDIO REGISTRY PATHS
  438. # =======================================================
  439. Write-Host "`n--- Checking Additional Visual Studio Registry Paths ---" -ForegroundColor $Colors.Section
  440. # Additional paths that might exist
  441. $additionalPaths = @(
  442. "HKCU:\Software\Microsoft\VisualStudio\14.0\General",
  443. "HKCU:\Software\Microsoft\VisualStudio\15.0\General",
  444. "HKCU:\Software\Microsoft\VisualStudio\16.0\General",
  445. "HKCU:\Software\Microsoft\VisualStudio\17.0\General"
  446. )
  447. foreach ($path in $additionalPaths) {
  448. Write-Host "→ " -NoNewline -ForegroundColor $Colors.Info
  449. Write-Host "Checking additional path..." -ForegroundColor $Colors.White
  450. Set-RegistryValue -Path $path -Name "EnableSQM" -Value 0
  451. }
  452. # Check Experience Improvement Program paths
  453. $experiencePaths = @(
  454. "HKLM:\SOFTWARE\Microsoft\SQMClient",
  455. "HKLM:\SOFTWARE\Wow6432Node\Microsoft\SQMClient"
  456. )
  457. foreach ($path in $experiencePaths) {
  458. Write-Host "→ " -NoNewline -ForegroundColor $Colors.Info
  459. Write-Host "Checking SQM Client path..." -ForegroundColor $Colors.White
  460. Set-RegistryValue -Path $path -Name "CEIPEnable" -Value 0
  461. }
  462. # =======================================================
  463. # TELEMETRY DIRECTORIES CLEANUP
  464. # =======================================================
  465. Write-Host "`n--- Checking Telemetry Directories ---" -ForegroundColor $Colors.Section
  466. $telemetryDirs = @(
  467. "$env:APPDATA\vstelemetry",
  468. "$env:LOCALAPPDATA\Microsoft\VSApplicationInsights",
  469. "$env:PROGRAMDATA\Microsoft\VSApplicationInsights",
  470. "$env:TEMP\Microsoft\VSApplicationInsights",
  471. "$env:TEMP\VSFaultInfo",
  472. "$env:TEMP\VSFeedbackIntelliCodeLogs",
  473. "$env:TEMP\VSFeedbackPerfWatsonData",
  474. "$env:TEMP\VSFeedbackVSRTCLogs",
  475. "$env:TEMP\VSRemoteControl",
  476. "$env:TEMP\VSTelem",
  477. "$env:TEMP\VSTelem.Out"
  478. )
  479. foreach ($dir in $telemetryDirs) {
  480. Remove-TelemetryDirectory -Path $dir
  481. }
  482. # =======================================================
  483. # .NET AND NUGET TELEMETRY DISABLE
  484. # =======================================================
  485. Write-Host "`n--- Disabling .NET and NuGet Telemetry ---" -ForegroundColor $Colors.Section
  486. # Check and set .NET CLI telemetry
  487. Set-EnvironmentVariableIfNeeded -Name 'DOTNET_CLI_TELEMETRY_OPTOUT' -Value '1' -Target 'User'
  488. # Check and set NuGet telemetry
  489. Set-EnvironmentVariableIfNeeded -Name 'NUGET_TELEMETRY_OPTOUT' -Value 'true' -Target 'User'
  490. # =======================================================
  491. # VISUAL STUDIO STANDARD COLLECTOR SERVICE
  492. # =======================================================
  493. Write-Host "`n--- Managing VS Standard Collector Service ---" -ForegroundColor $Colors.Section
  494. $serviceName = 'VSStandardCollectorService150'
  495. $service = Get-Service -Name $serviceName -ErrorAction SilentlyContinue
  496. if ($service) {
  497. Write-Host "→ Found service: $serviceName" -ForegroundColor $Colors.Info
  498. # Check and stop service if running
  499. if ($service.Status -eq 'Running') {
  500. try {
  501. Stop-Service -Name $serviceName -Force -ErrorAction Stop
  502. Write-Host "✓ Stopped $serviceName" -ForegroundColor $Colors.Success
  503. }
  504. catch {
  505. Write-Host "✗ Could not stop $serviceName : $_" -ForegroundColor $Colors.Error
  506. }
  507. } else {
  508. Write-Host "→ Service $serviceName is already stopped (Status: $($service.Status))" -ForegroundColor $Colors.Info
  509. }
  510. # Check and disable service
  511. if ($service.StartType -eq 'Disabled') {
  512. Write-Host "✓ $serviceName already disabled" -ForegroundColor $Colors.Success
  513. } else {
  514. try {
  515. Set-Service -Name $serviceName -StartupType Disabled -Confirm:$false -ErrorAction Stop
  516. Write-Host "✓ Disabled $serviceName" -ForegroundColor $Colors.Success
  517. }
  518. catch {
  519. Write-Host "✗ Could not disable $serviceName : $_" -ForegroundColor $Colors.Error
  520. }
  521. }
  522. } else {
  523. Write-Host "→ $serviceName not found (already removed or not installed)" -ForegroundColor $Colors.Gray
  524. }
  525. # =======================================================
  526. # VISUAL STUDIO CODE SETTINGS
  527. # =======================================================
  528. Write-Host "`n--- Configuring Visual Studio Code Settings ---" -ForegroundColor $Colors.Section
  529. $vscodeSettings = "$env:APPDATA\Code\User\settings.json"
  530. $vscodeUserDir = "$env:APPDATA\Code\User"
  531. $vscodeDetected = $false
  532. if (!(Test-Path "$env:APPDATA\Code")) {
  533. Write-Host "→ Visual Studio Code not detected" -ForegroundColor $Colors.Gray
  534. } else {
  535. Write-Host "→ Visual Studio Code detected" -ForegroundColor $Colors.Info
  536. $vscodeDetected = $true
  537. # Create User directory if needed
  538. if (!(Test-Path $vscodeUserDir)) {
  539. try {
  540. $null = New-Item -Path $vscodeUserDir -ItemType Directory -Force
  541. Write-Host "→ Created VS Code User directory" -ForegroundColor $Colors.Info
  542. } catch {
  543. Write-Host "✗ Failed to create VS Code User directory: $_" -ForegroundColor $Colors.Error
  544. }
  545. }
  546. # Privacy settings
  547. $privacyConfig = @{
  548. "telemetry.enableTelemetry" = $false
  549. "telemetry.enableCrashReporter" = $false
  550. "workbench.enableExperiments" = $false
  551. "update.mode" = "manual"
  552. "update.showReleaseNotes" = $false
  553. "extensions.autoCheckUpdates" = $false
  554. "extensions.showRecommendationsOnlyOnDemand" = $true
  555. "git.autofetch" = $false
  556. "npm.fetchOnlinePackageInfo" = $false
  557. }
  558. try {
  559. # Load existing settings
  560. $settings = @{}
  561. if (Test-Path $vscodeSettings) {
  562. $content = Get-Content $vscodeSettings -Raw -ErrorAction SilentlyContinue
  563. if ($content -and $content.Trim()) {
  564. try {
  565. # Use PowerShell's built-in JSON cmdlets
  566. $settingsObj = $content | ConvertFrom-Json
  567. # Convert PSCustomObject to hashtable for easier manipulation
  568. $settings = @{}
  569. $settingsObj.PSObject.Properties | ForEach-Object {
  570. $settings[$_.Name] = $_.Value
  571. }
  572. Write-Host "→ Found existing VS Code settings file" -ForegroundColor $Colors.Info
  573. }
  574. catch {
  575. Write-Host "→ Could not parse existing settings, creating new ones" -ForegroundColor $Colors.Warning
  576. $settings = @{}
  577. }
  578. }
  579. }
  580. # Update settings
  581. $changesMade = $false
  582. foreach ($key in $privacyConfig.Keys) {
  583. $value = $privacyConfig[$key]
  584. if ($settings.ContainsKey($key) -and $settings[$key] -eq $value) {
  585. Write-Host "✓ " -NoNewline -ForegroundColor $Colors.Success
  586. Write-Host "$key " -NoNewline -ForegroundColor $Colors.Info
  587. Write-Host "already set to " -NoNewline -ForegroundColor $Colors.White
  588. Write-Host "$value" -ForegroundColor $Colors.Success
  589. } else {
  590. $settings[$key] = $value
  591. Write-Host "✓ " -NoNewline -ForegroundColor $Colors.Success
  592. Write-Host "Updated " -NoNewline -ForegroundColor $Colors.White
  593. Write-Host "$key " -NoNewline -ForegroundColor $Colors.Info
  594. Write-Host "to " -NoNewline -ForegroundColor $Colors.White
  595. Write-Host "$value" -ForegroundColor $Colors.Success
  596. $changesMade = $true
  597. }
  598. }
  599. # Save settings if changes were made
  600. if ($changesMade -or !(Test-Path $vscodeSettings)) {
  601. $json = $settings | ConvertTo-Json -Depth 10
  602. $json | Out-File -FilePath $vscodeSettings -Encoding UTF8
  603. Write-Host "✓ Saved VS Code privacy settings" -ForegroundColor $Colors.Success
  604. } else {
  605. Write-Host "→ No changes needed for VS Code settings" -ForegroundColor $Colors.Info
  606. }
  607. }
  608. catch {
  609. Write-Host "✗ Failed to update VS Code settings: $_" -ForegroundColor $Colors.Error
  610. }
  611. }
  612. # =======================================================
  613. # VISUAL STUDIO BACKGROUND DOWNLOAD DISABLE
  614. # =======================================================
  615. Write-Host "`n--- Disabling Visual Studio Background Download ---" -ForegroundColor $Colors.Section
  616. $backgroundDownloadProcessed = $false
  617. # Check if any Visual Studio versions are installed before proceeding
  618. if ($installedVersions.Count -gt 0) {
  619. Write-Host "→ Visual Studio detected, processing BackgroundDownload settings..." -ForegroundColor $Colors.Info
  620. # 1. Disable scheduled tasks
  621. $tasksProcessed = Disable-BackgroundDownloadTasks
  622. # 2. Set registry keys to disable background downloads
  623. Write-Host "→ Setting registry keys to disable background downloads..." -ForegroundColor $Colors.Info
  624. $regPaths = @(
  625. "HKLM:\SOFTWARE\Microsoft\VisualStudio\Setup",
  626. "HKLM:\SOFTWARE\Wow6432Node\Microsoft\VisualStudio\Setup"
  627. )
  628. $regKeysSet = $false
  629. foreach ($regPath in $regPaths) {
  630. # Check if this registry path should exist (based on architecture)
  631. $shouldProcess = $true
  632. if ($regPath -like "*Wow6432Node*" -and ![Environment]::Is64BitOperatingSystem) {
  633. $shouldProcess = $false
  634. }
  635. if ($shouldProcess) {
  636. # Create the registry path if it doesn't exist (since we're configuring VS Setup)
  637. if (!(Test-Path $regPath)) {
  638. try {
  639. $null = New-Item -Path $regPath -Force -ErrorAction Stop
  640. Write-Host "→ Created registry path: $regPath" -ForegroundColor $Colors.Info
  641. }
  642. catch {
  643. Write-Host "✗ Could not create registry path $regPath : $_" -ForegroundColor $Colors.Error
  644. continue
  645. }
  646. }
  647. # Set the registry values
  648. $regSettings = @{
  649. "BackgroundDownloadDisabled" = 1
  650. "DisableBackgroundDownloads" = 1
  651. "DisableAutomaticUpdates" = 1
  652. }
  653. foreach ($setting in $regSettings.GetEnumerator()) {
  654. $success = Set-RegistryValue -Path $regPath -Name $setting.Key -Value $setting.Value -Type 'DWord'
  655. if ($success) {
  656. $regKeysSet = $true
  657. }
  658. }
  659. }
  660. }
  661. # 3. Stop running processes
  662. $processesProcessed = Stop-BackgroundDownloadProcesses
  663. # 4. Clean temporary folders
  664. $tempFoldersProcessed = Remove-BackgroundDownloadTempFolders
  665. # 5. Verification
  666. Write-Host "→ Verifying BackgroundDownload configuration..." -ForegroundColor $Colors.Info
  667. try {
  668. $verificationSuccess = $false
  669. # Check registry settings
  670. foreach ($regPath in $regPaths) {
  671. if (Test-Path $regPath) {
  672. $regValues = Get-ItemProperty -Path $regPath -ErrorAction SilentlyContinue
  673. if ($regValues -and $regValues.BackgroundDownloadDisabled -eq 1) {
  674. Write-Host "✓ Registry verification: BackgroundDownloadDisabled = 1 in $regPath" -ForegroundColor $Colors.Success
  675. $verificationSuccess = $true
  676. }
  677. }
  678. }
  679. if (!$verificationSuccess) {
  680. Write-Host "→ Could not verify registry settings" -ForegroundColor $Colors.Warning
  681. }
  682. } catch {
  683. Write-Host "→ Verification error: $_" -ForegroundColor $Colors.Warning
  684. }
  685. # Set processed flag if any operation was successful
  686. $backgroundDownloadProcessed = $tasksProcessed -or $regKeysSet -or $processesProcessed -or $tempFoldersProcessed
  687. } else {
  688. Write-Host "→ No Visual Studio installations detected, skipping BackgroundDownload configuration" -ForegroundColor $Colors.Gray
  689. }
  690. # =======================================================
  691. # ADDITIONAL POWERSHELL 7 TELEMETRY CHECKS
  692. # =======================================================
  693. Write-Host "`n--- PowerShell 7 Telemetry Checks ---" -ForegroundColor $Colors.Section
  694. # Check if PowerShell telemetry is disabled
  695. try {
  696. $psDataCollection = [Microsoft.PowerShell.Telemetry.ApplicationInsightsTelemetry]::Enabled -eq $false
  697. if ($psDataCollection) {
  698. Write-Host "✓ PowerShell telemetry already disabled" -ForegroundColor $Colors.Success
  699. } else {
  700. Write-Host "→ PowerShell telemetry status:" -ForegroundColor $Colors.Info
  701. }
  702. } catch {
  703. Write-Host "→ Could not check PowerShell telemetry status" -ForegroundColor $Colors.Gray
  704. }
  705. # Check PowerShell environment variables
  706. Set-EnvironmentVariableIfNeeded -Name 'POWERSHELL_TELEMETRY_OPTOUT' -Value '1' -Target 'User'
  707. # =======================================================
  708. # SUMMARY
  709. # =======================================================
  710. Write-Host "`n========================================" -ForegroundColor $Colors.Title
  711. Write-Host "TELEMETRY DISABLE COMPLETE" -ForegroundColor $Colors.Title
  712. Write-Host "========================================" -ForegroundColor $Colors.Title
  713. Write-Host "`nProcessed telemetry settings for:" -ForegroundColor $Colors.White
  714. # Visual Studio versions with status colors
  715. if ($installedVersions.Count -gt 0) {
  716. foreach ($version in $installedVersions) {
  717. Write-Host "✓ " -NoNewline -ForegroundColor $Colors.Success
  718. Write-Host "$($vsVersions[$version]) " -NoNewline -ForegroundColor $Colors.Info
  719. Write-Host "(detected and processed)" -ForegroundColor $Colors.Success
  720. }
  721. } else {
  722. Write-Host "→ " -NoNewline -ForegroundColor $Colors.Gray
  723. Write-Host "No Visual Studio versions detected" -ForegroundColor $Colors.Gray
  724. }
  725. # Visual Studio Code with status colors
  726. if ($vscodeDetected) {
  727. Write-Host "✓ " -NoNewline -ForegroundColor $Colors.Success
  728. Write-Host "Visual Studio Code " -NoNewline -ForegroundColor $Colors.Info
  729. Write-Host "(detected and configured)" -ForegroundColor $Colors.Success
  730. } else {
  731. Write-Host "→ " -NoNewline -ForegroundColor $Colors.Gray
  732. Write-Host "Visual Studio Code " -NoNewline -ForegroundColor $Colors.Info
  733. Write-Host "(not found)" -ForegroundColor $Colors.Gray
  734. }
  735. # .NET CLI status
  736. Write-Host "✓ " -NoNewline -ForegroundColor $Colors.Success
  737. Write-Host ".NET CLI " -NoNewline -ForegroundColor $Colors.Info
  738. Write-Host "(telemetry disabled)" -ForegroundColor $Colors.Success
  739. # NuGet status
  740. Write-Host "✓ " -NoNewline -ForegroundColor $Colors.Success
  741. Write-Host "NuGet " -NoNewline -ForegroundColor $Colors.Info
  742. Write-Host "(telemetry disabled)" -ForegroundColor $Colors.Success
  743. # VS Standard Collector Service status
  744. if ($null -ne $service) {
  745. Write-Host "✓ " -NoNewline -ForegroundColor $Colors.Success
  746. Write-Host "VS Standard Collector Service " -NoNewline -ForegroundColor $Colors.Info
  747. Write-Host "(processed)" -ForegroundColor $Colors.Success
  748. } else {
  749. Write-Host "→ " -NoNewline -ForegroundColor $Colors.Gray
  750. Write-Host "VS Standard Collector Service " -NoNewline -ForegroundColor $Colors.Info
  751. Write-Host "(not found)" -ForegroundColor $Colors.Gray
  752. }
  753. # PowerShell 7 status
  754. $psTelemetryOptOut = [Environment]::GetEnvironmentVariable('POWERSHELL_TELEMETRY_OPTOUT', 'User')
  755. if ($psTelemetryOptOut -eq '1') {
  756. Write-Host "✓ " -NoNewline -ForegroundColor $Colors.Success
  757. Write-Host "PowerShell 7 telemetry " -NoNewline -ForegroundColor $Colors.Info
  758. Write-Host "(opt-out configured via environment variable)" -ForegroundColor $Colors.Success
  759. } else {
  760. Write-Host "→ " -NoNewline -ForegroundColor $Colors.Gray
  761. Write-Host "PowerShell 7 telemetry " -NoNewline -ForegroundColor $Colors.Info
  762. Write-Host "(opt-out not configured; current value: $($psTelemetryOptOut ?? 'not set'))" -ForegroundColor $Colors.Gray
  763. }
  764. # Visual Studio Background Download status
  765. if ($backgroundDownloadProcessed) {
  766. Write-Host "✓ " -NoNewline -ForegroundColor $Colors.Success
  767. Write-Host "Visual Studio Background Download " -NoNewline -ForegroundColor $Colors.Info
  768. Write-Host "(disabled)" -ForegroundColor $Colors.Success
  769. } else {
  770. Write-Host "→ " -NoNewline -ForegroundColor $Colors.Gray
  771. Write-Host "Visual Studio Background Download " -NoNewline -ForegroundColor $Colors.Info
  772. Write-Host "(not processed)" -ForegroundColor $Colors.Gray
  773. }
  774. # Customer Experience Improvement Program status
  775. $experienceDisabled = $true
  776. foreach ($path in $experiencePaths) {
  777. $value = Get-ItemProperty -Path $path -Name "CEIPEnable" -ErrorAction SilentlyContinue
  778. if ($value -and $value.CEIPEnable -ne 0) {
  779. $experienceDisabled = $false
  780. break
  781. }
  782. }
  783. if ($experienceDisabled) {
  784. Write-Host "✓ " -NoNewline -ForegroundColor $Colors.Success
  785. Write-Host "Customer Experience Improvement Program " -NoNewline -ForegroundColor $Colors.Info
  786. Write-Host "(disabled)" -ForegroundColor $Colors.Success
  787. } else {
  788. Write-Host "→ " -NoNewline -ForegroundColor $Colors.Gray
  789. Write-Host "Customer Experience Improvement Program " -NoNewline -ForegroundColor $Colors.Info
  790. Write-Host "(not fully disabled)" -ForegroundColor $Colors.Gray
  791. }
  792. # Telemetry Directories Cleanup status
  793. Write-Host "✓ " -NoNewline -ForegroundColor $Colors.Success
  794. Write-Host "Telemetry Directories Cleanup " -NoNewline -ForegroundColor $Colors.Info
  795. Write-Host "(processed)" -ForegroundColor $Colors.Success
  796. # =======================================================
  797. # ADDITIONAL FEATURES AND ENVIRONMENT VARIABLES
  798. # =======================================================
  799. Write-Host "`n--- Optional: Additional Features and Environment Variables ---" -ForegroundColor $Colors.Section
  800. Write-Host "This will perform additional configuration:" -ForegroundColor $Colors.Info
  801. Write-Host "• Disable Visual Studio Settings Synchronization" -ForegroundColor $Colors.Info
  802. Write-Host "• Disable Live Share" -ForegroundColor $Colors.Info
  803. Write-Host "• Disable IntelliCode" -ForegroundColor $Colors.Info
  804. Write-Host "• Disable CodeLens" -ForegroundColor $Colors.Info
  805. Write-Host "• Set additional environment variables (INTELLICODE_TELEMETRY_OPTOUT, LIVESHARE_TELEMETRY_OPTOUT, VSSDK_TELEMETRY_OPTOUT)" -ForegroundColor $Colors.Info
  806. $enableAdditional = Read-Host "`nEnable additional configuration? (y/n)"
  807. if ($enableAdditional -eq 'y' -or $enableAdditional -eq 'Y' -or $enableAdditional -eq 'yes' -or $enableAdditional -eq 'Yes' -or $enableAdditional -eq 'YES') {
  808. # =======================================================
  809. # VISUAL STUDIO ADDITIONAL FEATURES DISABLE
  810. # =======================================================
  811. Write-Host "`n--- Disabling Additional Visual Studio Features ---" -ForegroundColor $Colors.Section
  812. if ($installedVersions.Count -gt 0) {
  813. foreach ($version in $installedVersions) {
  814. $vsName = $vsVersions[$version]
  815. Write-Host "`n--- Processing Additional Features for $vsName (version $version) ---" -ForegroundColor $Colors.Info
  816. # =======================================================
  817. # SETTINGS SYNCHRONIZATION
  818. # =======================================================
  819. Write-Host "→ Disabling Settings Synchronization..." -ForegroundColor $Colors.Info
  820. $settingsPaths = @(
  821. "HKCU:\Software\Microsoft\VisualStudio\$version\Settings",
  822. "HKCU:\Software\Microsoft\VisualStudio\$version\ApplicationPrivateSettings\Microsoft\VisualStudio\Settings"
  823. )
  824. foreach ($path in $settingsPaths) {
  825. Set-RegistryValue -Path $path -Name "SyncSettings" -Value 0
  826. Set-RegistryValue -Path $path -Name "EnableRoaming" -Value 0
  827. Set-RegistryValue -Path $path -Name "EnableSync" -Value 0
  828. Set-RegistryValue -Path $path -Name "DisableSync" -Value 1
  829. }
  830. # Additional settings sync paths
  831. $syncPath = "HKCU:\Software\Microsoft\VisualStudio\$version\ApplicationPrivateSettings\Microsoft\VisualStudio\ConnectedServices"
  832. Set-RegistryValue -Path $syncPath -Name "Provider.Enabled" -Value 0
  833. # =======================================================
  834. # LIVE SHARE
  835. # =======================================================
  836. Write-Host "→ Disabling Live Share..." -ForegroundColor $Colors.Info
  837. $liveSharePaths = @(
  838. "HKCU:\Software\Microsoft\VisualStudio\$version\LiveShare",
  839. "HKCU:\Software\Microsoft\VisualStudio\$version\ApplicationPrivateSettings\Microsoft\VisualStudio\LiveShare"
  840. )
  841. foreach ($path in $liveSharePaths) {
  842. Set-RegistryValue -Path $path -Name "Enabled" -Value 0
  843. Set-RegistryValue -Path $path -Name "EnableTelemetry" -Value 0
  844. Set-RegistryValue -Path $path -Name "DisableTelemetry" -Value 1
  845. Set-RegistryValue -Path $path -Name "OptedIn" -Value 0
  846. }
  847. # Live Share telemetry
  848. $liveShareTelemetryPath = "HKCU:\Software\Microsoft\VisualStudio\$version\LiveShare\Telemetry"
  849. Set-RegistryValue -Path $liveShareTelemetryPath -Name "Enabled" -Value 0
  850. Set-RegistryValue -Path $liveShareTelemetryPath -Name "OptOut" -Value 1
  851. # =======================================================
  852. # INTELLICODE
  853. # =======================================================
  854. Write-Host "→ Disabling IntelliCode..." -ForegroundColor $Colors.Info
  855. $intelliCodePaths = @(
  856. "HKCU:\Software\Microsoft\VisualStudio\$version\IntelliCode",
  857. "HKCU:\Software\Microsoft\VisualStudio\$version\IntelliSense\IntelliCode",
  858. "HKCU:\Software\Microsoft\VisualStudio\$version\ApplicationPrivateSettings\Microsoft\VisualStudio\IntelliCode"
  859. )
  860. foreach ($path in $intelliCodePaths) {
  861. Set-RegistryValue -Path $path -Name "DisableTelemetry" -Value 1
  862. Set-RegistryValue -Path $path -Name "EnableTelemetry" -Value 0
  863. Set-RegistryValue -Path $path -Name "OptedIn" -Value 0
  864. Set-RegistryValue -Path $path -Name "Enabled" -Value 0
  865. Set-RegistryValue -Path $path -Name "ModelDownloadEnabled" -Value 0
  866. }
  867. # IntelliCode privacy settings
  868. $intelliCodePrivacyPath = "HKCU:\Software\Microsoft\VisualStudio\$version\IntelliCode\Privacy"
  869. Set-RegistryValue -Path $intelliCodePrivacyPath -Name "TelemetryOptOut" -Value 1
  870. Set-RegistryValue -Path $intelliCodePrivacyPath -Name "DataCollection" -Value 0
  871. Set-RegistryValue -Path $intelliCodePrivacyPath -Name "UsageDataOptOut" -Value 1
  872. # =======================================================
  873. # CODELENS
  874. # =======================================================
  875. Write-Host "→ Disabling CodeLens..." -ForegroundColor $Colors.Info
  876. $codeLensPaths = @(
  877. "HKCU:\Software\Microsoft\VisualStudio\$version\CodeLens",
  878. "HKCU:\Software\Microsoft\VisualStudio\$version\TextEditor\CodeLens",
  879. "HKCU:\Software\Microsoft\VisualStudio\$version\ApplicationPrivateSettings\Microsoft\VisualStudio\CodeLens"
  880. )
  881. foreach ($path in $codeLensPaths) {
  882. Set-RegistryValue -Path $path -Name "Disabled" -Value 1
  883. Set-RegistryValue -Path $path -Name "ShowAuthorCodeLens" -Value 0
  884. Set-RegistryValue -Path $path -Name "ShowReferencesCodeLens" -Value 0
  885. Set-RegistryValue -Path $path -Name "ShowTestCodeLens" -Value 0
  886. Set-RegistryValue -Path $path -Name "Enabled" -Value 0
  887. }
  888. # CodeLens telemetry
  889. $codeLensTelemetryPath = "HKCU:\Software\Microsoft\VisualStudio\$version\CodeLens\Telemetry"
  890. Set-RegistryValue -Path $codeLensTelemetryPath -Name "Enabled" -Value 0
  891. Set-RegistryValue -Path $codeLensTelemetryPath -Name "OptOut" -Value 1
  892. }
  893. } else {
  894. Write-Host "→ No Visual Studio installations detected, skipping additional features" -ForegroundColor $Colors.Gray
  895. }
  896. # =======================================================
  897. # ADDITIONAL ENVIRONMENT VARIABLES
  898. # =======================================================
  899. Write-Host "`n--- Setting Additional Environment Variables ---" -ForegroundColor $Colors.Section
  900. Set-EnvironmentVariableIfNeeded -Name 'INTELLICODE_TELEMETRY_OPTOUT' -Value '1' -Target 'User'
  901. Set-EnvironmentVariableIfNeeded -Name 'LIVESHARE_TELEMETRY_OPTOUT' -Value '1' -Target 'User'
  902. Set-EnvironmentVariableIfNeeded -Name 'VSSDK_TELEMETRY_OPTOUT' -Value '1' -Target 'User'
  903. Write-Host "`n✓ Additional configuration completed" -ForegroundColor $Colors.Success
  904. } else {
  905. Write-Host "→ Skipping additional configuration" -ForegroundColor $Colors.Info
  906. }
  907. Write-Host "`nLegend:" -ForegroundColor $Colors.White
  908. Write-Host "✓ " -NoNewline -ForegroundColor $Colors.Success; Write-Host "Action completed successfully" -ForegroundColor $Colors.Gray
  909. Write-Host "→ " -NoNewline -ForegroundColor $Colors.Info; Write-Host "Information or preparatory action" -ForegroundColor $Colors.Gray
  910. Write-Host "→ " -NoNewline -ForegroundColor $Colors.Gray; Write-Host "Component not found or not processed" -ForegroundColor $Colors.Gray
  911. Write-Host "✗ " -NoNewline -ForegroundColor $Colors.Error; Write-Host "Error occurred" -ForegroundColor $Colors.Gray
  912. Write-Host "`nUsage Examples:" -ForegroundColor $Colors.White
  913. Write-Host "→ " -NoNewline -ForegroundColor $Colors.Info
  914. Write-Host "Create backup first: " -NoNewline -ForegroundColor $Colors.White
  915. Write-Host ".\off_telemetry_ps7.ps1 -CreateBackup" -ForegroundColor $Colors.Info
  916. Write-Host "→ " -NoNewline -ForegroundColor $Colors.Info
  917. Write-Host "Restore from backup: " -NoNewline -ForegroundColor $Colors.White
  918. Write-Host ".\off_telemetry_ps7.ps1 -RestoreBackup -BackupPath 'path\to\backup.reg'" -ForegroundColor $Colors.Info
  919. Write-Host "→ " -NoNewline -ForegroundColor $Colors.Info
  920. Write-Host "Run without backup: " -NoNewline -ForegroundColor $Colors.White
  921. Write-Host ".\off_telemetry_ps7.ps1" -ForegroundColor $Colors.Info
  922. if (!$CreateBackup) {
  923. Write-Host "`n⚠ " -NoNewline -ForegroundColor $Colors.Warning
  924. Write-Host "Tip: Run with -CreateBackup parameter to create registry backup first" -ForegroundColor $Colors.Warning
  925. }
  926. Write-Host "`n⚠ " -NoNewline -ForegroundColor $Colors.Warning
  927. Write-Host "Restart may be required for all changes to take effect." -ForegroundColor $Colors.Warning
  928. Write-Host "`nPress Enter to exit..." -ForegroundColor $Colors.White
  929. $null = Read-Host