请问卸载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 里面运行?
setup.exe --uninstall --system-level --verbose-logging --force-uninstall
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 这都不会,别玩卸载了,只能越卸问题越多 学习学习 直接找卸载软件轻松解决
页:
[1]