如何运行“.bat"安装过程中的文件? [英] How to run a ".bat" file during installation?

查看:35
本文介绍了如何运行“.bat"安装过程中的文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在安装项目中,可以接受诸如.exe、.dll、.js、.vbs"之类的可执行文件,但无法在自定义操作中运行 .bat 文件.

In a Setup project the executable files such as ".exe , .dll , .js , .vbs" are acceptable but there is no way to run a .bat file in a Custom Action.

问题是如何在安装过程中运行*.bat文件?

The question is how to run the *.bat files during installation?

推荐答案

好吧,经过多次搜索和反复试验,我已经解决了这个问题.我不确定这是否是最好的方法,但它确实有效.

Well, after much searching and trial and error I have solved this. I'm not sure if this is the best way, but it works.

场景如下:我有一个应用程序,我想通过 Visual Studio 安装项目进行部署.除了我的应用程序文件之外,我还想在包含批处理 (.bat) 文件的目标目录中创建一个子目录.我希望这个文件在安装过程结束时运行.

Here's the scenario: I have an application I would like to deploy via a Visual Studio Setup project. In addition to my application files, I would like to create a subdirectory in the target directory that contains a batch (.bat) file. I would like this file to run at the end of the installation process.

这就是你要做的:

  1. 创建一个安装项目并像往常一样进行配置,包括您将放置批处理文件的子目录(如果您不想将它放在子目录中,可以直接将它放在应用程序文件夹中).
  2. 在文件系统"视图中(在解决方案资源管理器中右键单击项目->视图->文件系统),添加要执行的批处理文件 cmd.exe(C:WindowsSystem32cmd.exe)
  3. 打开自定义操作"视图(在解决方案资源管理器中右键单击项目->视图->自定义操作)
  4. 右键单击提交"并选择添加自定义操作"
  5. 导航到并选择 cmd.exe.
  6. 打开新创建的自定义操作的属性面板.
  7. 从 Arguments 属性中删除/Commit.
  8. 在 Arguments 属性中输入:/c "[TARGETDIR]subdirectorynameatchfile.bat",其中 subdirectoryname 应替换为您的子目录的名称(如果您像我一样将批处理文件放在子目录中......如果你没有,值应该是 /c "[TARGETDIR]batchfile.bat") 和 batchfile.bat 应该是文件名您的批处理文件.
  1. Create a setup project and configure as you normally would, including the subdirectory in which you'll place your batch file (you can just place it in the Application Folder directly if you don't want it in a subdirectory).
  2. In the "File System" view (right-click on the project in Solution Explorer->View->File System), add the batch file you want to execute and cmd.exe (C:WindowsSystem32cmd.exe)
  3. Open the "Custom Actions" view (right-click on the project in Solution Explorer->View->Custom Actions)
  4. Right-click on "Commit" and choose "Add Custom Action"
  5. Navigate to and select cmd.exe.
  6. Open the properties panel for the newly created custom action.
  7. Delete /Commit from the Arguments property.
  8. Enter: /c "[TARGETDIR]subdirectorynameatchfile.bat" in the Arguments property, where subdirectoryname should be replaced by the name of your subdirectory (if you put the batch file in a subdirectory like I did... if you didn't, the value should be /c "[TARGETDIR]batchfile.bat") and batchfile.bat should be the filename of your batch file.

就是这样.完成安装过程的其余部分后,将立即执行批处理文件.

That's it. The batch file will now be executed once the rest of the installation process is completed.

为了清楚起见,这里有一个例子:

Here's an example for the sake of clarity:

我的批处理文件:blah.bat
我的子目录:mydir

针对 cmd.exe 的自定义操作的参数值将是

The value of the Arguments for my custom action targeting cmd.exe would then be

/c "[TARGETDIR]mydirlah.bat"

希望对某人有所帮助!

这篇关于如何运行“.bat"安装过程中的文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