| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- # uninstall.ps1 - CommModifyKit 驱动卸载脚本
- #Requires -RunAsAdministrator
- $ErrorActionPreference = 'Continue'
- Write-Host '=== CommModifyKit 卸载脚本 ===' -ForegroundColor Cyan
- Write-Host ""
- Write-Host "通过 pnputil 删除驱动包..." -ForegroundColor Yellow
- try {
- $raw = pnputil /enum-drivers 2>&1
- $lines = $raw -split "
- ?
- "
- $infs = @()
- for ($i=0; $i -lt $lines.Count; $i++) {
- if ($lines[$i] -match '(oem\d+\.inf)' -and $i+1 -lt $lines.Count -and $lines[$i+1] -match 'CommModifyKit') {
- $infs += $matches[1]
- }
- }
- if ($infs.Count -gt 0) {
- foreach ($inf in $infs) {
- Write-Host " 删除: $inf"
- pnputil /delete-driver $inf /uninstall /force 2>&1 | Out-Null
- if ($LASTEXITCODE -eq 0) { Write-Host " 完成" -ForegroundColor Green }
- else { Write-Warning " 失败" }
- }
- } else { Write-Host " 未找到驱动包" -ForegroundColor Green }
- } catch { Write-Warning "pnputil 失败: $_" }
- $srv = Get-Service -Name 'CommModifyKit' -ErrorAction SilentlyContinue
- if ($srv) {
- Write-Host ""
- if ($srv.Status -eq 'Running') { sc.exe stop CommModifyKit | Out-Null; Start-Sleep 2 }
- sc.exe delete CommModifyKit | Out-Null
- Write-Host "服务已删除" -ForegroundColor Green
- }
- # 从 Ports 类 UpperFilters 移除 CommModifyKit
- $PortsClassGuid = "{4D36E978-E325-11CE-BFC1-08002BE10318}"
- $ClassKey = "HKLM:\SYSTEM\CurrentControlSet\Control\Class\$PortsClassGuid"
- $existingFilters = (Get-ItemProperty -Path $ClassKey -Name "UpperFilters" -ErrorAction SilentlyContinue)
- if ($existingFilters) {
- $currentFilters = @($existingFilters.UpperFilters)
- if ($currentFilters -contains "CommModifyKit") {
- $newFilters = @($currentFilters | Where-Object { $_ -ne "CommModifyKit" })
- if ($newFilters.Count -eq 0) {
- Remove-ItemProperty -Path $ClassKey -Name "UpperFilters" -ErrorAction SilentlyContinue
- } else {
- Set-ItemProperty -Path $ClassKey -Name "UpperFilters" -Value $newFilters -Type MultiString
- }
- Write-Host "已从 Ports 类 UpperFilters 移除 CommModifyKit" -ForegroundColor Green
- }
- }
- $sys = Join-Path $env:windir "System32\drivers\CommModifyKit.sys"
- $inf = Join-Path $env:windir "System32\drivers\CommModifyKit.inf"
- Write-Host ""
- if (Test-Path $sys) { Remove-Item $sys -Force -ErrorAction SilentlyContinue }
- if (Test-Path $inf) { Remove-Item $inf -Force -ErrorAction SilentlyContinue }
- Write-Host "驱动文件已删除" -ForegroundColor Green
- Write-Host ""
- Write-Host '=== 卸载完成 ===' -ForegroundColor Cyan
|