You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

求助:编写PowerShell脚本向卸载提示框发送TAB和Enter按键以实现IObit Uninstaller静默卸载

Hey Alex, let's break down why your original script isn't working and fix it step by step.

The Problem with Your Original Script

Your current code launches the uninstaller and immediately sends keystrokes—but the uninstall window probably hasn't finished loading yet. Plus, there's no guarantee the uninstall window is the active foreground window when the keys are sent, so the input might go to the wrong app entirely.

Fixed PowerShell Script

Here's a revised version that waits for the uninstall window to load, activates it, and then sends the required keystrokes with proper delays:

# Load required .NET assemblies for window interaction and keystrokes
Add-Type -AssemblyName System.Windows.Forms
Add-Type -AssemblyName Microsoft.VisualBasic

# Launch the uninstaller and keep track of the process
$uninstallPath = "C:\Program Files (x86)\IObit\IObit Uninstaller\unins000.exe"
$uninstallProcess = Start-Process -FilePath $uninstallPath -PassThru

# Wait for the uninstall window to appear (timeout after 30 seconds)
$timeoutSeconds = 30
$startTime = Get-Date
do {
    Start-Sleep -Milliseconds 500
    $uninstallProcess.Refresh()  # Update process info to get latest window title
    $windowTitle = $uninstallProcess.MainWindowTitle
} while ([string]::IsNullOrEmpty($windowTitle) -and ((Get-Date) - $startTime).TotalSeconds -lt $timeoutSeconds)

# Check if we timed out waiting for the window
if ([string]::IsNullOrEmpty($windowTitle)) {
    Write-Error "Uninstall window failed to load within $timeoutSeconds seconds. Exiting."
    exit 1
}

# Activate the uninstall window to ensure keystrokes go to the right place
[Microsoft.VisualBasic.Interaction]::AppActivate($windowTitle)
Start-Sleep -Milliseconds 200  # Give the window time to become active

# Send the TAB and ENTER keystrokes with small delays
[System.Windows.Forms.SendKeys]::SendWait("{TAB}")
Start-Sleep -Milliseconds 100
[System.Windows.Forms.SendKeys]::SendWait("{ENTER}")

Key Improvements Explained

  • Assembly Loading: We explicitly load System.Windows.Forms (for SendKeys) and Microsoft.VisualBasic (for activating windows)—this ensures the required tools are available.
  • Window Wait Loop: We wait until the uninstall window has a visible title (meaning it's loaded) before sending any input, with a timeout to avoid hanging indefinitely.
  • Window Activation: Using AppActivate ensures the uninstall window is the foreground window, so your keystrokes don't get sent to another app like your browser or terminal.
  • Small Delays: Short Start-Sleep calls give the UI time to respond between actions—UI operations aren't instant, so these delays prevent missed keystrokes.

Bonus: Try Silent Uninstall First (More Reliable!)

Before relying on keystroke simulation, double-check if the uninstaller supports proper silent parameters. Many Inno Setup installers (which unins000.exe often is) use these arguments:

Start-Process -FilePath $uninstallPath -ArgumentList "/verysilent /suppressmsgboxes" -Wait -NoNewWindow

This is way more reliable than simulating keystrokes, so give it a shot first!

内容的提问来源于stack exchange,提问作者Alexandru Hera

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.29 07:14:08