void CTreeList::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) { PULONG pMagic = (PULONG) lpDrawItemStruct->itemData; TCHAR lpBuffer[256]; LV_ITEM lvi; LV_COLUMN lvc, lvcprev ; memset(lpBuffer, 0, 256); lvi.mask = LVIF_TEXT | LVIF_PARAM ; lvi.iItem = lpDrawItemStruct->itemID ; lvi.iSubItem = 0; lvi.pszText = lpBuffer ; lvi.cchTextMax = sizeof(lpBuffer); GetItem(&lvi); ::ZeroMemory(&lvc, sizeof(lvc)); ::ZeroMemory(&lvcprev, sizeof(lvcprev)); lvc.mask = LVCF_WIDTH |LVCF_FMT; lvcprev.mask = LVCF_WIDTH | LVCF_FMT; CDC* pDC; pDC = CDC::FromHandle(lpDrawItemStruct->hDC); int nCol; CRect rcText = lpDrawItemStruct->rcItem; CFont Fnt, *pOldFont = NULL; LOGFONT lf; int cyPixels = pDC->GetDeviceCaps(LOGPIXELSY); memset(&lf, 0, sizeof(LOGFONT)); if (pMagic == NULL) { return; } if (*pMagic == EXT2_CDROM_DEVICE_MAGIC || *pMagic == EXT2_DISK_MAGIC) { if (IsVistaOrAbove()) { lstrcpy(lf.lfFaceName, "MS Sans Serif"); /*Courier New*/ lf.lfHeight = -MulDiv(8, cyPixels, 72); lf.lfWeight = TRUE; } else { lstrcpy(lf.lfFaceName, "Arial Black"); /*Courier New*/ lf.lfHeight = -MulDiv(8, cyPixels, 72); lf.lfWeight = TRUE; } } else { lstrcpy(lf.lfFaceName, "MS Sans Serif"); lf.lfHeight = -MulDiv(8, cyPixels, 72); } Fnt.CreateFontIndirect(&lf); pOldFont = (CFont *) pDC->SelectObject(&Fnt); /* loading bitmap */ if (m_hBitmap == NULL) { m_hBitmap = (HBITMAP)::LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(IDB_LINE_SEP), IMAGE_BITMAP, 0, 0, 0); if (m_hBitmap) { m_hMemDC = ::CreateCompatibleDC(this->GetDC()->m_hDC); m_hOldBmp = (HBITMAP)::SelectObject(m_hMemDC, m_hBitmap); } } if (TRUE) { if (!m_SelectionFlag) { for (nCol=0; GetColumn(nCol, &lvc); nCol++) { if (nCol > 0) { GetSubItemRect(lpDrawItemStruct->itemID, nCol,LVIR_BOUNDS, m_SelectionRect); } else { GetItemRect(lpDrawItemStruct->itemID, m_SelectionRect,LVIR_BOUNDS); m_SelectionRect.right = GetColumnWidth(0); m_SelectionRect.left = 0; } if (m_SelectionRect.PtInRect(m_Point)) { m_SelectionFlag = TRUE; break; } else { m_SelectionFlag = FALSE; } } } if ((lpDrawItemStruct->itemState & ODS_SELECTED) && m_SelectionFlag ) { CRect rc = lpDrawItemStruct->rcItem; rc.left += 4; rc.right -= 4; rc.top += 1; rc.bottom -= 0; if (*pMagic == EXT2_CDROM_DEVICE_MAGIC || *pMagic == EXT2_DISK_MAGIC) { rc.bottom -= 3; rc.top -= 1; rc.right = (rc.Width() * 7 / 8) + rc.left; } pDC->FillSolidRect(&rc, GetSysColor(m_bFocus ? COLOR_HIGHLIGHT : COLOR_INACTIVEBORDER)); } else { CRect rc = lpDrawItemStruct->rcItem; pDC->FillSolidRect(&rc, GetSysColor(COLOR_WINDOW)) ; pDC->SetTextColor(GetSysColor(COLOR_WINDOWTEXT)) ; } } for (nCol=0; GetColumn(nCol, &lvc); nCol++) { UINT uFormat = DT_LEFT ; if (*pMagic == EXT2_CDROM_DEVICE_MAGIC || *pMagic == EXT2_DISK_MAGIC) { rcText = lpDrawItemStruct->rcItem; rcText.left += 4; rcText.bottom += 1; rcText.top = rcText.bottom - 6 + lf.lfHeight; ::DrawText(lpDrawItemStruct->hDC, lpBuffer, strlen(lpBuffer), &rcText, DT_LEFT) ; CRect rect = lpDrawItemStruct->rcItem; int rc = 0; BITMAP cs; rect.top = rcText.bottom - 4; rc = ::GetObject(m_hBitmap, sizeof(cs), &cs); if (rc == 0) { pDC->SelectObject(pOldFont); return; } ::StretchBlt(pDC->m_hDC, rect.left + 4, (rect.bottom + rect.top) / 2, rect.Width() * 7 / 8, cs.bmHeight, m_hMemDC, 0, 0, cs.bmWidth, cs.bmHeight, SRCCOPY); } else { if (nCol > 0) { GetColumn(nCol, &lvcprev) ; rcText.left = rcText.right; rcText.right += lvcprev.cx; rcText.left += 4; if (nCol == 3 || nCol == 4) { uFormat = DT_RIGHT; rcText.right -= 4; } } else { rcText = lpDrawItemStruct->rcItem; rcText.top += (16 + lf.lfHeight) / 2; rcText.right = rcText.left + GetColumnWidth(0); rcText.left += 20; } // Get and draw the text memset(lpBuffer, 0, 256); ::ZeroMemory(&lvi, sizeof(lvi)); lvi.iItem = lpDrawItemStruct->itemID; lvi.mask = LVIF_TEXT | LVIF_PARAM; lvi.iSubItem = nCol; lvi.pszText = lpBuffer; lvi.cchTextMax = sizeof(lpBuffer); GetItem(&lvi); ::DrawText(lpDrawItemStruct->hDC, lpBuffer, strlen(lpBuffer), &rcText, uFormat) ; if (nCol == 0) { rcText.left -= 20; } else { rcText.left -= 4; if (nCol == 3 || nCol == 4) { rcText.right += 4; } } } } pDC->SelectObject(pOldFont); return; }
// // _CreateSessionInfoKey // // Note that unlike _IsFirstRunThisSession this function can be called // multiple times without side-effects. // HKEY StartupRunner::_CreateSessionInfoKey() { HKEY hkSessionInfo = NULL; HANDLE hToken = NULL; if (OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &hToken)) { HRESULT hr = E_FAIL; TCHAR tzSessionInfo[128] = { 0 }; DWORD dwOutSize = 0; if (IsVistaOrAbove()) { DWORD dwSessionId = 0; // On Vista the subkey's name is the Session ID if (GetTokenInformation(hToken, TokenSessionId, &dwSessionId, sizeof(dwSessionId), &dwOutSize)) { hr = StringCchPrintf(tzSessionInfo, COUNTOF(tzSessionInfo), REGSTR_PATH_EXPLORER _T("\\SessionInfo\\%u"), dwSessionId); } } else { TOKEN_STATISTICS tsStats = { {0} }; // Prior to Vista the subkey's name is the AuthenticationId if (GetTokenInformation(hToken, TokenStatistics, &tsStats, sizeof(tsStats), &dwOutSize)) { hr = StringCchPrintf(tzSessionInfo, COUNTOF(tzSessionInfo), REGSTR_PATH_EXPLORER _T("\\SessionInfo\\%08x%08x"), tsStats.AuthenticationId.HighPart, tsStats.AuthenticationId.LowPart); } } if (SUCCEEDED(hr)) { // Finally open the SessionInfo key LONG lResult = RegCreateKeyEx( HKEY_CURRENT_USER, tzSessionInfo, 0, NULL, REG_OPTION_VOLATILE, KEY_WRITE, NULL, &hkSessionInfo, NULL); if (lResult != ERROR_SUCCESS) { hkSessionInfo = NULL; } } CloseHandle(hToken); } return hkSessionInfo; }
int _tmain(int argc, TCHAR* argv[]) { int result; ENSURE_DEBUGGER(); if (argc == 1 || (argc == 2 && !_tcsicmp(*(argv + 1), _T("/?")))) return PRINT_USAGE(VER_FULLVERSION, COPYRIGHT_INFO); // TODO: // /r (raw) do not interpret internal cmd commands as cmd /d /c command // /n do not copy env vars SetUp(); result = (!IsVistaOrAbove() || IsElevated()) ? ExecuteProgram() : ExecuteStub(); return CleanUp(result); }
// // LSPlaySystemSound // Wrapper around PlaySound to play system event sounds // BOOL LSPlaySystemSound(LPCTSTR pszSoundAlias) { BOOL bResult = FALSE; // We want to avoid linking to winmm.dll as long as it's used just here HMODULE hWinMM = LoadLibrary(_T("winmm.dll")); if (hWinMM) { typedef BOOL (WINAPI* PlaySoundProc)(LPCTSTR, HMODULE, DWORD); #if defined(UNICODE) PlaySoundProc fnPlaySound = (PlaySoundProc) GetProcAddress(hWinMM, "PlaySoundW"); #else PlaySoundProc fnPlaySound = (PlaySoundProc) GetProcAddress(hWinMM, "PlaySoundA"); #endif if (fnPlaySound) { // Use SND_NODEFAULT to make sure that not even a default sound is // played if the sound alias has no corresponding sound set // (if e.g. the user has disabled this particular sound) DWORD dwFlags = SND_ALIAS | SND_NODEFAULT; if (IsVistaOrAbove()) { // Vista has a special volume slider for system sounds, ie. all // those beeps etc. can be adjusted independently of all other // sounds. SND_SYSTEM makes PlaySound use that slider. dwFlags |= SND_SYSTEM; } bResult = fnPlaySound(pszSoundAlias, NULL, dwFlags); } VERIFY(FreeLibrary(hWinMM)); } return bResult; }
// // LSShutdownDialog // void LSShutdownDialog(HWND hWnd) { FARPROC fnProc = GetProcAddress( GetModuleHandleW(L"SHELL32.DLL"), (LPCSTR)((long)0x003C)); if (fnProc) { if (IsVistaOrAbove()) { typedef VOID (WINAPI* ExitWindowsDialogProc)(HWND, DWORD); ExitWindowsDialogProc fnExitWindowsDialog = \ (ExitWindowsDialogProc)fnProc; // Meaning of second parameter unknown fnExitWindowsDialog(hWnd, NULL); } else { typedef VOID (WINAPI* ExitWindowsDialogProc)(HWND); ExitWindowsDialogProc fnExitWindowsDialog = \ (ExitWindowsDialogProc)fnProc; fnExitWindowsDialog(hWnd); } // provide same mechansim for exiting the shell as explorer if ((GetAsyncKeyState(VK_SHIFT) & 0x8000) && (GetAsyncKeyState(VK_CONTROL) & 0x8000) && (GetAsyncKeyState(VK_MENU) & 0x8000)) { PostQuitMessage(LRV_SHUTDOWN_DLG); } } }
BOOL CPPageFormats::OnInitDialog() { __super::OnInitDialog(); m_list.SetExtendedStyle(m_list.GetExtendedStyle()|LVS_EX_FULLROWSELECT); m_list.InsertColumn(COL_CATEGORY, _T("Category"), LVCFMT_LEFT, 300); m_list.InsertColumn(COL_ENGINE, _T("Engine"), LVCFMT_RIGHT, 60); m_onoff.Create(IDB_ONOFF, 12, 3, 0xffffff); m_list.SetImageList(&m_onoff, LVSIL_SMALL); CMediaFormats& mf = AfxGetAppSettings().Formats; mf.UpdateData(FALSE); for(int i = 0; i < (int)mf.GetCount(); i++) { CString label; label.Format (_T("%s (%s)"), mf[i].GetLabel(), mf[i].GetExts()); int iItem = m_list.InsertItem(i, label); m_list.SetItemData(iItem, i); engine_t e = mf[i].GetEngineType(); m_list.SetItemText(iItem, COL_ENGINE, e == DirectShow ? _T("DirectShow") : e == RealMedia ? _T("RealMedia") : e == QuickTime ? _T("QuickTime") : e == ShockWave ? _T("ShockWave") : _T("-")); } // m_list.SetColumnWidth(COL_CATEGORY, LVSCW_AUTOSIZE); m_list.SetColumnWidth(COL_ENGINE, LVSCW_AUTOSIZE_USEHEADER); m_list.SetSelectionMark(0); m_list.SetItemState(0, LVIS_SELECTED, LVIS_SELECTED); m_exts = mf[(int)m_list.GetItemData(0)].GetExtsWithPeriod(); AppSettings& s = AfxGetAppSettings(); bool fRtspFileExtFirst; engine_t e = s.Formats.GetRtspHandler(fRtspFileExtFirst); m_iRtspHandler = (e==RealMedia?0:e==QuickTime?1:2); m_fRtspFileExtFirst = fRtspFileExtFirst; UpdateData(FALSE); f_setContextFiles = 0; for(int i = 0; i < m_list.GetItemCount(); i++) { SetListItemState(i); } m_fContextFiles.SetCheck(f_setContextFiles); if(AfxGetAppSettings().fXpOrBetter) { m_apvideo.SetCheck(IsAutoPlayRegistered(AP_VIDEO)); m_apmusic.SetCheck(IsAutoPlayRegistered(AP_MUSIC)); m_apaudiocd.SetCheck(IsAutoPlayRegistered(AP_AUDIOCD)); m_apdvd.SetCheck(IsAutoPlayRegistered(AP_DVDMOVIE)); } else { m_autoplay.ShowWindow(SW_HIDE); m_apvideo.ShowWindow(SW_HIDE); m_apmusic.ShowWindow(SW_HIDE); m_apaudiocd.ShowWindow(SW_HIDE); m_apdvd.ShowWindow(SW_HIDE); } CreateToolTip(); if (IsVistaOrAbove() && !IsUserAnAdmin()) { GetDlgItem(IDC_BUTTON1)->ShowWindow (SW_HIDE); GetDlgItem(IDC_BUTTON3)->ShowWindow (SW_HIDE); GetDlgItem(IDC_BUTTON4)->ShowWindow (SW_HIDE); GetDlgItem(IDC_CHECK1)->EnableWindow (FALSE); GetDlgItem(IDC_CHECK2)->EnableWindow (FALSE); GetDlgItem(IDC_CHECK3)->EnableWindow (FALSE); GetDlgItem(IDC_CHECK4)->EnableWindow (FALSE); GetDlgItem(IDC_CHECK5)->EnableWindow (FALSE); GetDlgItem(IDC_RADIO1)->EnableWindow (FALSE); GetDlgItem(IDC_RADIO2)->EnableWindow (FALSE); GetDlgItem(IDC_RADIO3)->EnableWindow (FALSE); GetDlgItem(IDC_BUTTON5)->ShowWindow (SW_SHOW); GetDlgItem(IDC_BUTTON5)->SendMessage (BCM_SETSHIELD, 0, 1); m_bInsufficientPrivileges = true; } else GetDlgItem(IDC_BUTTON5)->ShowWindow (SW_HIDE); CRegKey key; TCHAR buff[_MAX_PATH]; ULONG len = sizeof(buff); int fContextDir = 0; if(ERROR_SUCCESS == key.Open(HKEY_CLASSES_ROOT, _T("Directory\\shell\\mplayerc.play\\command"), KEY_READ)) { CString strCommand = GetOpenCommand(); if (ERROR_SUCCESS == key.QueryStringValue(NULL, buff, &len)) fContextDir = (strCommand.CompareNoCase(CString(buff)) == 0); } m_fContextDir.SetCheck(fContextDir); m_fAssociatedWithIcons.SetCheck(s.fAssociatedWithIcons); return TRUE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should return FALSE }
static int OpenVideoVista(vlc_object_t *obj) { /* Windows Vista or above, make this module the default */ return IsVistaOrAbove() ? Open(obj) : VLC_EGENERIC; }
static int OpenVideoXP(vlc_object_t *obj) { /* Windows XP or lower, make sure this module isn't the default */ return IsVistaOrAbove() ? VLC_EGENERIC : Open(obj); }
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= // // GetShellFolderPath // // Wrapper around SHGetSpecialFolderLocation to get around the lack of // SHGetSpecialFolderPath on Win95. Also fetches the QuickLaunch folder. // bool GetShellFolderPath(int nFolder, LPTSTR ptzPath, size_t cchPath) { ASSERT(cchPath >= MAX_PATH); ASSERT(NULL != ptzPath); HRESULT hr = E_FAIL; PIDLIST_ABSOLUTE pidl = NULL; if (nFolder == LS_CSIDL_QUICKLAUNCH) { if (IsVistaOrAbove()) { // // Vista turned the QuickLaunch folder into a "Known Folder" // whose location can be customized. But it didn't retroactively // get a CSIDL constant so we have to use the known folder API. // hr = LSGetKnownFolderIDList(FOLDERID_QuickLaunch, &pidl); } else { // // Prior to Vista there is no documented way of getting the path. // We try to hardcode as little as possible. // hr = GetShellFolderPath(CSIDL_APPDATA, ptzPath, cchPath); if (SUCCEEDED(hr)) { PathAppend(ptzPath, _T("Microsoft\\Internet Explorer\\Quick Launch")); // // SHGetSpecialFolderLocation only returns directories that // exist, so we do the same for our custom QuickLaunch case. // if (!PathFileExists(ptzPath)) { hr = HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND); } } } } else { // Starting with Vista, the "ALT" folders don't exist any more. // SHGetSpecialFolderLocation maps them to the non-"ALT" versions. if (IsVistaOrAbove() && (nFolder == CSIDL_ALTSTARTUP || nFolder == CSIDL_COMMON_ALTSTARTUP)) { hr = E_FAIL; } else { hr = SHGetSpecialFolderLocation(NULL, nFolder, &pidl); } } // // Convert PIDL to path // if (pidl != NULL) { if (SUCCEEDED(hr) && !SHGetPathFromIDList(pidl, ptzPath)) { hr = E_FAIL; } CoTaskMemFree(pidl); } if (FAILED(hr)) { ptzPath[0] = '\0'; } return (SUCCEEDED(hr)); }
DWORD WINAPI StartupRunner::_ThreadProc(LPVOID lpData) { bool bRunStartup = IsFirstRunThisSession(_T("StartupHasBeenRun")); BOOL bForceStartup = (lpData != 0); if (IsVistaOrAbove()) { // On Vista there's this additional subkey. // Its meaning is currently unknown. We create but ignore it. IsFirstRunThisSession(_T("RunStuffHasBeenRun")); } // by keeping the call to _IsFirstRunThisSession() above we make sure the // regkey is created even if we're in "force startup" mode if (bRunStartup || bForceStartup) { // Need to call CoInitializeEx for ShellExecuteEx VERIFY_HR(CoInitializeEx( NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE)); bool bHKLMRun = true; bool bHKCURun = true; bool bHKLMRunOnce = true; bool bHKCURunOnce = true; // // SHRestricted is not available on Windows 95 // typedef DWORD (WINAPI* SHREST_PROC)(RESTRICTIONS); SHREST_PROC pSHRestricted = (SHREST_PROC)GetProcAddress( GetModuleHandle(_T("shell32.dll")), (LPCSTR)((long)0x0064)); if (pSHRestricted) { bHKLMRun = !pSHRestricted(REST_NOLOCALMACHINERUN); bHKCURun = !pSHRestricted(REST_NOCURRENTUSERRUN); bHKLMRunOnce = !pSHRestricted(REST_NOLOCALMACHINERUNONCE); bHKCURunOnce = !pSHRestricted(REST_NOCURRENTUSERRUNONCE); } // // On Win64 there are separate 32-Bit and 64-Bit versions of // HKLM\Run, HKLM\RunOnce, and HKLM\RunOnceEx. // However, HKLM\...\Policies\Explorer\Run is a shared key. // // There is only a single version of all HKCU keys. // if (bHKLMRunOnce) { _RunRegKeys(HKEY_LOCAL_MACHINE, REGSTR_PATH_RUNONCE, (ERK_RUNSUBKEYS | ERK_DELETE | ERK_WAITFOR_QUIT | ERK_WIN64_BOTH)); } _RunRunOnceEx(); if (bHKLMRun) { _RunRegKeys(HKEY_LOCAL_MACHINE, REGSTR_PATH_RUN, ERK_WIN64_BOTH); } _RunRegKeys(HKEY_LOCAL_MACHINE, REGSTR_PATH_RUN_POLICY, ERK_NONE); _RunRegKeys(HKEY_CURRENT_USER, REGSTR_PATH_RUN_POLICY, ERK_NONE); if (bHKCURun) { _RunRegKeys(HKEY_CURRENT_USER, REGSTR_PATH_RUN, ERK_NONE); } _RunStartupMenu(); if (bHKCURunOnce) { _RunRegKeys(HKEY_CURRENT_USER, REGSTR_PATH_RUNONCE, (ERK_RUNSUBKEYS | ERK_DELETE)); } CoUninitialize(); } return bRunStartup; }
/******************************************************************** ConfigurePerfmonManifestRegister - CUSTOM ACTION ENTRY POINT for scheduling Perfmon counter manifest registering ********************************************************************/ extern "C" UINT __stdcall ConfigurePerfmonManifestRegister( __in MSIHANDLE hInstall ) { HRESULT hr; UINT er = ERROR_SUCCESS; PMSIHANDLE hView, hRec; LPWSTR pwzData = NULL, pwzResourceFilePath = NULL, pwzFile = NULL, pwzCommand = NULL; INSTALLSTATE isInstalled, isAction; hr = WcaInitialize(hInstall, "ConfigurePerfmonManifestReg"); ExitOnFailure(hr, "Failed to initialize"); if (!IsVistaOrAbove()) { WcaLog(LOGMSG_VERBOSE, "Skipping ConfigurePerfmonManifestRegister() because the target system does not support perfmon manifest"); ExitFunction1(hr = S_FALSE); } // check to see if necessary tables are specified if (S_OK != WcaTableExists(L"PerfmonManifest")) { WcaLog(LOGMSG_VERBOSE, "Skipping ConfigurePerfmonManifestRegister() because PerfmonManifest table not present"); ExitFunction1(hr = S_FALSE); } hr = WcaOpenExecuteView(vcsPerfmonManifestQuery, &hView); ExitOnFailure(hr, "failed to open view on PerfMonManifest table"); while ((hr = WcaFetchRecord(hView, &hRec)) == S_OK) { // get component install state hr = WcaGetRecordString(hRec, pfmComponent, &pwzData); ExitOnFailure(hr, "failed to get Component for PerfMonManifest"); er = ::MsiGetComponentStateW(hInstall, pwzData, &isInstalled, &isAction); hr = HRESULT_FROM_WIN32(er); ExitOnFailure(hr, "failed to get Component state for PerfMonManifest"); if (!WcaIsInstalling(isInstalled, isAction)) { continue; } hr = WcaGetRecordFormattedString(hRec, pfmFile, &pwzFile); ExitOnFailure(hr, "failed to get File for PerfMonManifest"); hr = WcaGetRecordFormattedString(hRec, pfmResourceFileDir, &pwzResourceFilePath); ExitOnFailure(hr, "failed to get ApplicationIdentity for PerfMonManifest"); size_t iResourcePath = lstrlenW(pwzResourceFilePath); if ( iResourcePath > 0 && *(pwzResourceFilePath + iResourcePath -1) == L'\\') *(pwzResourceFilePath + iResourcePath -1) = 0; //remove the trailing '\' hr = StrAllocFormatted(&pwzCommand, L"\"unlodctr.exe\" /m:\"%s\"", pwzFile); ExitOnFailure(hr, "failed to copy string in PerfMonManifest"); hr = WcaDoDeferredAction(PLATFORM_DECORATION(L"RollbackRegisterPerfmonManifest"), pwzCommand, COST_PERFMONMANIFEST_UNREGISTER); ExitOnFailure(hr, "failed to schedule RollbackRegisterPerfmonManifest action"); if ( *pwzResourceFilePath ) { hr = StrAllocFormatted(&pwzCommand, L"\"lodctr.exe\" /m:\"%s\" \"%s\"", pwzFile, pwzResourceFilePath); ExitOnFailure(hr, "failed to copy string in PerfMonManifest"); } else { hr = StrAllocFormatted(&pwzData, L"\"lodctr.exe\" /m:\"%s\"", pwzFile); ExitOnFailure(hr, "failed to copy string in PerfMonManifest"); } WcaLog(LOGMSG_VERBOSE, "RegisterPerfmonManifest's CustomActionData: '%ls'", pwzCommand); hr = WcaDoDeferredAction(PLATFORM_DECORATION(L"RegisterPerfmonManifest"), pwzCommand, COST_PERFMONMANIFEST_REGISTER); ExitOnFailure(hr, "failed to schedule RegisterPerfmonManifest action"); } if (hr == E_NOMOREITEMS) { hr = S_OK; } ExitOnFailure(hr, "Failure while processing PerfMonManifest"); hr = S_OK; LExit: ReleaseStr(pwzData); ReleaseStr(pwzResourceFilePath); ReleaseStr(pwzFile); ReleaseStr(pwzCommand); er = SUCCEEDED(hr) ? ERROR_SUCCESS : ERROR_INSTALL_FAILURE; return WcaFinalize(er); }
/******************************************************************** ConfigureEventManifestRegister - CUSTOM ACTION ENTRY POINT for scheduling Event manifest registering ********************************************************************/ extern "C" UINT __stdcall ConfigureEventManifestUnregister( __in MSIHANDLE hInstall ) { HRESULT hr; UINT er = ERROR_SUCCESS; PMSIHANDLE hView, hRec; LPWSTR pwzData = NULL, pwzFile = NULL, pwzCommand = NULL; INSTALLSTATE isInstalled, isAction; hr = WcaInitialize(hInstall, "ConfigureEventManifestUnreg"); ExitOnFailure(hr, "Failed to initialize"); if (!IsVistaOrAbove()) { WcaLog(LOGMSG_VERBOSE, "Skipping ConfigureEventManifestUnregister() because the target system does not support event manifest"); ExitFunction1(hr = S_FALSE); } // check to see if necessary tables are specified if (S_OK != WcaTableExists(L"EventManifest")) { WcaLog(LOGMSG_VERBOSE, "Skipping ConfigureEventManifestUnregister() because EventManifest table not present"); ExitFunction1(hr = S_FALSE); } hr = WcaOpenExecuteView(vcsEventManifestQuery, &hView); ExitOnFailure(hr, "failed to open view on EventManifest table"); while ((hr = WcaFetchRecord(hView, &hRec)) == S_OK) { // get component install state hr = WcaGetRecordString(hRec, emComponent, &pwzData); ExitOnFailure(hr, "failed to get Component for EventManifest"); er = ::MsiGetComponentStateW(hInstall, pwzData, &isInstalled, &isAction); hr = HRESULT_FROM_WIN32(er); ExitOnFailure(hr, "failed to get Component state for EventManifest"); // nothing to do on an install // schedule the rollback action when reinstalling to re-register pre-patch manifest if (!WcaIsUninstalling(isInstalled, isAction) && !WcaIsReInstalling(isInstalled, isAction)) { continue; } hr = WcaGetRecordFormattedString(hRec, emFile, &pwzFile); ExitOnFailure(hr, "failed to get File for EventManifest"); hr = StrAllocFormatted(&pwzCommand, L"\"wevtutil.exe\" im \"%s\"", pwzFile); ExitOnFailure(hr, "failed to copy string in EventManifest"); hr = WcaDoDeferredAction(PLATFORM_DECORATION(L"RollbackUnregisterEventManifest"), pwzCommand, COST_PERFMONMANIFEST_REGISTER); ExitOnFailure(hr, "failed to schedule RollbackUnregisterEventManifest action"); // no need to uninstall on a repair/patch. Register action will re-register and update the manifest. if (!WcaIsReInstalling(isInstalled, isAction)) { hr = StrAllocFormatted(&pwzCommand, L"\"wevtutil.exe\" um \"%s\"", pwzFile); ExitOnFailure(hr, "failed to copy string in EventManifest"); WcaLog(LOGMSG_VERBOSE, "UnregisterEventManifest's CustomActionData: '%ls'", pwzCommand); hr = WcaDoDeferredAction(PLATFORM_DECORATION(L"UnregisterEventManifest"), pwzCommand, COST_PERFMONMANIFEST_UNREGISTER); ExitOnFailure(hr, "failed to schedule UnregisterEventManifest action"); } } if (hr == E_NOMOREITEMS) { hr = S_OK; } ExitOnFailure(hr, "Failure while processing EventManifest"); hr = S_OK; LExit: ReleaseStr(pwzData); ReleaseStr(pwzFile); ReleaseStr(pwzCommand); er = SUCCEEDED(hr) ? ERROR_SUCCESS : ERROR_INSTALL_FAILURE; return WcaFinalize(er); }