HRESULT ScaVirtualDirGetComponent( __in LPCWSTR wzVirtualDir, __out LPWSTR* ppwzData ) { Assert(wzVirtualDir && *wzVirtualDir); HRESULT hr = S_OK; PMSIHANDLE hView, hRec; hr = WcaTableExists(L"IIsWebVirtualDir"); if (S_FALSE == hr) hr = E_ABORT; ExitOnFailure(hr, "IIsWebVirtualDir table does not exist or error"); hRec = ::MsiCreateRecord(1); if (!hRec) { hr = E_OUTOFMEMORY; ExitOnFailure(hr, "Failed to create record for lookup."); } hr = WcaSetRecordString(hRec, 1, wzVirtualDir); ExitOnFailure(hr, "Failed to look up VirtualDir Component"); hr = WcaOpenView(vcsVDirPropertiesQuery, &hView); ExitOnFailure(hr, "Failed to open view on VirtualDir"); hr = WcaExecuteView(hView, hRec); ExitOnFailure(hr, "Failed to exectue view on VirtualDir"); hr = WcaFetchSingleRecord(hView, &hRec); if (S_OK == hr) { #if DEBUG // check that vdir matches hr = WcaGetRecordString(hRec, vdqVDir, ppwzData); ExitOnFailure(hr, "Failed to get IIsWebVirtualDir.VirtualDir"); Assert(0 == lstrcmpW(*ppwzData, wzVirtualDir)); #endif hr = WcaGetRecordString(hRec, vdqComponent, ppwzData); ExitOnFailure(hr, "Failed to get Component for VirtualDir"); } else if (E_NOMOREITEMS == hr) { WcaLog(LOGMSG_STANDARD, "Error: Cannot locate IIsWebVirtualDir.VirtualDir='%S'", wzVirtualDir); hr = E_FAIL; } else { ExitOnFailure(hr, "Error or found multiple matching VirtualDir rows"); } LExit: return hr; }
/******************************************************************** WcaGetRecordFormattedString() - gets formatted string filed from record ********************************************************************/ extern "C" HRESULT WIXAPI WcaGetRecordFormattedString( __in MSIHANDLE hRec, __in UINT uiField, __inout LPWSTR* ppwzData ) { if (!hRec || !ppwzData) { return E_INVALIDARG; } HRESULT hr = S_OK; UINT er; DWORD_PTR cch = 0; PMSIHANDLE hRecFormat; // get the format string hr = WcaGetRecordString(hRec, uiField, ppwzData); ExitOnFailure(hr, "failed to get string from record"); if (!**ppwzData) { ExitFunction(); } // hide the nulls '[~]' so we can get them back after formatting HideNulls(*ppwzData); // set up the format record hRecFormat = ::MsiCreateRecord(1); ExitOnNull(hRecFormat, hr, E_UNEXPECTED, "Failed to create record to format string"); hr = WcaSetRecordString(hRecFormat, 0, *ppwzData); ExitOnFailure(hr, "failed to set string to format record"); // format the string hr = StrMaxLength(*ppwzData, &cch); ExitOnFailure(hr, "failed to get max length of string"); er = ::MsiFormatRecordW(WcaGetInstallHandle(), hRecFormat, *ppwzData, (DWORD*)&cch); if (ERROR_MORE_DATA == er) { hr = StrAlloc(ppwzData, ++cch); ExitOnFailure(hr, "Failed to allocate memory for record string"); er = ::MsiFormatRecordW(WcaGetInstallHandle(), hRecFormat, *ppwzData, (DWORD*)&cch); } ExitOnWin32Error(er, hr, "Failed to format string"); // put the nulls back RevealNulls(*ppwzData); LExit: return hr; }
static HRESULT GetUserAccountName( LPCWSTR pwzKey, LPWSTR* ppwzAccount ) { HRESULT hr = S_OK; PMSIHANDLE hView, hRecKey, hRec; LPWSTR pwzDomain = NULL; LPWSTR pwzName = NULL; // create parameter record hRecKey = ::MsiCreateRecord(1); ExitOnNull(hRecKey, hr, E_OUTOFMEMORY, "Failed to create record"); hr = WcaSetRecordString(hRecKey, 1, pwzKey); ExitOnFailure(hr, "Failed to set record string"); // open view hr = WcaOpenView(vcsUserQuery, &hView); ExitOnFailure(hr, "Failed to open view on User table"); hr = WcaExecuteView(hView, hRecKey); ExitOnFailure(hr, "Failed to execute view on User table"); // fetch record hr = WcaFetchSingleRecord(hView, &hRec); if (S_FALSE == hr) ExitOnFailure(hr = HRESULT_FROM_WIN32(ERROR_NOT_FOUND), "User not found, key: %S", pwzKey); ExitOnFailure(hr, "Failed to fetch user record"); // get user domain hr = WcaGetRecordFormattedString(hRec, uqDomain, &pwzDomain); ExitOnFailure(hr, "Failed to get domain"); // get user name hr = WcaGetRecordFormattedString(hRec, uqName, &pwzName); ExitOnFailure(hr, "Failed to get name"); // build account name hr = CpiBuildAccountName(pwzDomain, pwzName, ppwzAccount); ExitOnFailure(hr, "Failed to build account name"); hr = S_OK; LExit: // clean up ReleaseStr(pwzDomain); ReleaseStr(pwzName); return hr; }
HRESULT CpiVerifyComponentArchitecure( LPCWSTR pwzComponent, BOOL* pfMatchingArchitecture ) { HRESULT hr = S_OK; PMSIHANDLE hView, hRecKey, hRec; int iAttributes = 0; if (S_OK == WcaTableExists(L"Component")) { // create parameter record hRecKey = ::MsiCreateRecord(1); ExitOnNull(hRecKey, hr, E_OUTOFMEMORY, "Failed to create record"); hr = WcaSetRecordString(hRecKey, 1, pwzComponent); ExitOnFailure(hr, "Failed to set record string"); // open view hr = WcaOpenView(vcsComponentAttributesQuery, &hView); ExitOnFailure(hr, "Failed to open view on ActionText table"); hr = WcaExecuteView(hView, hRecKey); ExitOnFailure(hr, "Failed to execute view on ActionText table"); // fetch record hr = WcaFetchSingleRecord(hView, &hRec); if (S_FALSE != hr) { ExitOnFailure(hr, "Failed to fetch component record"); hr = WcaGetRecordInteger(hRec, caqAttributes, &iAttributes); ExitOnFailure(hr, "Failed to get component attributes"); } } // return values #ifdef _WIN64 *pfMatchingArchitecture = 256 == (iAttributes & 256); #else *pfMatchingArchitecture = 256 != (iAttributes & 256); #endif hr = S_OK; LExit: return hr; }
/****************************************************************** FileIdExists - checks if the file ID is found in the File table returns S_OK if the file exists; S_FALSE if not; otherwise, error ********************************************************************/ static HRESULT FileIdExists( __in_opt LPCWSTR wzFile ) { HRESULT hr = S_OK; PMSIHANDLE hView = NULL; PMSIHANDLE hRec = NULL; if (!wzFile) { hr = S_FALSE; ExitFunction(); } hRec = ::MsiCreateRecord(1); hr = WcaSetRecordString(hRec, fiFile, wzFile); ExitOnFailure1(hr, "failed to create a record with the file: %ls", wzFile); hr = WcaTableExists(L"File"); if (S_OK == hr) { hr = WcaOpenView(vcsFileId, &hView); ExitOnFailure(hr, "failed to open view on File table"); hr = WcaExecuteView(hView, hRec); ExitOnFailure(hr, "failed to execute view on File table"); // Reuse the same record; the handle will be released. hr = WcaFetchSingleRecord(hView, &hRec); ExitOnFailure(hr, "failed to fetch File from File table"); } LExit: return hr; }
HRESULT ScaUserRead( __out SCA_USER** ppsuList ) { //Assert(FALSE); Assert(ppsuList); HRESULT hr = S_OK; UINT er = ERROR_SUCCESS; PMSIHANDLE hView, hRec, hUserRec, hUserGroupView; LPWSTR pwzData = NULL; BOOL fUserGroupExists = FALSE; SCA_USER *psu = NULL; INSTALLSTATE isInstalled, isAction; if (S_OK != WcaTableExists(L"User")) { WcaLog(LOGMSG_VERBOSE, "User Table does not exist, exiting"); ExitFunction1(hr = S_FALSE); } if (S_OK == WcaTableExists(L"UserGroup")) { fUserGroupExists = TRUE; } // // loop through all the users // hr = WcaOpenExecuteView(vActionableQuery, &hView); ExitOnFailure(hr, "failed to open view on User table"); while (S_OK == (hr = WcaFetchRecord(hView, &hRec))) { hr = WcaGetRecordString(hRec, vaqComponent, &pwzData); ExitOnFailure(hr, "failed to get User.Component"); er = ::MsiGetComponentStateW(WcaGetInstallHandle(), pwzData, &isInstalled, &isAction); hr = HRESULT_FROM_WIN32(er); ExitOnFailure(hr, "failed to get Component state for User"); // don't bother if we aren't installing or uninstalling this component if (WcaIsInstalling(isInstalled, isAction) || WcaIsUninstalling(isInstalled, isAction)) { // // Add the user to the list and populate it's values // hr = AddUserToList(ppsuList); ExitOnFailure(hr, "failed to add user to list"); psu = *ppsuList; psu->isInstalled = isInstalled; psu->isAction = isAction; hr = ::StringCchCopyW(psu->wzComponent, countof(psu->wzComponent), pwzData); ExitOnFailure1(hr, "failed to copy component name: %ls", pwzData); hr = WcaGetRecordString(hRec, vaqUser, &pwzData); ExitOnFailure(hr, "failed to get User.User"); hr = ::StringCchCopyW(psu->wzKey, countof(psu->wzKey), pwzData); ExitOnFailure1(hr, "failed to copy user key: %ls", pwzData); hr = WcaGetRecordFormattedString(hRec, vaqName, &pwzData); ExitOnFailure(hr, "failed to get User.Name"); hr = ::StringCchCopyW(psu->wzName, countof(psu->wzName), pwzData); ExitOnFailure1(hr, "failed to copy user name: %ls", pwzData); hr = WcaGetRecordFormattedString(hRec, vaqDomain, &pwzData); ExitOnFailure(hr, "failed to get User.Domain"); hr = ::StringCchCopyW(psu->wzDomain, countof(psu->wzDomain), pwzData); ExitOnFailure1(hr, "failed to copy user domain: %ls", pwzData); hr = WcaGetRecordFormattedString(hRec, vaqPassword, &pwzData); ExitOnFailure(hr, "failed to get User.Password"); hr = ::StringCchCopyW(psu->wzPassword, countof(psu->wzPassword), pwzData); ExitOnFailure(hr, "failed to copy user password"); hr = WcaGetRecordInteger(hRec, vaqAttributes, &psu->iAttributes); ExitOnFailure(hr, "failed to get User.Attributes"); // Check if this user is to be added to any groups if (fUserGroupExists) { hUserRec = ::MsiCreateRecord(1); hr = WcaSetRecordString(hUserRec, 1, psu->wzKey); ExitOnFailure(hr, "Failed to create user record for querying UserGroup table"); hr = WcaOpenView(vcsUserGroupQuery, &hUserGroupView); ExitOnFailure1(hr, "Failed to open view on UserGroup table for user %ls", psu->wzKey); hr = WcaExecuteView(hUserGroupView, hUserRec); ExitOnFailure1(hr, "Failed to execute view on UserGroup table for user: %ls", psu->wzKey); while (S_OK == (hr = WcaFetchRecord(hUserGroupView, &hRec))) { hr = WcaGetRecordString(hRec, vugqGroup, &pwzData); ExitOnFailure(hr, "failed to get UserGroup.Group"); hr = AddGroupToList(&(psu->psgGroups)); ExitOnFailure(hr, "failed to add group to list"); hr = ScaGetGroup(pwzData, psu->psgGroups); ExitOnFailure1(hr, "failed to get information for group: %ls", pwzData); } if (E_NOMOREITEMS == hr) { hr = S_OK; } ExitOnFailure(hr, "failed to enumerate selected rows from UserGroup table"); } } } if (E_NOMOREITEMS == hr) { hr = S_OK; } ExitOnFailure(hr, "failed to enumerate selected rows from User table"); LExit: ReleaseStr(pwzData); return hr; }
HRESULT __stdcall ScaGetUser( __in LPCWSTR wzUser, __out SCA_USER* pscau ) { if (!wzUser || !pscau) { return E_INVALIDARG; } HRESULT hr = S_OK; PMSIHANDLE hView, hRec; LPWSTR pwzData = NULL; // clear struct and bail right away if no user key was passed to search for ::ZeroMemory(pscau, sizeof(*pscau)); if (!*wzUser) { ExitFunction1(hr = S_OK); } hRec = ::MsiCreateRecord(1); hr = WcaSetRecordString(hRec, 1, wzUser); ExitOnFailure(hr, "Failed to look up User"); hr = WcaOpenView(vcsUserQuery, &hView); ExitOnFailure(hr, "Failed to open view on User table"); hr = WcaExecuteView(hView, hRec); ExitOnFailure(hr, "Failed to execute view on User table"); hr = WcaFetchSingleRecord(hView, &hRec); if (S_OK == hr) { hr = WcaGetRecordString(hRec, vuqUser, &pwzData); ExitOnFailure(hr, "Failed to get User.User"); hr = ::StringCchCopyW(pscau->wzKey, countof(pscau->wzKey), pwzData); ExitOnFailure(hr, "Failed to copy key string to user object"); hr = WcaGetRecordString(hRec, vuqComponent, &pwzData); ExitOnFailure(hr, "Failed to get User.Component_"); hr = ::StringCchCopyW(pscau->wzComponent, countof(pscau->wzComponent), pwzData); ExitOnFailure(hr, "Failed to copy component string to user object"); hr = WcaGetRecordFormattedString(hRec, vuqName, &pwzData); ExitOnFailure(hr, "Failed to get User.Name"); hr = ::StringCchCopyW(pscau->wzName, countof(pscau->wzName), pwzData); ExitOnFailure(hr, "Failed to copy name string to user object"); hr = WcaGetRecordFormattedString(hRec, vuqDomain, &pwzData); ExitOnFailure(hr, "Failed to get User.Domain"); hr = ::StringCchCopyW(pscau->wzDomain, countof(pscau->wzDomain), pwzData); ExitOnFailure(hr, "Failed to copy domain string to user object"); hr = WcaGetRecordFormattedString(hRec, vuqPassword, &pwzData); ExitOnFailure(hr, "Failed to get User.Password"); hr = ::StringCchCopyW(pscau->wzPassword, countof(pscau->wzPassword), pwzData); ExitOnFailure(hr, "Failed to copy password string to user object"); } else if (E_NOMOREITEMS == hr) { WcaLog(LOGMSG_STANDARD, "Error: Cannot locate User.User='******'", wzUser); hr = E_FAIL; } else { ExitOnFailure(hr, "Error or found multiple matching User rows"); } LExit: ReleaseStr(pwzData); return hr; }
HRESULT __stdcall ScaGetGroup( __in LPCWSTR wzGroup, __out SCA_GROUP* pscag ) { if (!wzGroup || !pscag) { return E_INVALIDARG; } HRESULT hr = S_OK; PMSIHANDLE hView, hRec; LPWSTR pwzData = NULL; hRec = ::MsiCreateRecord(1); hr = WcaSetRecordString(hRec, 1, wzGroup); ExitOnFailure(hr, "Failed to look up Group"); hr = WcaOpenView(vcsGroupQuery, &hView); ExitOnFailure(hr, "Failed to open view on Group table"); hr = WcaExecuteView(hView, hRec); ExitOnFailure(hr, "Failed to execute view on Group table"); hr = WcaFetchSingleRecord(hView, &hRec); if (S_OK == hr) { hr = WcaGetRecordString(hRec, vgqGroup, &pwzData); ExitOnFailure(hr, "Failed to get Group.Group"); hr = ::StringCchCopyW(pscag->wzKey, countof(pscag->wzKey), pwzData); ExitOnFailure(hr, "Failed to copy Group.Group."); hr = WcaGetRecordString(hRec, vgqComponent, &pwzData); ExitOnFailure(hr, "Failed to get Group.Component_"); hr = ::StringCchCopyW(pscag->wzComponent, countof(pscag->wzComponent), pwzData); ExitOnFailure(hr, "Failed to copy Group.Component_."); hr = WcaGetRecordFormattedString(hRec, vgqName, &pwzData); ExitOnFailure(hr, "Failed to get Group.Name"); hr = ::StringCchCopyW(pscag->wzName, countof(pscag->wzName), pwzData); ExitOnFailure(hr, "Failed to copy Group.Name."); hr = WcaGetRecordFormattedString(hRec, vgqDomain, &pwzData); ExitOnFailure(hr, "Failed to get Group.Domain"); hr = ::StringCchCopyW(pscag->wzDomain, countof(pscag->wzDomain), pwzData); ExitOnFailure(hr, "Failed to copy Group.Domain."); } else if (E_NOMOREITEMS == hr) { WcaLog(LOGMSG_STANDARD, "Error: Cannot locate Group.Group='%ls'", wzGroup); hr = E_FAIL; } else { ExitOnFailure(hr, "Error or found multiple matching Group rows"); } LExit: ReleaseStr(pwzData); return hr; }
HRESULT ScaWebAppExtensionsRead( LPCWSTR wzApplication, SCA_WEB_APPLICATION_EXTENSION** ppswappextList ) { HRESULT hr = S_OK; PMSIHANDLE hView, hRec; SCA_WEB_APPLICATION_EXTENSION* pswappext = NULL; LPWSTR pwzData = NULL; // check pre-requisites hr = WcaTableExists(L"IIsWebApplicationExtension"); if (S_FALSE == hr) ExitFunction(); // convert the string into a msi record hRec = ::MsiCreateRecord(1); hr = WcaSetRecordString(hRec, 1, wzApplication); ExitOnFailure(hr, "Failed to set record to look up Web Application"); // open and execute the view on the applicatoin extension table hr = WcaOpenView(vcsWebAppExtensionQuery, &hView); ExitOnFailure(hr, "Failed to open view on IIsWebApplicationExtension table"); hr = WcaExecuteView(hView, hRec); ExitOnFailure1(hr, "Failed to execute view on IIsWebApplicationExtension table looking Application: %S", wzApplication); // get the application extention information while (S_OK == (hr = WcaFetchRecord(hView, &hRec))) { hr = NewAppExt(&pswappext); ExitOnFailure(hr, "failed to create new web app extension"); // get the extension hr = WcaGetRecordString(hRec, wappextqExtension, &pwzData); ExitOnFailure(hr, "Failed to get Web Application Extension"); StringCchCopyW(pswappext->wzExtension, countof(pswappext->wzExtension), pwzData); // application extension verbs hr = WcaGetRecordString(hRec, wappextqVerbs, &pwzData); ExitOnFailure1(hr, "Failed to get Verbs for Application: '%S'", wzApplication); StringCchCopyW(pswappext->wzVerbs, countof(pswappext->wzVerbs), pwzData); // extension executeable hr = WcaGetRecordFormattedString(hRec, wappextqExecutable, &pwzData); ExitOnFailure1(hr, "Failed to get Executable for Application: '%S'", wzApplication); StringCchCopyW(pswappext->wzExecutable, countof(pswappext->wzExecutable), pwzData); hr = WcaGetRecordInteger(hRec, wappextqAttributes, &pswappext->iAttributes); if (S_FALSE == hr) { pswappext->iAttributes = 0; hr = S_OK; } ExitOnFailure(hr, "Failed to get App isolation"); *ppswappextList = AddAppExtToList(*ppswappextList, pswappext); pswappext = NULL; // set the appext NULL so it doesn't accidentally get freed below } if (E_NOMOREITEMS == hr) hr = S_OK; LExit: // if anything was left over after an error clean it all up if (pswappext) ScaWebAppExtensionsFreeList(pswappext); ReleaseStr(pwzData); return hr; }
HRESULT CpiPropertiesRead( LPCWSTR pwzQuery, LPCWSTR pwzKey, CPI_PROPERTY_DEFINITION* pPropDefList, CPI_PROPERTY** ppPropList, int* piCount ) { HRESULT hr = S_OK; PMSIHANDLE hView, hRecKey, hRec; CPI_PROPERTY* pItm = NULL; LPWSTR pwzData = NULL; int iVersionNT = 0; CPI_PROPERTY_DEFINITION* pPropDef; *piCount = 0; // get NT version hr = WcaGetIntProperty(L"VersionNT", &iVersionNT); ExitOnFailure(hr, "Failed to set record string"); // create parameter record hRecKey = ::MsiCreateRecord(1); ExitOnNull(hRecKey, hr, E_OUTOFMEMORY, "Failed to create record"); hr = WcaSetRecordString(hRecKey, 1, pwzKey); ExitOnFailure(hr, "Failed to set record string"); // open view hr = WcaOpenView(pwzQuery, &hView); ExitOnFailure(hr, "Failed to open view on property table"); hr = WcaExecuteView(hView, hRecKey); ExitOnFailure(hr, "Failed to execute view on property table"); while (S_OK == (hr = WcaFetchRecord(hView, &hRec))) { // create entry pItm = (CPI_PROPERTY*)::HeapAlloc(::GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(CPI_PROPERTY)); if (!pItm) ExitFunction1(hr = E_OUTOFMEMORY); // get name hr = WcaGetRecordString(hRec, pqName, &pwzData); ExitOnFailure(hr, "Failed to get name"); StringCchCopyW(pItm->wzName, countof(pItm->wzName), pwzData); // get value hr = WcaGetRecordFormattedString(hRec, pqValue, &pItm->pwzValue); ExitOnFailure(hr, "Failed to get value"); // find property definition hr = FindPropertyDefinition(pPropDefList, pItm->wzName, &pPropDef); ExitOnFailure(hr, "Failed to find property definition"); if (S_FALSE == hr) ExitOnFailure(hr = HRESULT_FROM_WIN32(ERROR_NOT_FOUND), "Unknown property, key: %S, property: %S", pwzKey, pItm->wzName); // check version, ignore if catalog version is too low if (iVersionNT < pPropDef->iMinVersionNT) { WcaLog(LOGMSG_VERBOSE, "Skipping property since NT version is too low, key: %S, property: %S", pwzKey, pItm->wzName); CpiPropertiesFreeList(pItm); pItm = NULL; continue; } // if the property is a user, replace the User table key with a user account name if (cpptUser == pPropDef->iType) { hr = GetUserAccountName(pItm->pwzValue, &pItm->pwzValue); ExitOnFailure(hr, "Failed to get user account name"); } // add entry ++*piCount; if (*ppPropList) pItm->pNext = *ppPropList; *ppPropList = pItm; pItm = NULL; } if (E_NOMOREITEMS == hr) hr = S_OK; LExit: // clean up if (pItm) CpiPropertiesFreeList(pItm); ReleaseStr(pwzData); return hr; }
HRESULT CpiAddActionTextToActionData( LPCWSTR pwzAction, LPWSTR* ppwzActionData ) { HRESULT hr = S_OK; PMSIHANDLE hView, hRecKey, hRec; LPWSTR pwzDescription = NULL; LPWSTR pwzTemplate = NULL; if (S_OK == WcaTableExists(L"ActionText")) { // create parameter record hRecKey = ::MsiCreateRecord(1); ExitOnNull(hRecKey, hr, E_OUTOFMEMORY, "Failed to create record"); hr = WcaSetRecordString(hRecKey, 1, pwzAction); ExitOnFailure(hr, "Failed to set record string"); // open view hr = WcaOpenView(vcsActionTextQuery, &hView); ExitOnFailure(hr, "Failed to open view on ActionText table"); hr = WcaExecuteView(hView, hRecKey); ExitOnFailure(hr, "Failed to execute view on ActionText table"); // fetch record hr = WcaFetchSingleRecord(hView, &hRec); if (S_FALSE != hr) { ExitOnFailure(hr, "Failed to fetch action text record"); // get description hr = WcaGetRecordString(hRec, atqDescription, &pwzDescription); ExitOnFailure(hr, "Failed to get description"); // get template hr = WcaGetRecordString(hRec, atqTemplate, &pwzTemplate); ExitOnFailure(hr, "Failed to get template"); } } // add action name to action data hr = WcaWriteStringToCaData(pwzAction, ppwzActionData); ExitOnFailure(hr, "Failed to add action name to custom action data"); // add description to action data hr = WcaWriteStringToCaData(pwzDescription ? pwzDescription : L"", ppwzActionData); ExitOnFailure(hr, "Failed to add description to custom action data"); // add template to action data hr = WcaWriteStringToCaData(pwzTemplate ? pwzTemplate : L"", ppwzActionData); ExitOnFailure(hr, "Failed to add template to custom action data"); hr = S_OK; LExit: // clean up ReleaseStr(pwzDescription); ReleaseStr(pwzTemplate); return hr; }
static HRESULT GetStrongName( __out LPWSTR* ppwzStrongName, __in LPCWSTR pwzComponent ) { Assert(ppwzStrongName); HRESULT hr = S_OK; PMSIHANDLE hView = NULL; PMSIHANDLE hComponentRec = NULL; PMSIHANDLE hRec = NULL; LPWSTR pwzData = NULL; LPWSTR pwzName = NULL; LPWSTR pwzVersion = NULL; LPWSTR pwzCulture = NULL; LPWSTR pwzPublicKeyToken = NULL; hComponentRec = ::MsiCreateRecord(1); hr = WcaSetRecordString(hComponentRec, 1, pwzComponent); ExitOnFailure1(hr, "failed to set component value in record to: %ls", pwzComponent); // get the name value records for this component hr = WcaOpenView(vcsNgenStrongName, &hView); ExitOnFailure(hr, "failed to open view on NetFxNativeImage table"); hr = WcaExecuteView(hView, hComponentRec); ExitOnFailure(hr, "failed to execute strong name view"); while (S_OK == (hr = WcaFetchRecord(hView, &hRec))) { hr = WcaGetRecordString(hRec, ngsnName, &pwzData); ExitOnFailure1(hr, "failed to get MsiAssemblyName.Name for component: %ls", pwzComponent); if (0 == lstrcmpW(L"name", pwzData)) { hr = WcaGetRecordString(hRec, ngsnValue, &pwzName); ExitOnFailure2(hr, "failed to get MsiAssemblyName.Value for component: %ls Name: %ls", pwzComponent, pwzData); } else if (0 == lstrcmpW(L"version", pwzData)) { hr = WcaGetRecordString(hRec, ngsnValue, &pwzVersion); ExitOnFailure2(hr, "failed to get MsiAssemblyName.Value for component: %ls Name: %ls", pwzComponent, pwzData); } else if (0 == lstrcmpW(L"culture", pwzData)) { hr = WcaGetRecordString(hRec, ngsnValue, &pwzCulture); ExitOnFailure2(hr, "failed to get MsiAssemblyName.Value for component: %ls Name: %ls", pwzComponent, pwzData); } else if (0 == lstrcmpW(L"publicKeyToken", pwzData)) { hr = WcaGetRecordString(hRec, ngsnValue, &pwzPublicKeyToken); ExitOnFailure2(hr, "failed to get MsiAssemblyName.Value for component: %ls Name: %ls", pwzComponent, pwzData); } } if (E_NOMOREITEMS == hr) hr = S_OK; ExitOnFailure1(hr, "failed while looping through all names and values in MsiAssemblyName table for component: %ls", pwzComponent); hr = StrAllocFormatted(ppwzStrongName, L"\"%s, Version=%s, Culture=%s, PublicKeyToken=%s\"", pwzName, pwzVersion, pwzCulture, pwzPublicKeyToken); ExitOnFailure1(hr, "failed to format strong name for component: %ls", pwzComponent); LExit: ReleaseStr(pwzData); ReleaseStr(pwzName); ReleaseStr(pwzVersion); ReleaseStr(pwzCulture); ReleaseStr(pwzPublicKeyToken); return hr; }
HRESULT GetFileSpec( __in MSIHANDLE hViewFileSpec, __in LPCWSTR wzKey, __in SQL_FILESPEC* psf ) { HRESULT hr = S_OK; PMSIHANDLE hRecFileSpec, hRec; LPWSTR pwzData = NULL; // create a record to do the fetch hRecFileSpec = ::MsiCreateRecord(1); if (!hRecFileSpec) { ExitOnFailure1(hr = E_UNEXPECTED, "failed to create record for filespec: %ls", wzKey); } hr = WcaSetRecordString(hRecFileSpec, 1, wzKey); ExitOnFailure1(hr, "failed to set record string for filespec: %ls", wzKey); // get the FileSpec record hr = WcaExecuteView(hViewFileSpec, hRecFileSpec); ExitOnFailure1(hr, "failed to execute view on SqlFileSpec table for filespec: %ls", wzKey); hr = WcaFetchSingleRecord(hViewFileSpec, &hRec); ExitOnFailure1(hr, "failed to get record for filespec: %ls", wzKey); // read the data out of the filespec record hr = WcaGetRecordFormattedString(hRec, sfsqName, &pwzData); ExitOnFailure1(hr, "Failed to get SqlFileSpec.Name for filespec: %ls", wzKey); hr = ::StringCchCopyW(psf->wzName, countof(psf->wzName), pwzData); ExitOnFailure1(hr, "Failed to copy SqlFileSpec.Name string: %ls", pwzData); hr = WcaGetRecordFormattedString(hRec, sfsqFilename, &pwzData); ExitOnFailure1(hr, "Failed to get SqlFileSpec.Filename for filespec: %ls", wzKey); if (*pwzData) { hr = ::StringCchCopyW(psf->wzFilename, countof(psf->wzFilename), pwzData); ExitOnFailure1(hr, "Failed to copy filename to filespec object: %ls", pwzData); } else // if there is no file, skip this FILESPEC { WcaLog(LOGMSG_VERBOSE, "No filename specified, skipping FileSpec: %ls", psf->wzName); ExitFunction1(hr = S_FALSE); } hr = WcaGetRecordFormattedString(hRec, sfsqSize, &pwzData); ExitOnFailure1(hr, "Failed to get SqlFileSpec.Size for filespec: %ls", wzKey); if (*pwzData) { hr = ::StringCchCopyW(psf->wzSize, countof(psf->wzSize), pwzData); ExitOnFailure1(hr, "Failed to copy size to filespec object: %ls", pwzData); } else { psf->wzSize[0] = 0; } hr = WcaGetRecordFormattedString(hRec, sfsqMaxSize, &pwzData); ExitOnFailure1(hr, "Failed to get SqlFileSpec.MaxSize for filespec: %ls", wzKey); if (*pwzData) { hr = ::StringCchCopyW(psf->wzMaxSize, countof(psf->wzMaxSize), pwzData); ExitOnFailure1(hr, "Failed to copy max size to filespec object: %ls", pwzData); } else { psf->wzMaxSize[0] = 0; } hr = WcaGetRecordFormattedString(hRec, sfsqGrowth, &pwzData); ExitOnFailure1(hr, "Failed to get SqlFileSpec.GrowthSize for filespec: %ls", wzKey); if (*pwzData) { hr = ::StringCchCopyW(psf->wzGrow, countof(psf->wzGrow), pwzData); ExitOnFailure1(hr, "Failed to copy growth size to filespec object: %ls", pwzData); } else { psf->wzGrow[0] = 0; } hr = S_OK; LExit: ReleaseStr(pwzData); return hr; }