首页 > 解决方案 > 如何使用 bat 将卸载的文件复制回同一位置

问题描述

我正在使用从批处理文件运行的卸载字符串卸载软件。它成功卸载软件并删除存储在C:Test\Data.

我想在卸载后将数据文件复制回同一位置,但它不会复制回Data文件夹。

如果我在删除卸载字符串后运行批处理文件,它会按预期工作。

我不确定我在这里做错了什么。

if exist "C:\Test\Data" (
    mkdir C:\TempMPC
    start /wait /b xcopy  C:\Test\Data C:\TempMPC /S /I /Y /R
    rem wait for a moment
    timeout /t 2 /nobreak > nul
)

"C:\Program Files (x86)\InstallShield Installation Information\{2EA86967-B3D3-4B2E-9DE9-28A595AF2E2E}\setup.exe" -runfromtemp -l0x0409 -removeonly /s /f1
timeout /t 5 /nobreak > nul

// THis is not working but if I delete the above command it works
if exist "C:\TempMPC" (
    if not exist "C:\Test\Data" (
        mkdir  C:\Test\Data
    )
    timeout /t 2 /nobreak > nul
    start /wait /b xcopy /S /I /Y /R C:\TempMPC C:\Test\Data
    rem wait for a moment
    timeout /t 1 /nobreak > nul
)

感谢 Gerhard 的输入,我尝试过这种方式:

@echo off
if not exist exist "C:\Test\Data" goto :eof
mkdir "C:\TempMPC">nul 2>&1
robocopy "C:\Test\Data" "C:\TempMPC" /S /I /Y /R

start "" /wait "%ProgramFiles(x86)%\InstallShield Installation Information\{2EA86967-B3D3-4B2E-9DE9-28A595AF2E2E}\setup.exe" -runfromtemp -l0x0409 -removeonly /s /f1"%~dp0\uninstall.iss"

if not exist "C:\TempMPC" goto :eof
mkdir  "C:\Test\Data">nul 2>&1
timeout /t 2 /nobreak > nul
robocopy "C:\TempMPC" "C:\Test\Data" /MIR

卸载时绕过用户输入的响应文件在哪里uninstall.iss,卸载成功。没有复制回来。但是,如果我删除下面的代码行,那么它工作正常。

start "" /wait "%ProgramFiles(x86)%\InstallShield Installation Information\{2EA86967-B3D3-4B2E-9DE9-28A595AF2E2E}\setup.exe" -runfromtemp -l0x0409 -removeonly /s /f1"%~dp0\uninstall.iss"

标签: windowsbatch-fileuninstallation

解决方案


未经测试,请尝试以下方法:

@echo off
if not exist exist "C:\Test\Data" goto :eof
mkdir "C:\TempMPC">nul 2>&1
robocopy "C:\Test\Data" "C:\TempMPC" /MIR

start "" /wait "%ProgramFiles(x86)%\InstallShield Installation Information\{2EA86967-B3D3-4B2E-9DE9-28A595AF2E2E}\setup.exe" -runfromtemp -l0x0409 -removeonly /s /f1

if not exist "C:\TempMPC" goto :eof
mkdir  "C:\Test\Data">nul 2>&1
timeout /t 2 /nobreak > nul
robocopy "C:\TempMPC" "C:\Test\Data" /MIR

推荐阅读