大网数据广告活动
安装更新与部署

Accessing the Current Installer Session from Inside a Custom Action

· 52CE 我爱测

Nondeferred custom actions that call dynamic-link libraries or scripts may access a running installation to query or modify the attributes of the current installation session.

Nondeferred custom actions that call dynamic-link libraries or scripts may access a running installation to query or modify the attributes of the current installation session. Only one Session object can exist for each process, and custom action scripts must not attempt to create another session.

Custom actions can only add, modify, or remove temporary rows, columns, or tables from a database. Custom actions cannot modify persistent data in a database, for example, data that is a part of the database stored on disk.

Dynamic-Link Libraries

To access a running installation, custom actions that call dynamic-link libraries (DLL) are passed a handle of the type MSIHANDLE for the current session as the only argument to the DLL entry point named in the Target column of the CustomAction Table. Because the installer provides this handle, the custom action should not close it, for example, to receive the handle hInstall from the installer, the custom action function is declared as follows.

UINT __stdcall CustomAction(MSIHANDLE hInstall)

For read-only access to the current database obtain the database handle by calling MsiGetActiveDatabase. For more information, see Obtaining a Database Handle.

Scripts

Custom actions written in VBScript or JScript can access the current installation session by using the Session Object. The installer creates a Session object named "Session" that references the current installation. For read-only access to the current database use the Database property of the Session object.

Because a script is run from the context of the Session object, it is not always necessary to fully qualify properties and methods. In the following example, when using VBScript, the Me reference can replace the Session object, for example, the following three lines are equivalent.

Session.SetInstallLevel 1
Me.SetInstallLevel 1
SetInstallLevel 1

Executable Files

You cannot access the current installer session from custom actions that call executable files launched with a command-line, for example, Custom Action Type 2 and Custom Action Type 18.

Deferred Execution Custom Actions

You cannot access the current installer session or all property data from a deferred execution custom action. For more information, see Obtaining Context Information for Deferred Execution Custom Actions.

Related topics

Accessing a Database or Session from Inside a Custom Action

Source: Microsoft Learn / Windows Win32 documentation by Microsoft and contributors. Documentation licensed CC BY 4.0. Code samples are covered by the MIT License. Converted from Markdown, with links normalized and embedded media omitted.

资料来源与适用范围

资料来源
Microsoft Learn / Windows Win32 documentation
适用范围
Windows Win32 API · Source date 05/31/2018
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY 4.0 (documentation), MIT (code samples)

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。