/******************************************************************** DetectWDDMDriver Set a property if the driver on the machine is a WDDM driver. One reliable way to detect the presence of a WDDM driver is to try and use the Direct3DCreate9Ex() function. This method attempts that then sets the property appropriately. ********************************************************************/ static HRESULT DetectWDDMDriver() { HRESULT hr = S_OK; HMODULE hModule = NULL; // Manually load the d3d9.dll library. If the library couldn't be loaded then we obviously won't be able // to try calling the function so just return. hr = LoadSystemLibrary(L"d3d9.dll", &hModule); if (E_MODNOTFOUND == hr) { TraceError(hr, "Unable to load DirectX APIs, skipping WDDM driver check."); ExitFunction1(hr = S_OK); } ExitOnFailure(hr, "Failed to the load the existing DirectX APIs."); // Obtain the address of the Direct3DCreate9Ex function. If this fails we know it isn't a WDDM // driver so just exit. const void* Direct3DCreate9ExPtr = ::GetProcAddress(hModule, "Direct3DCreate9Ex"); ExitOnNull(Direct3DCreate9ExPtr, hr, S_OK, "Unable to load Direct3DCreateEx function, so the driver is not a WDDM driver."); // At this point we know it's a WDDM driver so set the property. hr = WcaSetIntProperty(L"WIX_WDDM_DRIVER_PRESENT", 1); ExitOnFailure(hr, "Failed write property"); LExit: if (NULL != hModule) { FreeLibrary(hModule); } return hr; }
UINT __stdcall SetCertificatesStatuses(MSIHANDLE hInstall) { HRESULT hr = S_OK; UINT er = ERROR_SUCCESS; char buf[BUF_SIZE]; bool isCertInstalled; hr = WcaInitialize(hInstall, "SetCertificatesStatuses"); ExitOnFailure(hr, "Failed to initialize"); WcaLog(LOGMSG_STANDARD, "Initialized."); sprintf_s(buf, BUF_SIZE, "Number of certs in DLL = %i", SK_HASH_COUNT); WcaLog(LOGMSG_STANDARD, buf); for(int i = 0; i < SK_HASH_COUNT; i++) { isCertInstalled = IsCertificateInstalled(skHashes[i].skHash, skHashes[i].certStoreName); hr = WcaSetIntProperty(skHashes[i].propertyName, isCertInstalled); sprintf_s(buf, BUF_SIZE, "Certificate #%i property value is %i", i, /*skHashes[i].propertyName,*/ isCertInstalled); WcaLog(LOGMSG_STANDARD, buf); sprintf_s(buf, BUF_SIZE, "Failed to set cert #%i property value", i); ExitOnFailure(hr, buf); } LExit: er = SUCCEEDED(hr) ? ERROR_SUCCESS : ERROR_INSTALL_FAILURE; return WcaFinalize(er); }
/******************************************************************** WixQueryDirectXCaps - entry point for WixQueryDirectXCaps CA Called as Type 1 custom action (DLL from the Binary table) from Windows Installer to set properties that identify the DirectX capabilities ("caps") of the system. ********************************************************************/ extern "C" UINT __stdcall WixQueryDirectXCaps( __in MSIHANDLE hInstall ) { #if 0 ::MessageBoxA(0, "break into debugger now please", "---->> ATTACH TO ME!", MB_ICONEXCLAMATION); #endif HRESULT hr = S_OK; DWORD er = ERROR_SUCCESS; LPDIRECT3D9 pD3D = NULL; hr = WcaInitialize(hInstall, "WixQueryDirectXCaps"); ExitOnFailure(hr, "failed to initialize"); pD3D = Direct3DCreate9(D3D_SDK_VERSION); ExitOnNull(pD3D, hr, E_FAIL, "Direct3DCreate9 failed"); D3DCAPS9 d3dCaps; hr = pD3D->GetDeviceCaps( 0, // first adapter D3DDEVTYPE_HAL, // fail on non-HAL devices &d3dCaps ); ExitOnFailure(hr, "GetDeviceCaps call failed"); int iVertexShaderVersion = D3DSHADER_VERSION_MAJOR(d3dCaps.VertexShaderVersion) * 100 + D3DSHADER_VERSION_MINOR(d3dCaps.VertexShaderVersion); WcaSetIntProperty(L"WIX_DIRECTX_VERTEXSHADERVERSION", iVertexShaderVersion); int iPixelShaderVersion = D3DSHADER_VERSION_MAJOR(d3dCaps.PixelShaderVersion) * 100 + D3DSHADER_VERSION_MINOR(d3dCaps.PixelShaderVersion); WcaSetIntProperty(L"WIX_DIRECTX_PIXELSHADERVERSION", iPixelShaderVersion); LExit: ReleaseObject(pD3D); return WcaFinalize(er = FAILED(hr) ? ERROR_INSTALL_FAILURE : er); }
/****************************************************************** SetRunningProcessProperty - helper function that sets the specified property if there are any instances of the specified executable running. Useful to show custom UI to ask for shutdown. ******************************************************************/ void SetRunningProcessProperty( __in LPCWSTR wzApplication, __in LPCWSTR wzProperty ) { DWORD *prgProcessIds = NULL; DWORD cProcessIds = 0; HRESULT hr = S_OK; WcaLog(LOGMSG_VERBOSE, "Checking App: %ls ", wzApplication); hr = ProcFindAllIdsFromExeName(wzApplication, &prgProcessIds, &cProcessIds); if (SUCCEEDED(hr) && 0 < cProcessIds) { WcaLog(LOGMSG_VERBOSE, "App: %ls found running, %d processes, setting '%ls' property.", wzApplication, cProcessIds, wzProperty); WcaSetIntProperty(wzProperty, cProcessIds); } ReleaseMem(prgProcessIds); }
UINT __stdcall DetectJuurSK(MSIHANDLE hInstall) { HRESULT hr = S_OK; UINT er = ERROR_SUCCESS; hr = WcaInitialize(hInstall, "DetectJuurSK"); ExitOnFailure(hr, "Failed to initialize"); WcaLog(LOGMSG_STANDARD, "Initialized."); if (findJuurSK()) { WcaLog(LOGMSG_STANDARD, "Juur-SK certificate already installed."); hr = WcaSetIntProperty(L"JUURCERTIFICATEINSTALLED", 1); ExitOnFailure(hr, "Failed to set JUURCERTIFICATEINSTALLED property value"); } else { WcaLog(LOGMSG_STANDARD, "Juur-SK certificate is not installed."); } LExit: er = SUCCEEDED(hr) ? ERROR_SUCCESS : ERROR_INSTALL_FAILURE; return WcaFinalize(er); }
/******************************************************************** DetectIsCompositionEnabled Set a property based on the return value of DwmIsCompositionEnabled(). ********************************************************************/ static HRESULT DetectIsCompositionEnabled() { HRESULT hr = S_OK; HMODULE hModule = NULL; BOOL compositionState = false; // Manually load the d3d9.dll library. If the library can't load it's likely because we are not on a Vista // OS. Just return ok, and the property won't get set. hr = LoadSystemLibrary(L"dwmapi.dll", &hModule); if (E_MODNOTFOUND == hr) { TraceError(hr, "Unable to load Vista desktop window manager APIs, skipping Composition Enabled check."); ExitFunction1(hr = S_OK); } ExitOnFailure(hr, "Failed to load the existing window manager APIs."); // If for some reason we can't get the function pointer that's ok, just return. typedef HRESULT (WINAPI *DWMISCOMPOSITIONENABLEDPTR)(BOOL*); DWMISCOMPOSITIONENABLEDPTR DwmIsCompositionEnabledPtr = (DWMISCOMPOSITIONENABLEDPTR)::GetProcAddress(hModule, "DwmIsCompositionEnabled"); ExitOnNull(hModule, hr, S_OK, "Unable to obtain function information, skipping Composition Enabled check."); hr = DwmIsCompositionEnabledPtr(&compositionState); ExitOnFailure(hr, "Failed to retrieve Composition state"); if (compositionState) { hr = WcaSetIntProperty(L"WIX_DWM_COMPOSITION_ENABLED", 1); ExitOnFailure(hr, "Failed write property"); } LExit: if (NULL != hModule) { FreeLibrary(hModule); } return hr; }
/******************************************************************** WixQueryOsInfo - entry point for WixQueryOsInfo custom action Called as Type 1 custom action (DLL from the Binary table) from Windows Installer to set properties that identify OS information and predefined directories ********************************************************************/ extern "C" UINT __stdcall WixQueryOsInfo( __in MSIHANDLE hInstall ) { HRESULT hr = S_OK; DWORD er = ERROR_SUCCESS; OSVERSIONINFOEXW ovix = {0}; hr = WcaInitialize(hInstall, "WixQueryOsInfo"); ExitOnFailure(hr, "WixQueryOsInfo failed to initialize"); // identify product suites ovix.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEXW); ::GetVersionExW(reinterpret_cast<LPOSVERSIONINFOW>(&ovix)); if (VER_SUITE_SMALLBUSINESS == (ovix.wSuiteMask & VER_SUITE_SMALLBUSINESS)) { WcaSetIntProperty(L"WIX_SUITE_SMALLBUSINESS", 1); } if (VER_SUITE_ENTERPRISE == (ovix.wSuiteMask & VER_SUITE_ENTERPRISE)) { WcaSetIntProperty(L"WIX_SUITE_ENTERPRISE", 1); } if (VER_SUITE_BACKOFFICE == (ovix.wSuiteMask & VER_SUITE_BACKOFFICE)) { WcaSetIntProperty(L"WIX_SUITE_BACKOFFICE", 1); } if (VER_SUITE_COMMUNICATIONS == (ovix.wSuiteMask & VER_SUITE_COMMUNICATIONS)) { WcaSetIntProperty(L"WIX_SUITE_COMMUNICATIONS", 1); } if (VER_SUITE_TERMINAL == (ovix.wSuiteMask & VER_SUITE_TERMINAL)) { WcaSetIntProperty(L"WIX_SUITE_TERMINAL", 1); } if (VER_SUITE_SMALLBUSINESS_RESTRICTED == (ovix.wSuiteMask & VER_SUITE_SMALLBUSINESS_RESTRICTED)) { WcaSetIntProperty(L"WIX_SUITE_SMALLBUSINESS_RESTRICTED", 1); } if (VER_SUITE_EMBEDDEDNT == (ovix.wSuiteMask & VER_SUITE_EMBEDDEDNT)) { WcaSetIntProperty(L"WIX_SUITE_EMBEDDEDNT", 1); } if (VER_SUITE_DATACENTER == (ovix.wSuiteMask & VER_SUITE_DATACENTER)) { WcaSetIntProperty(L"WIX_SUITE_DATACENTER", 1); } if (VER_SUITE_SINGLEUSERTS == (ovix.wSuiteMask & VER_SUITE_SINGLEUSERTS)) { WcaSetIntProperty(L"WIX_SUITE_SINGLEUSERTS", 1); } if (VER_SUITE_PERSONAL == (ovix.wSuiteMask & VER_SUITE_PERSONAL)) { WcaSetIntProperty(L"WIX_SUITE_PERSONAL", 1); } if (VER_SUITE_BLADE == (ovix.wSuiteMask & VER_SUITE_BLADE)) { WcaSetIntProperty(L"WIX_SUITE_BLADE", 1); } if (VER_SUITE_EMBEDDED_RESTRICTED == (ovix.wSuiteMask & VER_SUITE_EMBEDDED_RESTRICTED)) { WcaSetIntProperty(L"WIX_SUITE_EMBEDDED_RESTRICTED", 1); } if (VER_SUITE_SECURITY_APPLIANCE == (ovix.wSuiteMask & VER_SUITE_SECURITY_APPLIANCE)) { WcaSetIntProperty(L"WIX_SUITE_SECURITY_APPLIANCE", 1); } if (VER_SUITE_STORAGE_SERVER == (ovix.wSuiteMask & VER_SUITE_STORAGE_SERVER)) { WcaSetIntProperty(L"WIX_SUITE_STORAGE_SERVER", 1); } if (VER_SUITE_COMPUTE_SERVER == (ovix.wSuiteMask & VER_SUITE_COMPUTE_SERVER)) { WcaSetIntProperty(L"WIX_SUITE_COMPUTE_SERVER", 1); } if (VER_SUITE_WH_SERVER == (ovix.wSuiteMask & VER_SUITE_WH_SERVER)) { WcaSetIntProperty(L"WIX_SUITE_WH_SERVER", 1); } // only for XP and later if (5 < ovix.dwMajorVersion || (5 == ovix.dwMajorVersion && 0 < ovix.dwMinorVersion)) { if (::GetSystemMetrics(SM_SERVERR2)) { WcaSetIntProperty(L"WIX_SUITE_SERVERR2", 1); } if (::GetSystemMetrics(SM_MEDIACENTER)) { WcaSetIntProperty(L"WIX_SUITE_MEDIACENTER", 1); } if (::GetSystemMetrics(SM_STARTER)) { WcaSetIntProperty(L"WIX_SUITE_STARTER", 1); } if (::GetSystemMetrics(SM_TABLETPC)) { WcaSetIntProperty(L"WIX_SUITE_TABLETPC", 1); } } LExit: if (FAILED(hr)) er = ERROR_INSTALL_FAILURE; return WcaFinalize(er); }