2-download — And Install Usbdk-1.0.22-x64.msi
if ($success) Write-Log "SUCCESS" "USBDK installation completed successfully" exit 0
private async Task<bool> DownloadInstallerAsync() try using (var httpClient = new HttpClient()) httpClient.Timeout = TimeSpan.FromMinutes(5); using (var response = await httpClient.GetAsync(USBDK_DOWNLOAD_URL, HttpCompletionOption.ResponseHeadersRead)) response.EnsureSuccessStatusCode(); using (var fileStream = new FileStream(_downloadPath, FileMode.Create, FileAccess.Write, FileShare.None)) await response.Content.CopyToAsync(fileStream);
# USBDKInstaller.ps1 param( [switch]$ForceReinstall, [switch]$Silent ) $ErrorActionPreference = "Stop" Constants $USBDK_URL = "https://github.com/daynix/UsbDk/releases/download/v1.0.22/UsbDk_1.0.22_x64.msi" $InstallerPath = Join-Path $env:TEMP "UsbDk_1.0.22_x64.msi" Logging function function Write-Log param([string]$Level, [string]$Message) $timestamp = Get-Date -Format "HH:mm:ss" $color = @ "INFO" = "Cyan" "ERROR" = "Red" "SUCCESS" = "Green" "WARNING" = "Yellow" [$Level] 2-download and install usbdk-1.0.22-x64.msi
# Download and install if (Download-USBDKInstaller) $result = Install-USBDK # Cleanup if (Test-Path $InstallerPath) Remove-Item $InstallerPath -Force -ErrorAction SilentlyContinue Write-Log "INFO" "Cleaned up installer file" return $result
try $webClient = New-Object System.Net.WebClient $webClient.DownloadFile($USBDK_URL, $InstallerPath) if (Test-Path $InstallerPath) Write-Log "SUCCESS" "Downloaded to $InstallerPath" return $true using (var fileStream = new FileStream(_downloadPath
C# Usage:
// Check Windows registry string uninstallKey = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"; using (Microsoft.Win32.RegistryKey key = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(uninstallKey)) if (key != null) foreach (string subkeyName in key.GetSubKeyNames()) using (Microsoft.Win32.RegistryKey subkey = key.OpenSubKey(subkeyName)) if (subkey?.GetValue("DisplayName")?.ToString()?.Contains("UsbDk") == true) return true; return false; catch return false; # USBDKInstaller.ps1 param( [switch]$ForceReinstall
// Step 2: Check if already installed if (!forceReinstall && IsUSBDKInstalled()) _logger.LogInfo("USBDK is already installed"); return true;