uninstall.ps1 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. # uninstall.ps1 - CommModifyKit 驱动卸载脚本
  2. #Requires -RunAsAdministrator
  3. $ErrorActionPreference = 'Continue'
  4. Write-Host '=== CommModifyKit 卸载脚本 ===' -ForegroundColor Cyan
  5. Write-Host ""
  6. Write-Host "通过 pnputil 删除驱动包..." -ForegroundColor Yellow
  7. try {
  8. $raw = pnputil /enum-drivers 2>&1
  9. $lines = $raw -split "
  10. ?
  11. "
  12. $infs = @()
  13. for ($i=0; $i -lt $lines.Count; $i++) {
  14. if ($lines[$i] -match '(oem\d+\.inf)' -and $i+1 -lt $lines.Count -and $lines[$i+1] -match 'CommModifyKit') {
  15. $infs += $matches[1]
  16. }
  17. }
  18. if ($infs.Count -gt 0) {
  19. foreach ($inf in $infs) {
  20. Write-Host " 删除: $inf"
  21. pnputil /delete-driver $inf /uninstall /force 2>&1 | Out-Null
  22. if ($LASTEXITCODE -eq 0) { Write-Host " 完成" -ForegroundColor Green }
  23. else { Write-Warning " 失败" }
  24. }
  25. } else { Write-Host " 未找到驱动包" -ForegroundColor Green }
  26. } catch { Write-Warning "pnputil 失败: $_" }
  27. $srv = Get-Service -Name 'CommModifyKit' -ErrorAction SilentlyContinue
  28. if ($srv) {
  29. Write-Host ""
  30. if ($srv.Status -eq 'Running') { sc.exe stop CommModifyKit | Out-Null; Start-Sleep 2 }
  31. sc.exe delete CommModifyKit | Out-Null
  32. Write-Host "服务已删除" -ForegroundColor Green
  33. }
  34. # 从 Ports 类 UpperFilters 移除 CommModifyKit
  35. $PortsClassGuid = "{4D36E978-E325-11CE-BFC1-08002BE10318}"
  36. $ClassKey = "HKLM:\SYSTEM\CurrentControlSet\Control\Class\$PortsClassGuid"
  37. $existingFilters = (Get-ItemProperty -Path $ClassKey -Name "UpperFilters" -ErrorAction SilentlyContinue)
  38. if ($existingFilters) {
  39. $currentFilters = @($existingFilters.UpperFilters)
  40. if ($currentFilters -contains "CommModifyKit") {
  41. $newFilters = @($currentFilters | Where-Object { $_ -ne "CommModifyKit" })
  42. if ($newFilters.Count -eq 0) {
  43. Remove-ItemProperty -Path $ClassKey -Name "UpperFilters" -ErrorAction SilentlyContinue
  44. } else {
  45. Set-ItemProperty -Path $ClassKey -Name "UpperFilters" -Value $newFilters -Type MultiString
  46. }
  47. Write-Host "已从 Ports 类 UpperFilters 移除 CommModifyKit" -ForegroundColor Green
  48. }
  49. }
  50. $sys = Join-Path $env:windir "System32\drivers\CommModifyKit.sys"
  51. $inf = Join-Path $env:windir "System32\drivers\CommModifyKit.inf"
  52. Write-Host ""
  53. if (Test-Path $sys) { Remove-Item $sys -Force -ErrorAction SilentlyContinue }
  54. if (Test-Path $inf) { Remove-Item $inf -Force -ErrorAction SilentlyContinue }
  55. Write-Host "驱动文件已删除" -ForegroundColor Green
  56. Write-Host ""
  57. Write-Host '=== 卸载完成 ===' -ForegroundColor Cyan