问题
I am new to WiX installer. I need to Hide or disable the cancel button in WIX installer when progress bar is running.
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?
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.
Open visual studio -> Create new project -> custom action in C++ selected and select type DLL.
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;
}
This is the .def file code:
LIBRARY "HideCancelButton"
EXPORTS
HideCancelButton
Now i build the project and it's created the HideCancelButton.dll file.
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>
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.
回答1:
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.
How to hide the Cancel button during an MSI installation?
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 (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"
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 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:
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
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>
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.
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?
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.
来源:https://stackoverflow.com/questions/51893497/how-to-hide-or-disable-cancel-button-in-wix-installer