给Windows Installer添加Custom Action

Windows Installer的Custom Action可以是exe, dll, vbs或js文件。

通过这个Custom Action,只要有足够的权限,基本上想做什么就做什么。

用C++编写Custom Action的例子(省略建各种工程的步骤):

1.EXE

(1).C++代码,Console Application。其中可以通过MsiDoAction调用一些别的Action。目前并没有了解。

通常通过Windows Installer 的Property来进行数据共享。

 1  #include  < windows.h >
 2  #include  < Msiquery.h >
 3  #include  < stdio.h >
 4  #pragma  comment(lib, "msi.lib")
 5 
 6  int  main( int  argc,  char   * argv[])
 7  {
 8      printf( " This is a custom action " );
 9      getchar();
10       // MsiOpenPackage();
11       // MsiDoAction();
12       // MsiCloseHandle();
13       return  ERROR_SUCCESS;
14  }

(2).在部署项目的File System View中新建一个文件夹,并将此exe添加到该文件夹中。

(3).在Custom Actions View中添加Custom Action,选择该exe。

也可以将这多个项目集中到一个解决方案中,通过添加项目的Primary Output来进行添加。

在exe文件中,是无法获取当前installer的session的,只能通过DLL或script来操作当前installer,参考[4]。

 

2.DLL

(1)新建一个空的DLL项目。添加如下代码

 1  extern   " C "
 2  {
 3  #include  < windows.h >
 4  #include  < msi.h >
 5  #include  < Msiquery.h >
 6  #pragma  comment(lib, "msi.lib")
 7 
 8      __declspec(dllexport) UINT __stdcall FirstAction(MSIHANDLE hInstall)
 9      {
10          MessageBox( 0 , TEXT( "message " ), TEXT( " caption " ), MB_OK);
11           return  ERROR_SUCCESS;
12      }
13  };

(2)将此DLL添加到CustomAction,然后在EntryPoint指定为FirstAction。

最初的代码根据[7]编写,原文手工编写了def文件,我使用了dllexport省去了这一步,但是原文没有加extern,导致找不到FirstAction。

然后发现[6]中有这样一个Note:

For DLLs created using Visual C++, entry points must be defined using the extern keyword in order to be visible to Windows Installer. For more information, see Using extern to Specify Linkage

参考:

1.Visual Studio Setup - projects and custom actions 

2.Walkthrough: Creating a Custom Action

3.Custom Actions

4.Accessing the Current Installer Session from Inside a Custom Action

5.Dynamic-Link Libraries

6.Unspecified module entry point for custom action '<name>'

7.http://www.flexerasoftware.com/webdocuments/PDF/dlls-for-ipwi.pdf

8.Using extern to Specify Linkage

转载于:https://www.cnblogs.com/lbsx/archive/2010/10/08/1846081.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值