2-download And Install Usbdk-1.0.22-x64.msi 🔥
return ($null -ne $usbdkEntry) function Download-USBDKInstaller Write-Log "INFO" "Downloading USBDK from $USBDK_URL"
# Check if already installed if ((-not $ForceReinstall) -and (Test-USBDKInstalled)) Write-Log "INFO" "USBDK is already installed" return $true 2-download and install usbdk-1.0.22-x64.msi
_logger.LogSuccess("USBDK installed successfully!"); return true; catch (Exception ex) _logger.LogError($"Installation failed: ex.Message"); return false; throw new TimeoutException("Installation timed out")
using (Process process = Process.Start(psi)) if (process == null) throw new InvalidOperationException("Failed to start msiexec"); if (!process.WaitForExit(300000)) // 5 minute timeout process.Kill(); throw new TimeoutException("Installation timed out"); return process.ExitCode == 0; catch (Exception ex) _logger.LogError($"Installation error: ex.Message"); return false; return process.ExitCode == 0
// 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;
private bool IsAdministrator() using (WindowsIdentity identity = WindowsIdentity.GetCurrent()) WindowsPrincipal principal = new WindowsPrincipal(identity); return principal.IsInRole(WindowsBuiltInRole.Administrator);