NayanPatel
Posts: 3
Joined: Mon Jan 05, 2009 7:44 pm

Custom Action in Vista silently fails

Hi I am using Enterprise Ed of Advanced Installer.

I have a custom action which runs VB script (It writes some info to registry). Everything works fine on XP and win2003 but in Vista it silently fails even though I am logged in as administrator and running msi file under my login.

The only way I was able to get it working in vista if I run msi file using
• Start->Accessories ->Command Prompt …. Right click and select “Run As Administrator” option
• Enter full path of msi and hit enter to start setup.

But as you see user won’t know this approach because it’s not well known. I want some setting in the setup itself will ask for Admin Permission at runtime so it can write to registry????

I also tried following solutions but none of them worked

1. Created Custom action "Launch File As Administrator" under "UI Custom Action" and then called that action on Installation Dialog editor --> "Published Events" -> DoAction
<DIDN'T WORK>

2. Change Media -> Bootstrapper -> Security -> "Require Admin"
<DIDN'T WORK>

None of above solution elevating access to Admin Level and because of thet my VB script fails.

Please advice if there is a setting somewhere in Advanced Installer which is same as "Run As Administrator" found when you right click on exe file in Vista????

Thanks,
Nayan
NayanPatel
Posts: 3
Joined: Mon Jan 05, 2009 7:44 pm

Re: Custom Action in Vista silently fails

Ok I was able to fix my issue by doing the following settings

Create custom action (run vb script)

Make sure you change "Execution option" to "Deferred with no impersonation"
and

On Media -> Boot straper ->Secrity -> Change "Require Admin"
Cosmin
Posts: 5797
Joined: Tue Jul 10, 2007 6:39 pm
Contact: Website

Re: Custom Action in Vista silently fails

Hi,

On Windows Vista a custom action is not elevated by default, so it will not run with Administrator privileges. However, if the custom action runs without impersonation it will use the local system account to obtain full privileges.

Regards,
Cosmin
Cosmin Pirvu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
cbono
Posts: 42
Joined: Thu Aug 14, 2008 10:11 pm

Re: Custom Action in Vista silently fails

