param([switch]$StartAfterInstall) $ErrorActionPreference = 'Stop' [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 $packageUrl = 'https://decathlon.jokonet.com/api/client/download' $installDir = '%LOCALAPPDATA%\Programs\CallRecorder' $exeName = 'CallRecorder.exe' $installVcRedist = $true $vcRedistUrl = 'https://aka.ms/vs/17/release/vc_redist.x64.exe' $installDir = [Environment]::ExpandEnvironmentVariables($installDir) function Test-VcRedistInstalled { $keys = @( 'HKLM:\SOFTWARE\Microsoft\VisualStudio\14.0\VC\Runtimes\x64', 'HKLM:\SOFTWARE\WOW6432Node\Microsoft\VisualStudio\14.0\VC\Runtimes\x64' ) foreach ($key in $keys) { try { $item = Get-ItemProperty -Path $key -ErrorAction Stop if ($item.Installed -eq 1) { return $true } } catch {} } return $false } function Install-VcRedistIfNeeded { if (-not $installVcRedist) { Write-Host 'VC++ redistributable check disabled by configuration.' return } if (Test-VcRedistInstalled) { Write-Host 'VC++ redistributable already installed.' return } Write-Host 'VC++ redistributable not found, installing...' $vcExe = Join-Path $env:TEMP 'vc_redist.x64.exe' Invoke-WebRequest -Uri $vcRedistUrl -OutFile $vcExe try { Start-Process -FilePath $vcExe -ArgumentList '/install', '/quiet', '/norestart' -Wait -NoNewWindow | Out-Null } catch { Write-Warning 'VC++ installation failed. You may need to run this script as Administrator.' } } Install-VcRedistIfNeeded $tempRoot = Join-Path $env:TEMP ('CallRecorderInstall_' + [Guid]::NewGuid().ToString('N')) New-Item -ItemType Directory -Path $tempRoot -Force | Out-Null $zipPath = Join-Path $tempRoot 'CallRecorderClientBundle.zip' Write-Host 'Downloading client package...' Invoke-WebRequest -Uri $packageUrl -OutFile $zipPath Get-Process -Name 'CallRecorder' -ErrorAction SilentlyContinue | Stop-Process -Force if (Test-Path $installDir) { Remove-Item -Path $installDir -Recurse -Force } New-Item -ItemType Directory -Path $installDir -Force | Out-Null Write-Host 'Extracting package...' Expand-Archive -Path $zipPath -DestinationPath $installDir -Force $exePath = Join-Path $installDir $exeName if (-not (Test-Path $exePath)) { throw "Executable not found after extraction: $exePath" } $desktopPath = [Environment]::GetFolderPath('Desktop') $launcherPath = Join-Path $desktopPath 'CallRecorder.cmd' $launcherContent = @" @echo off cd /d "$installDir" start "" "$exePath" "@ Set-Content -Path $launcherPath -Value $launcherContent -Encoding Ascii -Force Write-Host "Desktop launcher created: $launcherPath" try { $shortcutPath = Join-Path $desktopPath 'CallRecorder.lnk' $shell = New-Object -ComObject WScript.Shell $shortcut = $shell.CreateShortcut($shortcutPath) $shortcut.TargetPath = $launcherPath $shortcut.WorkingDirectory = $installDir $shortcut.Save() } catch { Write-Warning 'Desktop .lnk shortcut creation failed. .cmd launcher is available.' } Remove-Item -Path $tempRoot -Recurse -Force -ErrorAction SilentlyContinue Write-Host "Installation completed: $exePath" if ($StartAfterInstall) { Start-Process -FilePath $exePath }