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

Hiding the Cancel Button During an Installation

· 52CE 我爱测

You can hide the Cancel button that is used to cancel an installation by using a command-line option, the Windows Installer API, or a custom action. The Cancel button can be hidden for part or all of the installation depending on which method you use.

You can hide the Cancel button that is used to cancel an installation by using a command-line option, the Windows Installer API, or a custom action. The Cancel button can be hidden for part or all of the installation depending on which method you use.

Hiding the Cancel Button from the Command Line

The Cancel button can be hidden during installation by using the (!) command-line option. This can only be done for a basic user interface level installation (/qb). The Cancel button is hidden for the entire installation. For more information, see Command-Line Options and User Interface Levels. The following command line hides the Cancel button and installs Example.msi.

msiexec /I example.msi /qb!

Hiding the Cancel Button from an Application or Script

You can write an application or script to hide the Cancel button. This can only be done for a basic UI level installation so that the Cancel button is hidden for the entire installation.

To hide the Cancel button from an application, set INSTALLUILEVEL_HIDECANCEL when calling MsiSetInternalUI. The following example hides the Cancel button and installs Example.msi.

#include <windows.h>
#include <stdio.h>
#include <Shellapi.h>
#include <msi.h>
#include <Msiquery.h>
#include <tchar.h>
#pragma comment(lib, "msi.lib")

int main()  
{

INSTALLUILEVEL uiPrevLevel = MsiSetInternalUI( INSTALLUILEVEL(INSTALLUILEVEL_BASIC | INSTALLUILEVEL_HIDECANCEL), 0); 
UINT uiStat = MsiInstallProduct(_T("example.msi"), NULL);

return 0;  
}

To hide the Cancel button from script, add msiUILevelHideCancel to the UILevel property of the Installer Object. The following VBScript sample hides the Cancel button and installs Example.msi.

Dim Installer As Object
Set Installer = CreateObject("WindowsInstaller.Installer")
Installer.UILevel = msiUILevelBasic + msiUILevelHideCancel
Installer.InstallProduct "example.msi"

Hiding the Cancel Button for Parts of an Installation Using a Custom Action

Your installation can hide and unhide the Cancel button during parts of an installation by sending an INSTALLMESSAGE_COMMONDATA message using a DLL custom action or scripts. For more information, see Dynamic-Link Libraries, Scripts, Custom Actions, and Sending Messages to Windows Installer Using MsiProcessMessage.

A call to a custom action must provide a record. Field 1 of this record must contain the value 2 (two) to specify the Cancel button. Field 2 must contain either the value 0 or 1. A value of 0 in Field 2 hides the button and a value of 1 in Field 2 unhides the button. Note that allocating a record of size 2 with MsiCreateRecord provides fields 0, 1, and 2.

The following sample DLL custom action hides the Cancel button.

#include <windows.h>
#include <stdio.h>
#include <Shellapi.h>
#include <msi.h>
#include <Msiquery.h>

UINT __stdcall HideCancelButton(MSIHANDLE hInstall)
{
    PMSIHANDLE hRecord = MsiCreateRecord(2);
    if ( !hRecord)
        return ERROR_INSTALL_FAILURE;

    if (ERROR_SUCCESS != MsiRecordSetInteger(hRecord, 1, 2)
     || ERROR_SUCCESS != MsiRecordSetInteger(hRecord, 2, 0))
        return ERROR_INSTALL_FAILURE;

    MsiProcessMessage(hInstall, INSTALLMESSAGE_COMMONDATA, hRecord);

    return ERROR_SUCCESS;
}

The following VBScript Custom Action hides the Cancel button.

Function HideCancelButton()

    Dim Record
    Set Record = Installer.CreateRecord(2)

    Record.IntegerData(1) = 2
    Record.IntegerData(2) = 0

    Session.Message msiMessageTypeCommonData, Record
 
    ' return success
    HideCancelButton = 1
    Exit Function

End Function

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)

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

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