I think I'm having a similar issue. I'm trying to use the code example for creating a mutually-exclusive Feature selection dialog ( http://www.advancedinstaller.com/user-g ... ature.html ). I can run this successfully on my own machines (I have Windows XP Pro and Vista Business), but another user with Vista Ultimate cannot run it.

Looking through the log file, I see this regarding the execution of my Custom Action ("SetFeatureStates"):

Code: Select all

MSI (c) (9C:44) [12:38:17:862]: Doing action: SetFeatureStates
Action 12:38:17: SetFeatureStates. 
Action start 12:38:17: SetFeatureStates.
Action ended 12:38:17: SetFeatureStates. Return value 3.
DEBUG: Error 2896:  Executing action SetFeatureStates failed.
The installer has encountered an unexpected error installing this package. This may indicate a problem with this package. The error code is 2896. The arguments are: SetFeatureStates, , 
Action ended 12:38:17: WelcomeDlg. Return value 3.
I wanted to try the solution presented by NayanPatel, but it seems that custom actions assigned to the "UI Custom Actions" category cannot be executed as anything except "Immediate Execution."

I've also tried running the .MSI package as Administrator, and invoking the MSI via an elevated Command Prompt. In both cases, the result is exactly the same. I don't understand why I can get this to work on 1 Vista instance and not another.

Sure hope you can shed some light on this.
cbono
Posts: 42
Joined: Thu Aug 14, 2008 10:11 pm

Re: Custom Action in Vista silently fails

After doing some more research on the issue, and finding references to blog posts written by Microsoft employees who *strongly* discourage the use of Windows scripting for Custom Actions (see http://www.advancedinstaller.com/forums ... f=2&t=8149 for relevant links), I decided to try my hand at writing a C++ DLL to do the same thing the VBScript was doing.

Same configuration ... attached the DLL as a Custom Action to "UI Custom Actions" and then set the relevant Dialog's "Next>" button to trigger the custom action. Same results as with the VBScript: works on XP, but does not work on Vista. Here's the snippet from my debug log:

Code: Select all

MSI (c) (04:D0) [18:04:24:649]: Doing action: FeatureStateSetter.dll
Action 18:04:24: FeatureStateSetter.dll. 
Action start 18:04:24: FeatureStateSetter.dll.
MSI (c) (04:18) [18:04:24:680]: Invoking remote custom action. DLL: C:\Users\cbono\AppData\Local\Temp\MSIC3A3.tmp, Entrypoint: SetFeatureState
Action ended 18:04:24: FeatureStateSetter.dll. Return value 3.
DEBUG: Error 2896:  Executing action FeatureStateSetter.dll failed.
The installer has encountered an unexpected error installing this package. This may indicate a problem with this package. The error code is 2896. The arguments are: FeatureStateSetter.dll, , 
Action ended 18:04:24: WelcomeDlg. Return value 3.
Keep in mind I have also sprinkled several debug calls in my DLL to display a message box at various stages of the DLL's execution. No message boxes are displayed, leading me to conclude that the DLL is not even executed.

What's going on here? I get no useful output from this process to help me understand what is failing and why. Let me know if you need more information. I'm happy to provide the AIP file and the DLL source code.

Just want to get to the bottom of this...

-Chris
Cosmin
Posts: 5797
Joined: Tue Jul 10, 2007 6:39 pm
Contact: Website

Re: Custom Action in Vista silently fails

Hi Chris,

I'm not sure why the custom action fails on Vista. Can you please send us the AIP file you are using to support at advancedinstaller dot com so we can investigate it? Also, please attach the full verbose log of the install process.

Regards,
Cosmin
Cosmin Pirvu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
cbono
Posts: 42
Joined: Thu Aug 14, 2008 10:11 pm

Re: Custom Action in Vista silently fails

Okay, I sent you the files.

I sent install logs from 2 different Vista machines. As I mentioned earlier, the VBS custom action worked fine in my Vista environment, but failed in a co-worker's. However, the DLL custom action fails in both our environments.

Please let me know if there's any additional information I can provide.

-Chris
Ionut
Posts: 605
Joined: Tue Nov 22, 2005 11:29 am
Contact: Website

Re: Custom Action in Vista silently fails

Hi Chris,

Most likely this problem is due to a dependency issue, because the Custom Action worked correctly on my development machine. I have noticed that the DLL you have sent has a dependency on "MSVCR90D.dll" (the debug version of the VC 2008 runtime library), which might not be present on the systems on which you are testing the package on.

I would suggest statically linking to the VC runtime library by selecting the option "Multi-threaded (/MT)" (and respectively "Multi-threaded Debug (/MTd)") for the "Runtime Library" setting in the "C/C++ \ Code Generation" page of the project properties dialog in VC++ 2008.

Let me know if this solves the problem.

Regards,
Ionut
Denis Toma
Advanced Installer Team
http://www.advancedinstaller.com/
cbono
Posts: 42
Joined: Thu Aug 14, 2008 10:11 pm

Re: Custom Action in Vista silently fails

Hi Ionut,

Yes, that turned out to be the problem. As you can probably tell, C++ is not my forte. Thank you so much for helping me with this; I was able to run successful tests on both Vista environments and it seems to be solid.

For anyone else who is interested in adapting a custom C++ DLL to replicate the functionality of the VBScript in the article ("How do I show a custom feature selection dialog?"), I am providing my solution. As you can see, it reads the value of a custom Property ("INSTALLTYPE"), and based on its value, it turns on either the "RunLocal" Feature or the "RunCD" Feature. I have a custom Dialog that presents 2 radio buttons to the user; the Radio Button Group is linked to the "INSTALLTYPE" property, and the indvidual radio buttons have values of "RunLocal" and "RunCD" -- named after their corresponding Features. Should be easily adaptable to your own Features/Properties.

A zipped Visual Studio 2008 project is available at:
http://www.box.net/shared/x0zahcase7

Here's the source code for what I call the FeatureStateSetter:

Code: Select all

#include "stdafx.h"

BOOL APIENTRY DllMain(HANDLE /*hModule*/, DWORD  /*ul_reason_for_call*/,
                      LPVOID /*lpReserved*/)
{
  return TRUE;
}


UINT __stdcall SetFeatureState(MSIHANDLE hInstall)
{
	
	UINT uiStatus = ERROR_SUCCESS;
	
	// INSTALLTYPE property & buffer length
	TCHAR* szInstallType = NULL;
	DWORD cchInstallTypeLen = 0;
		
	// Set the mutually-exclusive features to Absent
	MsiSetFeatureState(hInstall, _T("RunLocal"), INSTALLSTATE_ABSENT);
	MsiSetFeatureState(hInstall, _T("RunCD"), INSTALLSTATE_ABSENT);
		
	// Look up the property
	uiStatus = MsiGetProperty(hInstall, _T("INSTALLTYPE"), _T(""), &cchInstallTypeLen);
	if (ERROR_MORE_DATA == uiStatus) {
        
        // Initialize length and buffer
        ++cchInstallTypeLen; // on output does not include terminating null, so add 1
        szInstallType = new TCHAR[cchInstallTypeLen];
        
        // Perform real lookup for property
        if (szInstallType) {
            uiStatus = MsiGetProperty(hInstall, _T("INSTALLTYPE"), szInstallType, &cchInstallTypeLen);
        }
    }

	// Return if the property could not be retrieved
	if (uiStatus != ERROR_SUCCESS) {
		return 1;
	}
		
	// Turn on the corresponding feature
	int cmpResult = _tcscmp(szInstallType, _T("RunCD"));
	if (cmpResult == 0) {
		MsiSetFeatureState(hInstall, _T("RunCD"), INSTALLSTATE_LOCAL);
	}
	else {
		MsiSetFeatureState(hInstall, _T("RunLocal"), INSTALLSTATE_LOCAL);
	}
		
	return 0;
}
Obvious disclaimer: I'm am amateur C++ coder, so use this at your own risk!

-Chris

Return to “Common Problems”