force reboot after custom action - Advanced Installer Community

We’re moving our forums to a new platform.

You can still browse and search existing topics, but you can no longer create new topics or post replies.

For questions, technical issues, or feature requests, please don’t hesitate to contact our support team at support@advancedinstaller.com.

Thank you for your understanding!

Stardraw
Posts: 14
Joined: Thu Oct 16, 2008 12:39 pm

force reboot after custom action

I have a custom action that runs a 3rd party exe that installs a device driver.
It may return an error code of -17 if the system needs to be rebooted.
I would like to catch this error code and set the REBOOT flag appropriately.
How do I do this?
Cosmin
Posts: 5797
Joined: Tue Jul 10, 2007 6:39 pm
Contact: Website

Re: force reboot after custom action

Hi,

Unfortunately Windows Installer does not support a way of handling the return codes of the custom actions (they are handled automatically). Therefore, what you need can be done by handling the return code of the third party EXE inside a custom action.

In a C++ DLL you can use the ShellExecuteEx function to launch the EXE and the GetExitCodeProcess function to get its return code. If the return code is -17, you can use the MsiSetProperty function to set the REBOOT property to "Force".

Regards,
Cosmin
Cosmin Pirvu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
Stardraw
Posts: 14
Joined: Thu Oct 16, 2008 12:39 pm

Re: force reboot after custom action

From within my Custom Action DLL, how do I find out where the application has been installed to?
I need to do a ShellExecute on an exe that has been copied to the APPDIR.
Cosmin
Posts: 5797
Joined: Tue Jul 10, 2007 6:39 pm
Contact: Website

Re: force reboot after custom action

Hi,

Inside the custom action you can use the MsiGetProperty function to get the value of APPDIR. To this value you can append the name of the EXE you want to launch in order to obtain a complete file path.

Regards,
Cosmin
Cosmin Pirvu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
Stardraw
Posts: 14
Joined: Thu Oct 16, 2008 12:39 pm

Re: force reboot after custom action

I'm seeing a strange problem when I try to set the REBOOT property:

res = ::MsiSetProperty(hInstall, _T("REBOOT"), _T("Force"));

res is set to 6 (ERROR_INVALID_HANDLE)

Interestingly, hInstall is also 6 when the entrypoint in the DLL is called.
This could be a coincidence, but MsiSetProperty should not be returning 6.
What am I doing wrong?
Cosmin
Posts: 5797
Joined: Tue Jul 10, 2007 6:39 pm
Contact: Website

Re: force reboot after custom action

Hi,

Please make sure that your custom action is written correctly. The User Guide contains some sample code which may help you. Basically, the function which is being called from the MSI should look like this:

Code: Select all

UINT __stdcall FunctionName(MSIHANDLE hInstall) 
{
  // code implementation

  return ERROR_SUCCESS;
}
Regards,
Cosmin
Cosmin Pirvu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
Stardraw
Posts: 14
Joined: Thu Oct 16, 2008 12:39 pm

Re: force reboot after custom action

This is my code...

UINT ShowError(LPTSTR caption, UINT res) {

DWORD error = ::GetLastError();

_TCHAR buffer[1024];

wsprintf(buffer, "An error occured during installation : %d, %x", error, res);

MessageBox(NULL, buffer, caption, MB_OK);

return 1;
}

UINT __stdcall InstallHasp(MSIHANDLE hInstall)
{
TCHAR szDirectory[PIDKEY_LENGTH];
DWORD dwLen = sizeof(szDirectory) / sizeof(szDirectory[0]);

UINT res = 0;

ShowhInstall(hInstall);

res = ::MsiGetProperty(hInstall, _T("CustomActionData"), szDirectory, &dwLen);

if (res != ERROR_SUCCESS)
return ShowError(_T("Installing Hasp Driver - could not get APPDIR"), res);

strcat(szDirectory, _T("Hasp\\"));

MessageBox(NULL, szDirectory, "InstallHasp", MB_OK);

SHELLEXECUTEINFO info;
ZeroMemory(&info, sizeof(info));
info.cbSize = sizeof(info);
info.fMask = SEE_MASK_NOCLOSEPROCESS;
info.lpDirectory = szDirectory;
info.lpFile = _T("hinstall.exe");
info.lpParameters = _T("-i -kp -nomsg");

MessageBox(NULL, "About to ShellExecute", "HaspInstall", MB_OK);

if (::ShellExecuteEx(&info)) {

DWORD exitCode = 0;

MessageBox(NULL, "About to GetExitCodeProcess", "HaspInstall", MB_OK);

if (::GetExitCodeProcess(info.hProcess, &exitCode)) {

::CloseHandle(info.hProcess);

if (exitCode != 0) {

TCHAR buffer[1024];

wsprintf(buffer, "Need to set REBOOT FLAG, ExitCode = %d", exitCode);

MessageBox(NULL, buffer, "HaspInstall", MB_OK);

ShowhInstall(hInstall);

res = ::MsiSetProperty(hInstall, _T("REBOOT"), _T("Force"));

if (res != ERROR_SUCCESS)
return ShowError(_T("Installing Hasp Driver1"), res);
}
} else
return ShowError(_T("Installing Hasp Driver2"));
} else
return ShowError(_T("Installing Hasp Driver3"));

return 0;
}

I am getting a MessageBox(NULL, "An error occured during installation : 0, 6", "Installing Hasp Driver1", MB_OK);
Stardraw
Posts: 14
Joined: Thu Oct 16, 2008 12:39 pm

Re: force reboot after custom action

So what am I doing wrong?
Why would ::MsiSetProperty return Invalid Handle?
Cosmin
Posts: 5797
Joined: Tue Jul 10, 2007 6:39 pm
Contact: Website

Re: force reboot after custom action

Hi,

Since the handle is the same in the entire custom action ("hInstall"), most likely there is a problem with the way you call the custom action. Can you please send us the AIP (project) file you are using to support at advancedinstaller dot com so we can investigate it?

Regards,
Cosmin
Cosmin Pirvu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

Return to “Common Problems”