如何在WIX安装程序中隐藏或禁用“取消”按钮? [英] How to hide or disable Cancel button in WIX Installer?

查看:149
本文介绍了如何在WIX安装程序中隐藏或禁用“取消”按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是WiX安装程序的新手。当进度条运行时,我需要在WIX安装程序中隐藏禁用 取消按钮

I am new to WiX installer. I need to Hide or disable the cancel button in WIX installer when progress bar is running.

我已经用Google搜索过,但是找不到隐藏取消按钮的有用链接。我发现了这一点: 在安装过程中隐藏取消按钮 ,但仍然不知道如何使用自定义操作。有没有人可以给我一些指导以实现这一目标?

I have googled but did not find some useful link to hide the cancel button. I found this: Hiding the Cancel Button During an Installation, but still have no idea how to use a custom action. Is there anyone who can give me some guidance to achieve this?

我已经完成了以下操作,以隐藏取消按钮,但它不起作用。
首先,我根据上面提到的链接用C ++编写了一个自定义动作。让我展示一下我为自定义操作所做的事情。

I have done the following things to hide the cancel button but it's not working. First of all, i have written a custom action in C++ according to mentioned link above. Let me show what i did for custom action.

打开Visual Studio->创建新项目->在C ++中选择自定义操作,然后选择DLL类型。

Open visual studio -> Create new project -> custom action in C++ selected and select type DLL.

它将使用cpp文件创建一个新项目。我将cpp文件命名为自定义操作,并编写了以下代码:

It will create a new project with cpp file. I named the cpp file as custom action and write the below code:

#include "stdafx.h"
#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;
}


// DllMain - Initialize and cleanup WiX custom action utils.
extern "C" BOOL WINAPI DllMain(
    __in HINSTANCE hInst,
    __in ULONG ulReason,
    __in LPVOID
    )
{
    switch(ulReason)
    {
    case DLL_PROCESS_ATTACH:
        WcaGlobalInitialize(hInst);
        break;

    case DLL_PROCESS_DETACH:
        WcaGlobalFinalize();
        break;
    }

    return TRUE;
}

这是.def文件代码:

This is the .def file code:

LIBRARY "HideCancelButton"

EXPORTS
    HideCancelButton

现在我构建项目,并创建了HideCancelButton.dll文件。

Now i build the project and it's created the HideCancelButton.dll file.

现在进入我的WIX项目。
添加自定义操作:

Now come to my WIX project. Add custom action:

 <Binary Id="HideCancelButtonDll" SourceFile="C:\Users\umer\Desktop\HideCancelButton.dll"/>
    <CustomAction Id="CAhidecancel" BinaryKey="HideCancelButtonDll" Execute="immediate" Impersonate="no" DllEntry="HideCancelButton" Return="check"/>

在安装执行顺序中添加以下行

Add following line in install execution sequence

 <Custom Action='CAhidecancel' Before='CreateSSISCatalog'></Custom>

这是我所做的全部,但没有用。我检查了日志,它显示返回值为1。但是仍然显示取消按钮。要检查函数是否正在调用,我将sleep(10000)放在安装程序上并显示状态,它按预期工作,但显示取消按钮。

That's all i have done but it's not working. I checked the log and it shows that return value is 1. But still cancel button is showing. To check whether function is calling or not i put sleep(10000) and show status on installer and it was working as expected but cancel button is showing.

推荐答案

隐藏取消按钮



您找到的链接最多可以找到权威。它说明了一切,但是让我在这里为任何发现此问题的未来用户进行总结。

Hiding Cancel Button

The link you found is the most authoritative that can be found. It says it all, but let me summarize here for any future user who finds this.

在这样做之前,我们必须问您为什么需要这个?它可能表明应该以其他方式解决该问题,以便正确避免。

Before doing so, we have to ask why you need this? It might indicate a problem that should be solved in some other way to be avoided properly.

如何在MSI安装过程中隐藏取消按钮?

