在Basic MSI 和InstallScript MSI工程中,推迟,提交,回滚的自定义操作(Custom Actions)只能访问有限的几个windows安装属性:CustomActionData, ProductCode, 和UserSID。
如果你想在推迟/提交/回滚的自定义操作中,访问一些其他的windows属性,可以将需要访问的属性传递给CustomActionData,然后获取CustomActionData的值。
下面是一个在推迟自定义操作中,访问windows安装属性SUPPORTDIR的例子:
1. 在Custom Actions and Sequences中创建一个set-a-property的自定义操作叫GetSUPPORTDIR。如下设置这个自定义操作,
・ Property Name: DisplaySupportDir
・ Property Value: [SUPPORTDIR]
function DisplaySupportDir(hMSI)
STRING supportDirPath;
NUMBER supportDirPathBuffer;
begin
supportDirPathBuffer = MAX_PATH;
if(MsiGetProperty(hMSI, "CustomActionData", supportDirPath, supportDirPathBuffer) == ERROR_SUCCESS) then
SprintfBox(INFORMATION,"Deferred Execution","The value of SUPPORTDIR is %s",supportDirPath);
SprintfBox(INFORMATION,"Deferred Execution","The value of InstallScript's SUPPORTDIR is %s",SUPPORTDIR);
endif;
・ In-Script Execution: Deferred Execution in System Context
如果你想在推迟/提交/回滚的自定义操作中,访问一些其他的windows属性,可以将需要访问的属性传递给CustomActionData,然后获取CustomActionData的值。
下面是一个在推迟自定义操作中,访问windows安装属性SUPPORTDIR的例子:
1. 在Custom Actions and Sequences中创建一个set-a-property的自定义操作叫GetSUPPORTDIR。如下设置这个自定义操作,
・ Property Name: DisplaySupportDir
・ Property Value: [SUPPORTDIR]
・ Install Exec Sequence: After InstallInitialize
2. 在InstallScript中,创建一个新的函数叫DisplaySupportDir。
function DisplaySupportDir(hMSI)
STRING supportDirPath;
NUMBER supportDirPathBuffer;
begin
supportDirPathBuffer = MAX_PATH;
if(MsiGetProperty(hMSI, "CustomActionData", supportDirPath, supportDirPathBuffer) == ERROR_SUCCESS) then
SprintfBox(INFORMATION,"Deferred Execution","The value of SUPPORTDIR is %s",supportDirPath);
SprintfBox(INFORMATION,"Deferred Execution","The value of InstallScript's SUPPORTDIR is %s",SUPPORTDIR);
endif;
end;
4. 在Custom Actions and Sequences中创建一个InstallScript的自定义操作叫DisplaySupportDir。如下设置这个自定义操作,
・ Function Name: DisplaySupportDir・ In-Script Execution: Deferred Execution in System Context
・ Install Exec Sequence: After GetSUPPORTDIR