windows - 如何使用 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"
解决方案
未经测试,请尝试以下方法:
@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
推荐阅读
- java - 如何初始化矩阵对象
- batch-file - 具有从 cmd 调用的输入重定向的批处理脚本自动添加数字参数
- flutter - 在屏幕之间传递数据
- asp.net-mvc - ASP.NET MVC 5 Identity - 更改密码后如何让用户保持登录状态?
- node.js - 我应该如何在 NodeJs 中使用多种不同的两种语言?
- html - React 按钮单击事件未触发 - 一键有效,一键无效
- xml - 将 XML 导入 Excel 时,是否可以在一行中导入节点及其子节点?如果是,怎么做?
- php - 除了 1 个 PHP 变量,来自 $_POST 的所有其他数据都在获取
- javascript - 如何在 Primereact 数据列中添加图像
- reactjs - React Mapbox Layer:为标记显示不同的图像