How to hide the Cancel button during an MSI installation?


  1. msiexec.exe: 您可以使用 安装来隐藏 取消 按钮。在执行基本用户界面级别安装时,指定了strong>命令行选项: msiexec.exe / I Setup.msi / QB-! 。您可以将批处理文件与MSI一起交付,以这种方式进行安装,或在分发系统(SCCM或类似系统)中对其进行配置。

  1. msiexec.exe: You can hide the Cancel button by installing with the ! command line option specified when doing a basic user interface level installation: msiexec.exe /I Setup.msi /QB-!. You can deliver a batch file along with your MSI to install like this, or configure it in your distribution system (SCCM or similar).

Windows Installer API (在MSI外部运行):您可以通过 MSI API COM自动化(VBScript和其他脚本)或 MSI API Win32安装程序功能(C ++)。这里是VBScript:

Windows Installer API (running outside MSI): You can invoke the installation via MSI API COM automation (VBScript & other scripts) or MSI API Win32 installer functions (C++). Here VBScript:

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


  • 自定义操作 (在MSI中运行):您可以在实际安装文件的过程中通过发送隐藏取消按钮 INSTALLMESSAGE_COMMONDATA 消息:

  • Custom Action (running inside MSI): You can hide the Cancel button during the actual file copy of the installation by sending an INSTALLMESSAGE_COMMONDATA message:

    Dim rec : Set rec = Installer.CreateRecord(2)
    rec.IntegerData(1) = 2
    rec.IntegerData(2) = 0
    Session.Message 184549376, rec
    







  • WiX标记示例



    自切成薄片以来,这并不是最大的事情,但是这里有一些快速的WiX标记片段,可以插入到您的WiX源中。我会再看一遍,但是您可以尝试一下:


    WiX Sample Markup

    Not the greatest thing since sliced bread, but here are some quick WiX markup snippets to insert into your WiX source. I'll have one more look at this, but you can give it a try:

    您需要编译到WiX MSI中的实际VBScript(与上面相同) 。另存为 HideCancel.vbs

    The actual VBScript that you need to compile into your WiX MSI (same as above). Save as HideCancel.vbs:

    Dim rec : Set rec = Installer.CreateRecord(2)
    rec.IntegerData(1) = 2
    rec.IntegerData(2) = 0
    Session.Message 184549376, rec
    

    以及实际的WiX标记(插入到您的主要WiX项目中):

    And the actual WiX markup (insert into your main WiX project):

    <Binary Id='HideCancel.vbs' SourceFile='HideCancel.vbs' />
    <CustomAction Id='HideCancel.vbs' VBScriptCall='' BinaryKey='HideCancel.vbs' 
                  Execute='immediate' Return='ignore'/>
    
    <!-- You can leave out this element -->
    <InstallUISequence>
      <Custom Action='HideCancel.vbs' Before='AppSearch' />
    </InstallUISequence>
    
    <!-- Required element -->
    <InstallExecuteSequence>
      <Custom Action='HideCancel.vbs' Before='AppSearch' />
    </InstallExecuteSequence>
    

    如果您遇到 Before ='AppSearch',也许尝试使用 Before ='LaunchConditions' Before ='FindRelatedProducts'。严格来说,您似乎不需要上面的 InstallUISequence 元素。

    If you get problems with Before='AppSearch', maybe try with Before='LaunchConditions' or Before='FindRelatedProducts'. Strictly speaking you do not need the InstallUISequence element above it seems.

    令人惊讶的是,似乎无法禁用对话框向导中的取消按钮(不确定是否特定于WiX,也许不是),但是您可以将其隐藏在一旦安装程序实际运行文件复制或安装操作本身,则显示安装进度对话框-希望这是您所需要的吗?

    Astonishingly it seems it is not possible to disable the Cancel button in the dialog wizard (not sure if this is WiX specific, probably not), but you can hide it in the installation progress dialog once your setup is actually running the file copy or installation operation itself - which is hopefully what you need?

    如果您还想禁用设置向导对话框中的 取消 按钮,那么您需要修改WiX对话框控件,这需要做更多工作。 FireGiant教程 UI向导 已重新访问用户界面

    If you also want to disable the Cancel button in the setup wizard dialogs, then you need to modify the WiX dialog controls, which is more work. FireGiant tutorials: UI Wizardry and User Interface Revisited.

    这篇关于如何在WIX安装程序中隐藏或禁用“取消”按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