读书人

【转】NSIS 公布程序及bat编写及运行

发布时间: 2012-09-01 09:33:02 作者: rapoo

【转】NSIS 发布程序及bat编写及运行

?

提到这个第三方打包软件,最近研究了下,之前使用vs2008打包,只是简单的程序打包,没有设计到dll、ocx注册及其他辅助程序的运行等,所以,这回需求需要将这些内容都统一打包进去,所以就选择这个NSIS第三个打包到了一点脚本语言的编写,还好有这个NSIS帮助文档。说白了,它是向导+编码。做起来还是比较容易。

这个软件,我用的是nsis2.37版本,编辑器用的是VNISEdit060712。

首先要准备好你的程序,比如我们的SMMS.exe,还要程序运行的必要注册安装之类的东西。比如,我们需要注册TeeChar.ocx,需要注册matlab写好的两个com,singkalman.dll,和singSubImgPro.dll,还有一些图像的库dll.

而且在用户机器上需要安装vs2008安装包,vcredist_x86.exe和matlab的运行时MCRInstaller.exe。所以这些需要写脚步文件进行控制。最后是一些按照过程中的安装图标(格式为ico),背景图片(格式为bmp)等。

一、打开HM-VNISEdit,文件-》新建向导,打开向导,如下图

【转】NSIS 公布程序及bat编写及运行

??File "singKalman14Reg\distrib\singKalman14_1_0.dll"

??File "singKalman14Reg\distrib\singKalman14_pkg.exe"

??File "singSubImgPro10Reg\distrib\singSubImgPro10_1_0.dll"

??File "singSubImgPro10Reg\distrib\singSubImgPro10_pkg.exe"

??File "singKalman14Reg\distrib\singKalman14.ctf"

??File "singSubImgPro10Reg\distrib\singSubImgPro10.ctf"

SectionEnd

三)运行exe

Section StartPro

??ExecWait $INSTDIR\MCRInstaller.exe?

SectionEnd

ExecWait?要比Exc?要好,直到这个程序运行完毕,才执行下面步骤。

?

四)运行ocx

我不知道怎么运行ocx,只能把这个ocx写成一个bat文件,bat代码如下

echo off

regsvr32 TeeChart5.ocx

echo Installation complete.

命名为为TeeChar_install.bat,(而且这个文件在加载文件的时候,已经打包到安装程序里面,还有他需要的TeeChart5.ocx,否则会运行失败,脚步文件运行bat时只需运行他目录下的TeeChar_install.bat即可。)

脚本文件注册bat为

Section StartPro

?ExecWait $INSTDIR\TeeChar_install.bat

SectionEnd

?

将两个注册com的代码写成了一个注册bat,bat代码如下

echo off

echo Deploying project singKalman14, version 1.0.

IF EXIST MCRInstaller.exe (

echo Running MCRInstaller

MCRInstaller.exe

)

echo Registering the component...

IF EXIST MCRRegCOMComponent.exe (

MCRRegCOMComponent.exe singKalman14_1_0.dll?

) ELSE (

regsvr32 singKalman14_1_0.dll?

)

echo Installation complete.

echo Please refer to the documentation for any additional setup steps.

?

echo off

rem echo Deploying project singSubImgPro10, version 1.0.

rem IF EXIST MCRInstaller.exe (

rem echo Running MCRInstaller

rem MCRInstaller.exe

rem )

rem echo Registering the component...

rem IF EXIST MCRRegCOMComponent.exe (

rem MCRRegCOMComponent.exe singSubImgPro10_1_0.dll?

rem ) ELSE?

(

regsvr32 singSubImgPro10_1_0.dll?

)

rem是注释的意思。

脚步文件运行注册bat是一样的,

;bat 文件

Section StartPro

?ExecWait $INSTDIR\Two_install.bat

SectionEnd

?

五)脚步文件注册DLL

Section Regdll

??RegDLL $INSTDIR\MFC42D.DLL

SectionEnd

?

Section Regdll

??RegDLL $INSTDIR\MSVCRTD.DLL

SectionEnd

?

Section Regdll

??RegDLL $INSTDIR\FreeImage.dll

SectionEnd

?

Section Regdll

??RegDLL $INSTDIR\ImagePro.dll

SectionEnd

?

Section Regdll

??RegDLL $INSTDIR\Utility.dll

SectionEnd

?

打包程序中安装部分基本完成,卸载部分基本都是默认的。

不过,有些com卸载不了,也可装自己写个bat,在卸载的时候加上运行即可。

比如,卸载的com的bat。

echo off

IF EXIST MCRInstaller.exe (

echo unRunning MCRInstaller

InstallUtil.exe -u MCRInstaller.exe

?

)

echo Registering the component...

IF EXIST MCRRegCOMComponent.exe (

InstallUtil.exe -u MCRRegCOMComponent.exe singKalman14_1_0.dll

) ELSE (

regsvr32??-u singKalman14_1_0.dll?

)

echo Unstallation complete.

echo Please refer to the documentation for any additional setup steps.

?

?基本ok了,其他的每太研究。

?

?

?

?

转自:http://hi.baidu.com/liyy011/blog/item/876c01b0f8a458470823021b.html

读书人网 >软件开发

热点推荐