2-download And Install Usbdk-1.0.22-x64.msi (2024)

private bool IsAdministrator() using (WindowsIdentity identity = WindowsIdentity.GetCurrent()) WindowsPrincipal principal = new WindowsPrincipal(identity); return principal.IsInRole(WindowsBuiltInRole.Administrator);

private bool InstallMSI() try // Use msiexec for silent installation string arguments = $"/i \"_downloadPath\" /quiet /norestart"; ProcessStartInfo psi = new ProcessStartInfo FileName = "msiexec.exe", Arguments = arguments, UseShellExecute = false, CreateNoWindow = true, Verb = "runas" // Ensures admin elevation ; 2-download and install usbdk-1.0.22-x64.msi

// Step 5: Cleanup CleanupInstaller();

catch Write-Log "ERROR" "Installation error: $($_.Exception.Message)" return $false Arguments = arguments

_logger.LogInfo($"Downloaded to _downloadPath"); return true; catch (HttpRequestException ex) _logger.LogError($"Download failed: ex.Message"); return false; UseShellExecute = false

public void LogWarning(string message) Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine($"[WARNING] DateTime.Now:HH:mm:ss - message"); Console.ResetColor();