我已经写了一个批处理文件,该文件在两个文件夹路径中查找可执行文件,然后运行它。我是编写批处理文件的新手,并被告知这很草率,可以用if/else语句写得更好。
@echo off
Taskkill /im firefox.exe >nul 2>nul
echo Remove and re-install Mozilla Firefox
"C:program filesMozilla Firefoxuninstallhelper.exe" /s
"C:program files (x86)Mozilla Firefoxuninstallhelper.exe" /s
到目前为止,我发现什么都没有起作用;这是最后一次不起作用的尝试;
@echo off
Taskkill /im firefox.exe >nul 2>nul
echo Remove and re-install Mozilla Firefox
IF exist helper.exe /s ( "C:program filesMozilla Firefoxuninstall
) else helper.exe /s ( "C:program files (x86)Mozilla firefoxuninstall
)
您可以做:
@echo off
taskkill /im firefox.exe >nul 2>nul
echo Remove and re-install Mozilla Firefox
if exist "C:program filesMozilla Firefoxuninstallhelper.exe" (
"C:program filesMozilla Firefoxuninstallhelper.exe" /s
) else (
"C:program files (x86)Mozilla firefoxuninstallhelper.exe" /s
)
但是您实际上不需要else
语句:
@echo off
taskkill /im firefox.exe >nul 2>nul
echo Remove and re-install Mozilla Firefox
if exist "C:program filesMozilla Firefoxuninstallhelper.exe" /s
if exist "C:program files (x86)Mozilla firefoxuninstallhelper.exe" /s
或
"C:program filesMozilla Firefoxuninstallhelper.exe" /s || "C:program files (x86)Mozilla firefoxuninstallhelper.exe" /s
甚至更好,在环境中找到Firefox的路径(如果正确安装)并使用它的路径:
@echo off
taskkill /im firefox.exe >nul 2>nul
echo Remove and re-install Mozilla Firefox
for /f "delims=" %%i in ('where firefox.exe') do (
"%%~dpihelper.exe" /s
)