qq2348227 发表于 2025-3-13 23:10

请问卸载edge想写个批处理,请问这个变量应该怎么写?

"C:\Program Files (x86)\Microsoft\Edge\Application\92.0.902.67\Installer\setup.exe" --uninstall --msedge --channel=stable --system-level --verbose-logging --run-as-admin


这个批处理如何在 powershell 里面运行?

qq2348227 发表于 2025-3-13 23:17

setup.exe --uninstall --system-level --verbose-logging --force-uninstall

chengyiqun 发表于 2025-3-14 12:03

bat脚本
@echo off
:: 请求管理员权限
net session >nul 2>&1
if %errorLevel% neq 0 (
    powershell -Command "Start-Process '%~f0' -Verb runAs"
    exit /b
)

set "edge_base=C:\Program Files (x86)\Microsoft\Edge\Application"
set "version="

:: 查找最新的版本目录
for /f "delims=" %%a in ('dir /b /ad /od "%edge_base%" 2^>nul') do set "version=%%a"

if not defined version (
    echo 未找到Microsoft Edge的安装目录。
    pause
    exit /b 1
)

set "setup_exe=%edge_base%\%version%\Installer\setup.exe"

if not exist "%setup_exe%" (
    echo 未找到卸载程序:%setup_exe%
    pause
    exit /b 1
)

echo 正在卸载Microsoft Edge版本%version%...
"%setup_exe%" --uninstall --msedge --channel=stable --system-level --verbose-logging --run-as-admin

echo 卸载完成。
pause

powershell脚本
#requires -RunAsAdministrator

$edgeBase = "C:\Program Files (x86)\Microsoft\Edge\Application"
$versionPattern = "^\d+\.\d+\.\d+\.\d+$"# 匹配版本号格式

# 获取最新的Edge版本目录
try {
    $versionDirs = Get-ChildItem -Path $edgeBase -Directory |
                   Where-Object { $_.Name -match $versionPattern } |
                   Sort-Object { $_.Name } -Descending

    if (-not $versionDirs) {
      throw "未找到有效的Edge版本目录"
    }

    $latestVersion = $versionDirs.Name
    Write-Host "找到最新版本: $latestVersion" -ForegroundColor Green

    # 构建卸载程序路径
    $setupPath = Join-Path -Path $edgeBase -ChildPath "$latestVersion\Installer\setup.exe"
   
    if (-not (Test-Path $setupPath)) {
      throw "卸载程序未找到: $setupPath"
    }

    # 执行卸载命令
    Write-Host "正在卸载Microsoft Edge $latestVersion..." -ForegroundColor Yellow
    $arguments = @(
      "--uninstall",
      "--msedge",
      "--channel=stable",
      "--system-level",
      "--verbose-logging",
      "--run-as-admin"
    )

    Start-Process -FilePath $setupPath -ArgumentList $arguments -Wait -NoNewWindow

    Write-Host "卸载完成" -ForegroundColor Green

} catch {
    Write-Host "错误: $_" -ForegroundColor Red
    Read-Host "按Enter键退出"
    exit 1
}

以上内容来自 qwen QwQ

h3nrychang2 发表于 2025-3-14 15:39

这都不会,别玩卸载了,只能越卸问题越多

nathan6498 发表于 2025-3-14 17:36

学习学习

滚粗 发表于 2025-3-15 09:52

直接找卸载软件轻松解决
页: [1]
查看完整版本: 请问卸载edge想写个批处理,请问这个变量应该怎么写?