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

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

问题描述

在安装项目的可执行文件,如名为.exe,.dll的.js,.vbs的是可以接受的,也没有办法运行在自定义操作.bat文件。

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

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

The question is how to run the "xxxxxx.bat" 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 :\\ WINDOWS \\ SYSTEM32 \\ CMD.EXE)

  3. 打开自定义操作的看法
  4. (在解决方案资源管理项目>查看 - >自定义操作右键点击)
  5. 右键点击提交,然后选择添加自定义操作

  6. 浏览并选择cmd.exe的。

  7. 打开新创建的自定义操作的属性面板。

  8. 删除/从Arguments属性提交。

  9. 输入: / C[TARGETDIR] subdirectoryname \\ batchfile.bat 在Arguments属性,其中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:\Windows\System32\cmd.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]subdirectoryname\batchfile.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

My batch file: blah.bat
My subdirectory: mydir

的参数为我的自定义操作的目标则CMD.EXE将是值

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

/ C[TARGETDIR] MYDIR \\ blah.bat

希望帮助别人!

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

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