Batch file giving invalid path error while creating an installer

隐身守侯 提交于 2021-01-28 18:35:50

问题


Basically I am trying to create an installer. I have an EXE file and I need to do the following steps through a bat file:

  1. create a folder at C:\Data
  2. Copy a file in C.\Data
  3. Create a folder inside C:\Program Files
  4. Copy exe file in C:\Program Files\My Project Folder
  5. Create shortcut to exe on Desktop

My code is as follows:

@echo off
if not exist "%PROGRAMFILES%\MyFolder" mkdir %PROGRAMFILES%\MyFolder
if not exist "C:\Data" mkdir C:\Data
copy /q /y ".\MyFile.exe" "%PROGRAMFILES%\MyFolder\MyFile.exe"
copy /q /y ".\MyFileDb.db" "C:\Data\MyFileDb.db"

The problem is that it shows "invalid path" error and says 0 files copied for MyFolder. However, it successfully creates Data folder and copies MyFileDb.db inside it.

Second problem is that I cannot figure out how to execute the Step 5 of my problem statement.


回答1:


  1. MSI: I would use a proper MSI deployment tool. Here are some of the major ones.

    • For something this simple I think the free version of Advanced Installer would work properly. It should be very simple. Maybe check the help portal and the videos.
    • Then there is always WiX which is free and open source, but there is a learning curve.
    • The Visual Studio Installer projects do work for simple things, but do not scale well. Free.
  2. Non-MSI: You can also use non-MSI deployment technologies such as Inno Setup or NSIS.

  3. Self-Extraction Tools: Some recommend self-extracting archives.

    • I am very skeptical - essentially for practical-, runtime dependency- and security-reasons.
    • Combine exe and msi file in one installer

Some Further Links:

  • RoboCopy.exe: How do I compare two folders recursively and generate a list of files and folders that are different? A practical sample of using the newer RoboCopy.exe to do the copying.


来源:https://stackoverflow.com/questions/53130986/batch-file-giving-invalid-path-error-while-creating-an-installer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!