Windows 批处理脚本相当于 Windows PowerShell 脚本

Windows 批处理脚本相当于 Windows PowerShell 脚本

有人能帮我创建一个与我编写的 Windows PowerShell 脚本等效的 Windows 批处理脚本吗?我知道前几行应该是什么,但我不知道其余的是什么。

PowerShell 代码:

Get-Process -Name Firefox | Stop-Process

Start-Process -FilePath "C:\Program Files\Mozilla Firefox\uninstall\helper.exe" -ArgumentList "-ms" -ErrorAction SilentlyContinue -PassThru | Wait-Process -Timeout 30
Start-Process -FilePath "C:\Program Files (x86)\Mozilla Firefox\uninstall\helper.exe" -ArgumentList "-ms" -ErrorAction SilentlyContinue -PassThru | Wait-Process -Timeout 30

$UserProfiles = Get-ChildItem -Path "C:\Users" -Exclude "Public", "Default"

foreach ($Profile in $UserProfiles) {
    Remove-Item -Path "$Profile\AppData\Roaming\Mozilla\Firefox" -Force -Recurse -ErrorAction SilentlyContinue -Confirm:$false
}

批号:

taskill Firefox
"C:\Program Files\Mozilla Firefox\uninstall\helper.exe" -ms
"C:\Program Files (x86)\Mozilla Firefox\uninstall\helper.exe" -ms
...

答案1

@echo off && Setlocal EnableDelayedExpansion

set^ "_Mozilla_Firefox=AppData\Roaming\Mozilla\Firefox\." 
set^ "_Mozilla_helper_=Mozilla Firefox\uninstall\helper.exe"
set^ "_ProgramFiles=ProgramFiles,ProgramFiles(x86^),ProgramW6432"
set^ "_wmic=^<con: %__AppDir__%\wbem\wmic.exe" & cd /d "%__AppDir__%" 

:again
tasklist.exe /svc /fo list|find.exe /i "firefox.exe" >nul && 2>nul (( 
    taskkill.exe /f /im firefox.exe >nul ) || ( timeout.exe /t 001 >nul & goto :again ))
     
for %%i in (!_ProgramFiles!)do if exist "!%%~i!\!_Mozilla_helper_!" (
    start "Unistall Mozilla Firefox.exe" /Wait /Normal "!%%~i!\!_Mozilla_helper_!" -ms )

<nul cd /d "%UserProfile%" && cd.. && for /f usebackq^ ^tokens^=1*^ ^delims^=^= %%i in (
`%_wmic% UserAccount where status^='ok' get name/format:list^|%__AppDir__%more.com^|findstr.exe .
   `)do call set^ "_%%~i=%%~j" && <con: call rmDir /q /s "!__cd__!\!_name!\!_Mozilla_Firefox!" 2>nul 
         
popd & endlocal & goto :eof

观察:尝试想象一个 bat 来执行相同的任务,这比在 ps1 上搜索涉及 cmd 中不存在的方法的“翻译”更容易。

相关内容