private/Test-InstallVSCode.ps1
|
function Test-InstallVSCode { <# .SYNOPSIS Tests whether stable Visual Studio Code is installed .DESCRIPTION Checks the known per-user and system-wide Code.exe paths. If neither file exists, searches the machine and current-user uninstall registry for the Visual Studio Code display name. Returns $true when any method finds an installation; otherwise, returns $false. .EXAMPLE PS> Test-InstallVSCode Tests known paths and uninstall registry entries for stable Visual Studio Code. .INPUTS None. This function does not accept pipeline input. .OUTPUTS System.Boolean. Returns $true when stable Visual Studio Code is detected; otherwise, returns $false. .NOTES Author: David Segura Company: Recast Software Version: 1.0.0 Date: 2026-08-28 .LINK Test-CommandVSCode #> [OutputType([bool])] param () # Fast path — known install locations $knownPaths = @( (Join-Path $env:LOCALAPPDATA 'Programs\Microsoft VS Code\Code.exe'), (Join-Path $env:ProgramFiles 'Microsoft VS Code\Code.exe') ) foreach ($path in $knownPaths) { if (Test-Path -Path $path) { return $true } } # Registry fallback $regPaths = @( 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\*', 'HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*', 'HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\*' ) foreach ($regPath in $regPaths) { $entry = Get-ItemProperty -Path $regPath -ErrorAction SilentlyContinue | Where-Object { $_.PSObject.Properties['DisplayName'] -and $_.DisplayName -like 'Microsoft Visual Studio Code' } | Select-Object -First 1 if ($entry) { return $true } } return $false } |