From b4750608b3f9fba47d4fef74ebf4955db2cb62ab Mon Sep 17 00:00:00 2001 From: Simon Rozman Date: Thu, 20 Mar 2014 12:17:08 +0000 Subject: [PATCH] ERROR_SUCCESS => NO_ERROR Dodal sem podporo za upravljanje sistemskih servisov. --- .gitattributes | 1 + MSICACert/MSICACert.cpp | 28 ++-- MSICALib/MSIBuild/Makefile | 3 + MSICALib/MSICALib.cpp | 18 +-- MSICALib/MSICALib.h | 207 ++++++++++++++++++------------ MSICALib/MSICALib.vcxproj | 1 + MSICALib/MSICALib.vcxproj.filters | 3 + MSICALib/OpCert.cpp | 12 +- MSICALib/OpFile.cpp | 12 +- MSICALib/OpReg.cpp | 78 +++++------ MSICALib/OpSvc.cpp | 179 ++++++++++++++++++++++++++ MSICALib/OpTS.cpp | 24 ++-- MSICATS/MSICATS.cpp | 26 ++-- 13 files changed, 413 insertions(+), 179 deletions(-) create mode 100644 MSICALib/OpSvc.cpp diff --git a/.gitattributes b/.gitattributes index 9601add..83a31cd 100644 --- a/.gitattributes +++ b/.gitattributes @@ -23,6 +23,7 @@ MSICALib/MSICALib.vcxproj.filters -text svneol=unset#text/xml MSICALib/OpCert.cpp -text MSICALib/OpFile.cpp -text MSICALib/OpReg.cpp -text +MSICALib/OpSvc.cpp -text MSICALib/OpTS.cpp -text MSICALib/stdafx.cpp -text MSICALib/stdafx.h -text diff --git a/MSICACert/MSICACert.cpp b/MSICACert/MSICACert.cpp index b14956e..a4e66fb 100644 --- a/MSICACert/MSICACert.cpp +++ b/MSICACert/MSICACert.cpp @@ -40,7 +40,7 @@ UINT MSICACERT_API EvaluateSequence(MSIHANDLE hInstall) // Check and add the rollback enabled state. uiResult = ::MsiGetProperty(hInstall, _T("RollbackDisabled"), sValue); - bRollbackEnabled = uiResult == ERROR_SUCCESS ? + bRollbackEnabled = uiResult == NO_ERROR ? _ttoi(sValue) || !sValue.IsEmpty() && _totlower(sValue.GetAt(0)) == _T('y') ? FALSE : TRUE : TRUE; olExecute.AddTail(new MSICA::COpRollbackEnable(bRollbackEnabled)); @@ -55,10 +55,10 @@ UINT MSICACERT_API EvaluateSequence(MSIHANDLE hInstall) // Prepare a query to get a list/view of certificates. uiResult = ::MsiDatabaseOpenView(hDatabase, _T("SELECT Binary_,Store,Flags,Encoding,Condition,Component_ FROM Certificate"), &hViewCert); - if (uiResult == ERROR_SUCCESS) { + if (uiResult == NO_ERROR) { // Execute query! uiResult = ::MsiViewExecute(hViewCert, NULL); - if (uiResult == ERROR_SUCCESS) { + if (uiResult == NO_ERROR) { //ATL::CAtlString sComponent; ATL::CAtlStringW sStore; int iFlags, iEncoding; @@ -72,14 +72,14 @@ UINT MSICACERT_API EvaluateSequence(MSIHANDLE hInstall) // Fetch one record from the view. uiResult = ::MsiViewFetch(hViewCert, &hRecord); if (uiResult == ERROR_NO_MORE_ITEMS) { - uiResult = ERROR_SUCCESS; + uiResult = NO_ERROR; break; - } else if (uiResult != ERROR_SUCCESS) + } else if (uiResult != NO_ERROR) break; // Read and evaluate certificate's condition. uiResult = ::MsiRecordGetString(hRecord, 5, sValue); - if (uiResult != ERROR_SUCCESS) break; + if (uiResult != NO_ERROR) break; condition = ::MsiEvaluateCondition(hInstall, sValue); if (condition == MSICONDITION_FALSE) continue; @@ -90,25 +90,25 @@ UINT MSICACERT_API EvaluateSequence(MSIHANDLE hInstall) // Perform another query to get certificate's binary data. uiResult = ::MsiDatabaseOpenView(hDatabase, _T("SELECT Data FROM Binary WHERE Name=?"), &hViewBinary); - if (uiResult != ERROR_SUCCESS) break; + if (uiResult != NO_ERROR) break; // Execute query! uiResult = ::MsiViewExecute(hViewBinary, hRecord); - if (uiResult == ERROR_SUCCESS) { + if (uiResult == NO_ERROR) { PMSIHANDLE hRecord; // Fetch one record from the view. uiResult = ::MsiViewFetch(hViewBinary, &hRecord); - if (uiResult == ERROR_SUCCESS) + if (uiResult == NO_ERROR) uiResult = ::MsiRecordGetStream(hRecord, 1, binCert); ::MsiViewClose(hViewBinary); - if (uiResult != ERROR_SUCCESS) break; + if (uiResult != NO_ERROR) break; } else break; // Read certificate's store. uiResult = ::MsiRecordGetString(hRecord, 2, sStore); - if (uiResult != ERROR_SUCCESS) break; + if (uiResult != NO_ERROR) break; // Read certificate's flags. iFlags = ::MsiRecordGetInteger(hRecord, 3); @@ -126,11 +126,11 @@ UINT MSICACERT_API EvaluateSequence(MSIHANDLE hInstall) // Read certificate's Component ID. uiResult = ::MsiRecordGetString(hRecord, 6, sValue); - if (uiResult != ERROR_SUCCESS) break; + if (uiResult != NO_ERROR) break; // Get the component state. uiResult = ::MsiGetComponentState(hInstall, sValue, &iInstalled, &iAction); - if (uiResult != ERROR_SUCCESS) break; + if (uiResult != NO_ERROR) break; if (iAction >= INSTALLSTATE_LOCAL) { // Component is or should be installed. Install the certificate. @@ -147,7 +147,7 @@ UINT MSICACERT_API EvaluateSequence(MSIHANDLE hInstall) } ::MsiViewClose(hViewCert); - if (uiResult == ERROR_SUCCESS) { + if (uiResult == NO_ERROR) { // Save the sequences. uiResult = MSICA::SaveSequence(hInstall, _T("InstallCertificates"), _T("CommitCertificates"), _T("RollbackCertificates"), olExecute); } else if (uiResult != ERROR_INSTALL_USEREXIT) { diff --git a/MSICALib/MSIBuild/Makefile b/MSICALib/MSIBuild/Makefile index aeea88c..cbc6a47 100644 --- a/MSICALib/MSIBuild/Makefile +++ b/MSICALib/MSIBuild/Makefile @@ -37,6 +37,9 @@ i2 L0 2559 Error [4] copying "[2]" scheduled task to "[3]". Please, contact your support personnel. 2569 Error [3] installing certificate to certificate store "[2]". Please, contact your support personnel. 2570 Error [3] removing certificate from certificate store "[2]". Please, contact your support personnel. +2571 Error [3] changing service "[2]" start type. Please, contact your support personnel. +2572 Error [3] starting service "[2]". Please, contact your support personnel. +2573 Error [3] stopping service "[2]". Please, contact your support personnel. <>(ATL::CAtlFile &f, COpSvcSetStart &op); + +protected: + DWORD m_dwStartType; +}; + + +//////////////////////////////////////////////////////////////////////////// +// COpSvcStart +//////////////////////////////////////////////////////////////////////////// + +class COpSvcStart : public COpTypeSingleString +{ +public: + COpSvcStart(LPCWSTR pszService = L"", int iTicks = 0); + virtual HRESULT Execute(CSession *pSession); +}; + + +//////////////////////////////////////////////////////////////////////////// +// COpSvcStop +//////////////////////////////////////////////////////////////////////////// + +class COpSvcStop : public COpTypeSingleString +{ +public: + COpSvcStop(LPCWSTR pszService = L"", int iTicks = 0); + virtual HRESULT Execute(CSession *pSession); +}; + + //////////////////////////////////////////////////////////////////////////// // COpList //////////////////////////////////////////////////////////////////////////// @@ -490,6 +535,9 @@ protected: OP_TASK_COPY, OP_CERT_INSTALL, OP_CERT_REMOVE, + OP_SVC_SET_START, + OP_SVC_START, + OP_SVC_STOP, OP_SUBLIST }; @@ -553,12 +601,12 @@ inline UINT MsiGetPropertyA(MSIHANDLE hInstall, LPCSTR szName, ATL::CAtlStringA LPSTR szBuffer = sValue.GetBuffer(dwSize++); if (!szBuffer) return ERROR_OUTOFMEMORY; uiResult = ::MsiGetPropertyA(hInstall, szName, szBuffer, &dwSize); - sValue.ReleaseBuffer(uiResult == ERROR_SUCCESS ? dwSize : 0); + sValue.ReleaseBuffer(uiResult == NO_ERROR ? dwSize : 0); return uiResult; - } else if (uiResult == ERROR_SUCCESS) { + } else if (uiResult == NO_ERROR) { // The string in database is empty. sValue.Empty(); - return ERROR_SUCCESS; + return NO_ERROR; } else { // Return error code. return uiResult; @@ -578,12 +626,12 @@ inline UINT MsiGetPropertyW(MSIHANDLE hInstall, LPCWSTR szName, ATL::CAtlStringW LPWSTR szBuffer = sValue.GetBuffer(dwSize++); if (!szBuffer) return ERROR_OUTOFMEMORY; uiResult = ::MsiGetPropertyW(hInstall, szName, szBuffer, &dwSize); - sValue.ReleaseBuffer(uiResult == ERROR_SUCCESS ? dwSize : 0); + sValue.ReleaseBuffer(uiResult == NO_ERROR ? dwSize : 0); return uiResult; - } else if (uiResult == ERROR_SUCCESS) { + } else if (uiResult == NO_ERROR) { // The string in database is empty. sValue.Empty(); - return ERROR_SUCCESS; + return NO_ERROR; } else { // Return error code. return uiResult; @@ -603,12 +651,12 @@ inline UINT MsiRecordGetStringA(MSIHANDLE hRecord, unsigned int iField, ATL::CAt LPSTR szBuffer = sValue.GetBuffer(dwSize++); if (!szBuffer) return ERROR_OUTOFMEMORY; uiResult = ::MsiRecordGetStringA(hRecord, iField, szBuffer, &dwSize); - sValue.ReleaseBuffer(uiResult == ERROR_SUCCESS ? dwSize : 0); + sValue.ReleaseBuffer(uiResult == NO_ERROR ? dwSize : 0); return uiResult; - } else if (uiResult == ERROR_SUCCESS) { + } else if (uiResult == NO_ERROR) { // The string in database is empty. sValue.Empty(); - return ERROR_SUCCESS; + return NO_ERROR; } else { // Return error code. return uiResult; @@ -628,12 +676,12 @@ inline UINT MsiRecordGetStringW(MSIHANDLE hRecord, unsigned int iField, ATL::CAt LPWSTR szBuffer = sValue.GetBuffer(dwSize++); if (!szBuffer) return ERROR_OUTOFMEMORY; uiResult = ::MsiRecordGetStringW(hRecord, iField, szBuffer, &dwSize); - sValue.ReleaseBuffer(uiResult == ERROR_SUCCESS ? dwSize : 0); + sValue.ReleaseBuffer(uiResult == NO_ERROR ? dwSize : 0); return uiResult; - } else if (uiResult == ERROR_SUCCESS) { + } else if (uiResult == NO_ERROR) { // The string in database is empty. sValue.Empty(); - return ERROR_SUCCESS; + return NO_ERROR; } else { // Return error code. return uiResult; @@ -648,7 +696,7 @@ inline UINT MsiRecordGetStream(MSIHANDLE hRecord, unsigned int iField, ATL::CAtl // Query the actual data length first. uiResult = ::MsiRecordReadStream(hRecord, iField, NULL, &dwSize); - if (uiResult == ERROR_SUCCESS) { + if (uiResult == NO_ERROR) { if (!binData.SetCount(dwSize)) return ERROR_OUTOFMEMORY; return ::MsiRecordReadStream(hRecord, iField, (char*)binData.GetData(), &dwSize); } else { @@ -670,12 +718,12 @@ inline UINT MsiFormatRecordA(MSIHANDLE hInstall, MSIHANDLE hRecord, ATL::CAtlStr LPSTR szBuffer = sValue.GetBuffer(dwSize++); if (!szBuffer) return ERROR_OUTOFMEMORY; uiResult = ::MsiFormatRecordA(hInstall, hRecord, szBuffer, &dwSize); - sValue.ReleaseBuffer(uiResult == ERROR_SUCCESS ? dwSize : 0); + sValue.ReleaseBuffer(uiResult == NO_ERROR ? dwSize : 0); return uiResult; - } else if (uiResult == ERROR_SUCCESS) { + } else if (uiResult == NO_ERROR) { // The result is empty. sValue.Empty(); - return ERROR_SUCCESS; + return NO_ERROR; } else { // Return error code. return uiResult; @@ -695,12 +743,12 @@ inline UINT MsiFormatRecordW(MSIHANDLE hInstall, MSIHANDLE hRecord, ATL::CAtlStr LPWSTR szBuffer = sValue.GetBuffer(dwSize++); if (!szBuffer) return ERROR_OUTOFMEMORY; uiResult = ::MsiFormatRecordW(hInstall, hRecord, szBuffer, &dwSize); - sValue.ReleaseBuffer(uiResult == ERROR_SUCCESS ? dwSize : 0); + sValue.ReleaseBuffer(uiResult == NO_ERROR ? dwSize : 0); return uiResult; - } else if (uiResult == ERROR_SUCCESS) { + } else if (uiResult == NO_ERROR) { // The result is empty. sValue.Empty(); - return ERROR_SUCCESS; + return NO_ERROR; } else { // Return error code. return uiResult; @@ -715,10 +763,10 @@ inline UINT MsiRecordFormatStringA(MSIHANDLE hInstall, MSIHANDLE hRecord, unsign // Read string to format. uiResult = ::MsiRecordGetStringA(hRecord, iField, sValue); - if (uiResult != ERROR_SUCCESS) return uiResult; + if (uiResult != NO_ERROR) return uiResult; // If the string is empty, there's nothing left to do. - if (sValue.IsEmpty()) return ERROR_SUCCESS; + if (sValue.IsEmpty()) return NO_ERROR; // Create a record. hRecordEx = ::MsiCreateRecord(1); @@ -726,7 +774,7 @@ inline UINT MsiRecordFormatStringA(MSIHANDLE hInstall, MSIHANDLE hRecord, unsign // Populate record with data. uiResult = ::MsiRecordSetStringA(hRecordEx, 0, sValue); - if (uiResult != ERROR_SUCCESS) return uiResult; + if (uiResult != NO_ERROR) return uiResult; // Do the formatting. return ::MsiFormatRecordA(hInstall, hRecordEx, sValue); @@ -740,10 +788,10 @@ inline UINT MsiRecordFormatStringW(MSIHANDLE hInstall, MSIHANDLE hRecord, unsign // Read string to format. uiResult = ::MsiRecordGetStringW(hRecord, iField, sValue); - if (uiResult != ERROR_SUCCESS) return uiResult; + if (uiResult != NO_ERROR) return uiResult; // If the string is empty, there's nothing left to do. - if (sValue.IsEmpty()) return ERROR_SUCCESS; + if (sValue.IsEmpty()) return NO_ERROR; // Create a record. hRecordEx = ::MsiCreateRecord(1); @@ -751,7 +799,7 @@ inline UINT MsiRecordFormatStringW(MSIHANDLE hInstall, MSIHANDLE hRecord, unsign // Populate record with data. uiResult = ::MsiRecordSetStringW(hRecordEx, 0, sValue); - if (uiResult != ERROR_SUCCESS) return uiResult; + if (uiResult != NO_ERROR) return uiResult; // Do the formatting. return ::MsiFormatRecordW(hInstall, hRecordEx, sValue); @@ -776,12 +824,12 @@ inline UINT MsiGetTargetPathA(MSIHANDLE hInstall, LPCSTR szFolder, ATL::CAtlStri LPSTR szBuffer = sValue.GetBuffer(dwSize++); if (!szBuffer) return ERROR_OUTOFMEMORY; uiResult = ::MsiGetTargetPathA(hInstall, szFolder, szBuffer, &dwSize); - sValue.ReleaseBuffer(uiResult == ERROR_SUCCESS ? dwSize : 0); + sValue.ReleaseBuffer(uiResult == NO_ERROR ? dwSize : 0); return uiResult; - } else if (uiResult == ERROR_SUCCESS) { + } else if (uiResult == NO_ERROR) { // The result is empty. sValue.Empty(); - return ERROR_SUCCESS; + return NO_ERROR; } else { // Return error code. return uiResult; @@ -801,12 +849,12 @@ inline UINT MsiGetTargetPathW(MSIHANDLE hInstall, LPCWSTR szFolder, ATL::CAtlStr LPWSTR szBuffer = sValue.GetBuffer(dwSize++); if (!szBuffer) return ERROR_OUTOFMEMORY; uiResult = ::MsiGetTargetPathW(hInstall, szFolder, szBuffer, &dwSize); - sValue.ReleaseBuffer(uiResult == ERROR_SUCCESS ? dwSize : 0); + sValue.ReleaseBuffer(uiResult == NO_ERROR ? dwSize : 0); return uiResult; - } else if (uiResult == ERROR_SUCCESS) { + } else if (uiResult == NO_ERROR) { // The result is empty. sValue.Empty(); - return ERROR_SUCCESS; + return NO_ERROR; } else { // Return error code. return uiResult; @@ -1368,6 +1416,28 @@ inline HRESULT operator >>(ATL::CAtlFile &f, COpCert &op) } +inline HRESULT operator <<(ATL::CAtlFile &f, const COpSvcSetStart &op) +{ + HRESULT hr; + + hr = f << (const COpTypeSingleString&)op; if (FAILED(hr)) return hr; + hr = f << (int)(op.m_dwStartType); if (FAILED(hr)) return hr; + + return S_OK; +} + + +inline HRESULT operator >>(ATL::CAtlFile &f, COpSvcSetStart &op) +{ + HRESULT hr; + + hr = f >> (COpTypeSingleString&)op; if (FAILED(hr)) return hr; + hr = f >> (int&)(op.m_dwStartType); if (FAILED(hr)) return hr; + + return S_OK; +} + + inline HRESULT operator <<(ATL::CAtlFile &f, const COpList &list) { POSITION pos; @@ -1411,6 +1481,12 @@ inline HRESULT operator <<(ATL::CAtlFile &f, const COpList &list) hr = list.Save(f, pOp); else if (dynamic_cast(pOp)) hr = list.Save(f, pOp); + else if (dynamic_cast(pOp)) + hr = list.Save(f, pOp); + else if (dynamic_cast(pOp)) + hr = list.Save(f, pOp); + else if (dynamic_cast(pOp)) + hr = list.Save(f, pOp); else if (dynamic_cast(pOp)) hr = list.Save(f, pOp); else { @@ -1443,54 +1519,25 @@ inline HRESULT operator >>(ATL::CAtlFile &f, COpList &list) if (FAILED(hr)) return hr; switch ((COpList::OPERATION)iTemp) { - case COpList::OP_ROLLBACK_ENABLE: - hr = list.LoadAndAddTail(f); - break; - case COpList::OP_FILE_DELETE: - hr = list.LoadAndAddTail(f); - break; - case COpList::OP_FILE_MOVE: - hr = list.LoadAndAddTail(f); - break; - case COpList::OP_REG_KEY_CREATE: - hr = list.LoadAndAddTail(f); - break; - case COpList::OP_REG_KEY_COPY: - hr = list.LoadAndAddTail(f); - break; - case COpList::OP_REG_KEY_DELETE: - hr = list.LoadAndAddTail(f); - break; - case COpList::OP_REG_VALUE_CREATE: - hr = list.LoadAndAddTail(f); - break; - case COpList::OP_REG_VALUE_COPY: - hr = list.LoadAndAddTail(f); - break; - case COpList::OP_REG_VALUE_DELETE: - hr = list.LoadAndAddTail(f); - break; - case COpList::OP_TASK_CREATE: - hr = list.LoadAndAddTail(f); - break; - case COpList::OP_TASK_DELETE: - hr = list.LoadAndAddTail(f); - break; - case COpList::OP_TASK_ENABLE: - hr = list.LoadAndAddTail(f); - break; - case COpList::OP_TASK_COPY: - hr = list.LoadAndAddTail(f); - break; - case COpList::OP_CERT_INSTALL: - hr = list.LoadAndAddTail(f); - break; - case COpList::OP_CERT_REMOVE: - hr = list.LoadAndAddTail(f); - break; - case COpList::OP_SUBLIST: - hr = list.LoadAndAddTail(f); - break; + case COpList::OP_ROLLBACK_ENABLE: hr = list.LoadAndAddTail(f); break; + case COpList::OP_FILE_DELETE: hr = list.LoadAndAddTail(f); break; + case COpList::OP_FILE_MOVE: hr = list.LoadAndAddTail(f); break; + case COpList::OP_REG_KEY_CREATE: hr = list.LoadAndAddTail(f); break; + case COpList::OP_REG_KEY_COPY: hr = list.LoadAndAddTail(f); break; + case COpList::OP_REG_KEY_DELETE: hr = list.LoadAndAddTail(f); break; + case COpList::OP_REG_VALUE_CREATE: hr = list.LoadAndAddTail(f); break; + case COpList::OP_REG_VALUE_COPY: hr = list.LoadAndAddTail(f); break; + case COpList::OP_REG_VALUE_DELETE: hr = list.LoadAndAddTail(f); break; + case COpList::OP_TASK_CREATE: hr = list.LoadAndAddTail(f); break; + case COpList::OP_TASK_DELETE: hr = list.LoadAndAddTail(f); break; + case COpList::OP_TASK_ENABLE: hr = list.LoadAndAddTail(f); break; + case COpList::OP_TASK_COPY: hr = list.LoadAndAddTail(f); break; + case COpList::OP_CERT_INSTALL: hr = list.LoadAndAddTail(f); break; + case COpList::OP_CERT_REMOVE: hr = list.LoadAndAddTail(f); break; + case COpList::OP_SVC_SET_START: hr = list.LoadAndAddTail(f); break; + case COpList::OP_SVC_START: hr = list.LoadAndAddTail(f); break; + case COpList::OP_SVC_STOP: hr = list.LoadAndAddTail(f); break; + case COpList::OP_SUBLIST: hr = list.LoadAndAddTail(f); break; default: // Unsupported type of operation. hr = E_UNEXPECTED; diff --git a/MSICALib/MSICALib.vcxproj b/MSICALib/MSICALib.vcxproj index cf1a6d1..e01d031 100644 --- a/MSICALib/MSICALib.vcxproj +++ b/MSICALib/MSICALib.vcxproj @@ -22,6 +22,7 @@ + diff --git a/MSICALib/MSICALib.vcxproj.filters b/MSICALib/MSICALib.vcxproj.filters index 9227914..7f72ba2 100644 --- a/MSICALib/MSICALib.vcxproj.filters +++ b/MSICALib/MSICALib.vcxproj.filters @@ -33,6 +33,9 @@ Source Files + + Source Files + diff --git a/MSICALib/OpCert.cpp b/MSICALib/OpCert.cpp index 9adf5b0..0b9d1de 100644 --- a/MSICALib/OpCert.cpp +++ b/MSICALib/OpCert.cpp @@ -64,12 +64,12 @@ HRESULT COpCertInstall::Execute(CSession *pSession) // Order rollback action to delete the certificate. pSession->m_olRollback.AddHead(new COpCertRemove(m_binCert.GetData(), m_binCert.GetCount(), m_sValue, m_dwEncodingType, m_dwFlags)); } - dwError = ERROR_SUCCESS; + dwError = NO_ERROR; } else { dwError = ::GetLastError(); if (dwError == CRYPT_E_EXISTS) { // Certificate store already contains given certificate. Nothing to install then. - dwError = ERROR_SUCCESS; + dwError = NO_ERROR; } } ::CertFreeCertificateContext(pCertContext); @@ -79,7 +79,7 @@ HRESULT COpCertInstall::Execute(CSession *pSession) } else dwError = ::GetLastError(); - if (dwError == ERROR_SUCCESS) + if (dwError == NO_ERROR) return S_OK; else { PMSIHANDLE hRecordProg = ::MsiCreateRecord(3); @@ -130,14 +130,14 @@ HRESULT COpCertRemove::Execute(CSession *pSession) // Order rollback action to reinstall the certificate. pSession->m_olRollback.AddHead(new COpCertInstall(m_binCert.GetData(), m_binCert.GetCount(), m_sValue, m_dwEncodingType, m_dwFlags)); } - dwError = ERROR_SUCCESS; + dwError = NO_ERROR; } else { dwError = ::GetLastError(); ::CertFreeCertificateContext(pCertContextExisting); } } else { // We haven't found the certificate. Nothing to delete then. - dwError = ERROR_SUCCESS; + dwError = NO_ERROR; } ::CertFreeCertificateContext(pCertContext); } else @@ -146,7 +146,7 @@ HRESULT COpCertRemove::Execute(CSession *pSession) } else dwError = ::GetLastError(); - if (dwError == ERROR_SUCCESS) + if (dwError == NO_ERROR) return S_OK; else { PMSIHANDLE hRecordProg = ::MsiCreateRecord(3); diff --git a/MSICALib/OpFile.cpp b/MSICALib/OpFile.cpp index b49de6d..eaa74b5 100644 --- a/MSICALib/OpFile.cpp +++ b/MSICALib/OpFile.cpp @@ -24,9 +24,9 @@ HRESULT COpFileDelete::Execute(CSession *pSession) do { // Rename the file to make a backup. sBackupName.Format(L"%ls (orig %u)", (LPCWSTR)m_sValue, ++uiCount); - dwError = ::MoveFileW(m_sValue, sBackupName) ? ERROR_SUCCESS : ::GetLastError(); + dwError = ::MoveFileW(m_sValue, sBackupName) ? NO_ERROR : ::GetLastError(); } while (dwError == ERROR_ALREADY_EXISTS); - if (dwError == ERROR_SUCCESS) { + if (dwError == NO_ERROR) { // Order rollback action to restore from backup copy. pSession->m_olRollback.AddHead(new COpFileMove(sBackupName, m_sValue)); @@ -35,10 +35,10 @@ HRESULT COpFileDelete::Execute(CSession *pSession) } } else { // Delete the file. - dwError = ::DeleteFileW(m_sValue) ? ERROR_SUCCESS : ::GetLastError(); + dwError = ::DeleteFileW(m_sValue) ? NO_ERROR : ::GetLastError(); } - if (dwError == ERROR_SUCCESS || dwError == ERROR_FILE_NOT_FOUND) + if (dwError == NO_ERROR || dwError == ERROR_FILE_NOT_FOUND) return S_OK; else { PMSIHANDLE hRecordProg = ::MsiCreateRecord(3); @@ -66,8 +66,8 @@ HRESULT COpFileMove::Execute(CSession *pSession) DWORD dwError; // Move the file. - dwError = ::MoveFileW(m_sValue1, m_sValue2) ? ERROR_SUCCESS : ::GetLastError(); - if (dwError == ERROR_SUCCESS) { + dwError = ::MoveFileW(m_sValue1, m_sValue2) ? NO_ERROR : ::GetLastError(); + if (dwError == NO_ERROR) { if (pSession->m_bRollbackEnabled) { // Order rollback action to move it back. pSession->m_olRollback.AddHead(new COpFileMove(m_sValue2, m_sValue1)); diff --git a/MSICALib/OpReg.cpp b/MSICALib/OpReg.cpp index c872a7a..a651450 100644 --- a/MSICALib/OpReg.cpp +++ b/MSICALib/OpReg.cpp @@ -70,9 +70,9 @@ HRESULT COpRegKeyCreate::Execute(CSession *pSession) // Create the key. lResult = ::RegCreateKeyExW(m_hKeyRoot, sPartialName, NULL, NULL, REG_OPTION_NON_VOLATILE, KEY_ENUMERATE_SUB_KEYS | samAdditional, NULL, &hKey, NULL); - if (lResult != ERROR_SUCCESS) break; + if (lResult != NO_ERROR) break; ::RegCloseKey(hKey); - } else if (lResult == ERROR_SUCCESS) { + } else if (lResult == NO_ERROR) { // This key already exists. Release its handle and continue. ::RegCloseKey(hKey); } else @@ -82,7 +82,7 @@ HRESULT COpRegKeyCreate::Execute(CSession *pSession) iStart = iStartNext + 1; } - if (lResult == ERROR_SUCCESS) + if (lResult == NO_ERROR) return S_OK; else { PMSIHANDLE hRecordProg = ::MsiCreateRecord(4); @@ -133,7 +133,7 @@ HRESULT COpRegKeyCopy::Execute(CSession *pSession) // Copy the registry key. lResult = CopyKeyRecursively(m_hKeyRoot, m_sValue1, m_sValue2, samAdditional); - if (lResult == ERROR_SUCCESS) + if (lResult == NO_ERROR) return S_OK; else { PMSIHANDLE hRecordProg = ::MsiCreateRecord(5); @@ -155,7 +155,7 @@ LONG COpRegKeyCopy::CopyKeyRecursively(HKEY hKeyRoot, LPCWSTR pszKeyNameSrc, LPC // Open source key. lResult = ::RegOpenKeyExW(hKeyRoot, pszKeyNameSrc, 0, READ_CONTROL | KEY_READ | samAdditional, &hKeySrc); - if (lResult != ERROR_SUCCESS) return lResult; + if (lResult != NO_ERROR) return lResult; { DWORD dwSecurityDescriptorSize, dwClassLen = MAX_PATH; @@ -164,7 +164,7 @@ LONG COpRegKeyCopy::CopyKeyRecursively(HKEY hKeyRoot, LPCWSTR pszKeyNameSrc, LPC // Get source key class length and security descriptor size. lResult = ::RegQueryInfoKeyW(hKeySrc, pszClass, &dwClassLen, NULL, NULL, NULL, NULL, NULL, NULL, NULL, &dwSecurityDescriptorSize, NULL); - if (lResult != ERROR_SUCCESS) { + if (lResult != NO_ERROR) { delete [] pszClass; return lResult; } @@ -173,7 +173,7 @@ LONG COpRegKeyCopy::CopyKeyRecursively(HKEY hKeyRoot, LPCWSTR pszKeyNameSrc, LPC // Get source key security descriptor. sa.lpSecurityDescriptor = (PSECURITY_DESCRIPTOR)(new BYTE[dwSecurityDescriptorSize]); lResult = ::RegGetKeySecurity(hKeySrc, DACL_SECURITY_INFORMATION, sa.lpSecurityDescriptor, &dwSecurityDescriptorSize); - if (lResult != ERROR_SUCCESS) { + if (lResult != NO_ERROR) { delete [] (LPBYTE)(sa.lpSecurityDescriptor); delete [] pszClass; return lResult; @@ -183,7 +183,7 @@ LONG COpRegKeyCopy::CopyKeyRecursively(HKEY hKeyRoot, LPCWSTR pszKeyNameSrc, LPC lResult = ::RegCreateKeyExW(hKeyRoot, pszKeyNameDst, 0, pszClass, REG_OPTION_NON_VOLATILE, KEY_WRITE | samAdditional, &sa, &hKeyDst, NULL); delete [] (LPBYTE)(sa.lpSecurityDescriptor); delete [] pszClass; - if (lResult != ERROR_SUCCESS) return lResult; + if (lResult != NO_ERROR) return lResult; } // Copy subkey recursively. @@ -200,7 +200,7 @@ LONG COpRegKeyCopy::CopyKeyRecursively(HKEY hKeySrc, HKEY hKeyDst, REGSAM samAdd // Query the source key. lResult = ::RegQueryInfoKeyW(hKeySrc, NULL, NULL, NULL, NULL, &dwMaxSubKeyLen, &dwMaxClassLen, NULL, &dwMaxValueNameLen, &dwMaxDataSize, NULL, NULL); - if (lResult != ERROR_SUCCESS) return lResult; + if (lResult != NO_ERROR) return lResult; // Copy values first. dwMaxValueNameLen++; @@ -212,19 +212,19 @@ LONG COpRegKeyCopy::CopyKeyRecursively(HKEY hKeySrc, HKEY hKeyDst, REGSAM samAdd // Read value. lResult = ::RegEnumValueW(hKeySrc, dwIndex, pszName, &dwNameLen, NULL, &dwType, lpData, &dwValueSize); if (lResult == ERROR_NO_MORE_ITEMS) { - lResult = ERROR_SUCCESS; + lResult = NO_ERROR; break; - } else if (lResult != ERROR_SUCCESS) + } else if (lResult != NO_ERROR) break; // Save value. lResult = ::RegSetValueExW(hKeyDst, pszName, 0, dwType, lpData, dwValueSize); - if (lResult != ERROR_SUCCESS) + if (lResult != NO_ERROR) break; } delete [] lpData; delete [] pszName; - if (lResult != ERROR_SUCCESS) return lResult; + if (lResult != NO_ERROR) return lResult; // Iterate over all subkeys and copy them. dwMaxSubKeyLen++; @@ -238,14 +238,14 @@ LONG COpRegKeyCopy::CopyKeyRecursively(HKEY hKeySrc, HKEY hKeyDst, REGSAM samAdd // Read subkey. lResult = ::RegEnumKeyExW(hKeySrc, dwIndex, pszName, &dwNameLen, NULL, pszClass, &dwClassLen, NULL); if (lResult == ERROR_NO_MORE_ITEMS) { - lResult = ERROR_SUCCESS; + lResult = NO_ERROR; break; - } else if (lResult != ERROR_SUCCESS) + } else if (lResult != NO_ERROR) break; // Open source subkey. lResult = ::RegOpenKeyExW(hKeySrc, pszName, 0, READ_CONTROL | KEY_READ | samAdditional, &hKeySrcSub); - if (lResult != ERROR_SUCCESS) break; + if (lResult != NO_ERROR) break; { DWORD dwSecurityDescriptorSize; @@ -253,12 +253,12 @@ LONG COpRegKeyCopy::CopyKeyRecursively(HKEY hKeySrc, HKEY hKeyDst, REGSAM samAdd // Get source subkey security descriptor size. lResult = ::RegQueryInfoKeyW(hKeySrcSub, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, &dwSecurityDescriptorSize, NULL); - if (lResult != ERROR_SUCCESS) break; + if (lResult != NO_ERROR) break; // Get source subkey security descriptor. sa.lpSecurityDescriptor = (PSECURITY_DESCRIPTOR)(new BYTE[dwSecurityDescriptorSize]); lResult = ::RegGetKeySecurity(hKeySrc, DACL_SECURITY_INFORMATION, sa.lpSecurityDescriptor, &dwSecurityDescriptorSize); - if (lResult != ERROR_SUCCESS) { + if (lResult != NO_ERROR) { delete [] (LPBYTE)(sa.lpSecurityDescriptor); break; } @@ -266,12 +266,12 @@ LONG COpRegKeyCopy::CopyKeyRecursively(HKEY hKeySrc, HKEY hKeyDst, REGSAM samAdd // Create new destination subkey of the same class and security. lResult = ::RegCreateKeyExW(hKeyDst, pszName, 0, pszClass, REG_OPTION_NON_VOLATILE, KEY_WRITE | samAdditional, &sa, &hKeyDstSub, NULL); delete [] (LPBYTE)(sa.lpSecurityDescriptor); - if (lResult != ERROR_SUCCESS) break; + if (lResult != NO_ERROR) break; } // Copy subkey recursively. lResult = CopyKeyRecursively(hKeySrcSub, hKeyDstSub, samAdditional); - if (lResult != ERROR_SUCCESS) break; + if (lResult != NO_ERROR) break; } delete [] pszClass; delete [] pszName; @@ -304,7 +304,7 @@ HRESULT COpRegKeyDelete::Execute(CSession *pSession) // Probe to see if the key exists. lResult = ::RegOpenKeyExW(m_hKeyRoot, m_sValue, 0, DELETE | samAdditional, &hKey); - if (lResult == ERROR_SUCCESS) { + if (lResult == NO_ERROR) { ::RegCloseKey(hKey); if (pSession->m_bRollbackEnabled) { @@ -320,7 +320,7 @@ HRESULT COpRegKeyDelete::Execute(CSession *pSession) HKEY hKey; sBackupName.Format(L"%.*ls (orig %u)", iLength, (LPCWSTR)m_sValue, ++uiCount); lResult = ::RegOpenKeyExW(m_hKeyRoot, sBackupName, 0, KEY_ENUMERATE_SUB_KEYS | samAdditional, &hKey); - if (lResult != ERROR_SUCCESS) break; + if (lResult != NO_ERROR) break; ::RegCloseKey(hKey); } if (lResult == ERROR_FILE_NOT_FOUND) { @@ -349,7 +349,7 @@ HRESULT COpRegKeyDelete::Execute(CSession *pSession) lResult = DeleteKeyRecursively(m_hKeyRoot, m_sValue, samAdditional); } - if (lResult == ERROR_SUCCESS || lResult == ERROR_FILE_NOT_FOUND) + if (lResult == NO_ERROR || lResult == ERROR_FILE_NOT_FOUND) return S_OK; else { PMSIHANDLE hRecordProg = ::MsiCreateRecord(4); @@ -370,12 +370,12 @@ LONG COpRegKeyDelete::DeleteKeyRecursively(HKEY hKeyRoot, LPCWSTR pszKeyName, RE // Open the key. lResult = ::RegOpenKeyExW(hKeyRoot, pszKeyName, 0, DELETE | KEY_READ | samAdditional, &hKey); - if (lResult == ERROR_SUCCESS) { + if (lResult == NO_ERROR) { DWORD dwMaxSubKeyLen; // Determine the largest subkey name. lResult = ::RegQueryInfoKeyW(hKey, NULL, NULL, NULL, NULL, &dwMaxSubKeyLen, NULL, NULL, NULL, NULL, NULL, NULL); - if (lResult == ERROR_SUCCESS) { + if (lResult == NO_ERROR) { LPWSTR pszSubKeyName; // Prepare buffer to hold the subkey names (including zero terminator). @@ -388,12 +388,12 @@ LONG COpRegKeyDelete::DeleteKeyRecursively(HKEY hKeyRoot, LPCWSTR pszKeyName, RE for (dwIndex = 0; ;) { DWORD dwNameLen = dwMaxSubKeyLen; lResult = ::RegEnumKeyExW(hKey, dwIndex, pszSubKeyName, &dwNameLen, NULL, NULL, NULL, NULL); - if (lResult == ERROR_SUCCESS) { + if (lResult == NO_ERROR) { lResult = DeleteKeyRecursively(hKey, pszSubKeyName, samAdditional); - if (lResult != ERROR_SUCCESS) + if (lResult != NO_ERROR) dwIndex++; } else if (lResult == ERROR_NO_MORE_ITEMS) { - lResult = ERROR_SUCCESS; + lResult = NO_ERROR; break; } else dwIndex++; @@ -410,7 +410,7 @@ LONG COpRegKeyDelete::DeleteKeyRecursively(HKEY hKeyRoot, LPCWSTR pszKeyName, RE lResult = ::RegDeleteKeyW(hKeyRoot, pszKeyName); } else if (lResult == ERROR_FILE_NOT_FOUND) { // The key doesn't exist. Not really an error in this case. - lResult = ERROR_SUCCESS; + lResult = NO_ERROR; } return lResult; @@ -508,7 +508,7 @@ HRESULT COpRegValueCreate::Execute(CSession *pSession) // Open the key. lResult = ::RegOpenKeyExW(m_hKeyRoot, m_sValue, 0, sam, &hKey); - if (lResult == ERROR_SUCCESS) { + if (lResult == NO_ERROR) { if (pSession->m_bRollbackEnabled) { // Order rollback action to delete the value. pSession->m_olRollback.AddHead(new COpRegValueDelete(m_hKeyRoot, m_sValue, m_sValueName)); @@ -545,7 +545,7 @@ HRESULT COpRegValueCreate::Execute(CSession *pSession) ::RegCloseKey(hKey); } - if (lResult == ERROR_SUCCESS) + if (lResult == NO_ERROR) return S_OK; else { PMSIHANDLE hRecordProg = ::MsiCreateRecord(5); @@ -593,16 +593,16 @@ HRESULT COpRegValueCopy::Execute(CSession *pSession) // Open the key. lResult = ::RegOpenKeyExW(m_hKeyRoot, m_sValue, 0, sam, &hKey); - if (lResult == ERROR_SUCCESS) { + if (lResult == NO_ERROR) { DWORD dwType, dwSize; // Query the source registry value size. lResult = ::RegQueryValueExW(hKey, m_sValueName1, 0, NULL, NULL, &dwSize); - if (lResult == ERROR_SUCCESS) { + if (lResult == NO_ERROR) { LPBYTE lpData = new BYTE[dwSize]; // Read the source registry value. lResult = ::RegQueryValueExW(hKey, m_sValueName1, 0, &dwType, lpData, &dwSize); - if (lResult == ERROR_SUCCESS) { + if (lResult == NO_ERROR) { if (pSession->m_bRollbackEnabled) { // Order rollback action to delete the destination copy. pSession->m_olRollback.AddHead(new COpRegValueDelete(m_hKeyRoot, m_sValue, m_sValueName2)); @@ -617,7 +617,7 @@ HRESULT COpRegValueCopy::Execute(CSession *pSession) ::RegCloseKey(hKey); } - if (lResult == ERROR_SUCCESS) + if (lResult == NO_ERROR) return S_OK; else { PMSIHANDLE hRecordProg = ::MsiCreateRecord(6); @@ -657,12 +657,12 @@ HRESULT COpRegValueDelete::Execute(CSession *pSession) // Open the key. lResult = ::RegOpenKeyExW(m_hKeyRoot, m_sValue, 0, sam, &hKey); - if (lResult == ERROR_SUCCESS) { + if (lResult == NO_ERROR) { DWORD dwType; // See if the value exists at all. lResult = ::RegQueryValueExW(hKey, m_sValueName, 0, &dwType, NULL, NULL); - if (lResult == ERROR_SUCCESS) { + if (lResult == NO_ERROR) { if (pSession->m_bRollbackEnabled) { // Make a backup of the value first. ATL::CAtlStringW sBackupName; @@ -671,7 +671,7 @@ HRESULT COpRegValueDelete::Execute(CSession *pSession) for (;;) { sBackupName.Format(L"%ls (orig %u)", (LPCWSTR)m_sValueName, ++uiCount); lResult = ::RegQueryValueExW(hKey, sBackupName, 0, &dwType, NULL, NULL); - if (lResult != ERROR_SUCCESS) break; + if (lResult != NO_ERROR) break; } if (lResult == ERROR_FILE_NOT_FOUND) { // Since copying registry value is a complicated job (when rollback/commit support is required), and we do have an operation just for that, we use it. @@ -707,7 +707,7 @@ HRESULT COpRegValueDelete::Execute(CSession *pSession) ::RegCloseKey(hKey); } - if (lResult == ERROR_SUCCESS || lResult == ERROR_FILE_NOT_FOUND) + if (lResult == NO_ERROR || lResult == ERROR_FILE_NOT_FOUND) return S_OK; else { PMSIHANDLE hRecordProg = ::MsiCreateRecord(5); diff --git a/MSICALib/OpSvc.cpp b/MSICALib/OpSvc.cpp new file mode 100644 index 0000000..d0a04de --- /dev/null +++ b/MSICALib/OpSvc.cpp @@ -0,0 +1,179 @@ +#include "stdafx.h" + +#pragma comment(lib, "advapi32.lib") + + +namespace MSICA { + +//////////////////////////////////////////////////////////////////////////// +// COpSvcSetStart +//////////////////////////////////////////////////////////////////////////// + +COpSvcSetStart::COpSvcSetStart(LPCWSTR pszService, DWORD dwStartType, int iTicks) : + COpTypeSingleString(pszService, iTicks), + m_dwStartType(dwStartType) +{ +} + + +HRESULT COpSvcSetStart::Execute(CSession *pSession) +{ + DWORD dwError; + SC_HANDLE hSCM; + + // Open Service Control Manager. + hSCM = ::OpenSCManager(NULL, SERVICES_ACTIVE_DATABASE, SC_MANAGER_CONNECT); + if (hSCM) { + SC_HANDLE hService; + + // Open the specified service. + hService = ::OpenServiceW(hSCM, m_sValue, SERVICE_QUERY_CONFIG | SERVICE_CHANGE_CONFIG); + if (hService) { + QUERY_SERVICE_CONFIG sc; + DWORD dwSize; + + // Query current service config. + if (::QueryServiceConfig(hService, &sc, sizeof(sc), &dwSize)) { + if (sc.dwStartType != m_dwStartType) { + // Set requested service start. + if (::ChangeServiceConfig(hService, SERVICE_NO_CHANGE, m_dwStartType, SERVICE_NO_CHANGE, NULL, NULL, NULL, NULL, NULL, NULL, NULL)) { + if (pSession->m_bRollbackEnabled) { + // Order rollback action to revert the service start change. + pSession->m_olRollback.AddHead(new COpSvcSetStart(m_sValue, sc.dwStartType)); + } + dwError = NO_ERROR; + } else + dwError = ::GetLastError(); + } else { + // Service is already configured to start the requested way. + dwError = NO_ERROR; + } + } else + dwError = ::GetLastError(); + } else + dwError = ::GetLastError(); + } else + dwError = ::GetLastError(); + + if (dwError == NO_ERROR) + return S_OK; + else { + PMSIHANDLE hRecordProg = ::MsiCreateRecord(3); + ::MsiRecordSetInteger(hRecordProg, 1, ERROR_INSTALL_SVC_SET_START_FAILED); + ::MsiRecordSetStringW(hRecordProg, 2, m_sValue ); + ::MsiRecordSetInteger(hRecordProg, 3, dwError ); + ::MsiProcessMessage(pSession->m_hInstall, INSTALLMESSAGE_ERROR, hRecordProg); + return AtlHresultFromWin32(dwError); + } +} + + +//////////////////////////////////////////////////////////////////////////// +// COpSvcStart +//////////////////////////////////////////////////////////////////////////// + +COpSvcStart::COpSvcStart(LPCWSTR pszService, int iTicks) : COpTypeSingleString(pszService, iTicks) +{ +} + + +HRESULT COpSvcStart::Execute(CSession *pSession) +{ + DWORD dwError; + SC_HANDLE hSCM; + + // Open Service Control Manager. + hSCM = ::OpenSCManager(NULL, SERVICES_ACTIVE_DATABASE, SC_MANAGER_CONNECT); + if (hSCM) { + SC_HANDLE hService; + + // Open the specified service. + hService = ::OpenServiceW(hSCM, m_sValue, SERVICE_START); + if (hService) { + // Start the service. + if (::StartService(hService, 0, NULL)) { + if (pSession->m_bRollbackEnabled) { + // Order rollback action to stop the service. + pSession->m_olRollback.AddHead(new COpSvcStop(m_sValue)); + } + dwError = NO_ERROR; + } else { + dwError = ::GetLastError(); + if (dwError == ERROR_SERVICE_ALREADY_RUNNING) { + // Service is already running. Not an error. + dwError = NO_ERROR; + } + } + } else + dwError = ::GetLastError(); + } else + dwError = ::GetLastError(); + + if (dwError == NO_ERROR) + return S_OK; + else { + PMSIHANDLE hRecordProg = ::MsiCreateRecord(3); + ::MsiRecordSetInteger(hRecordProg, 1, ERROR_INSTALL_SVC_START_FAILED); + ::MsiRecordSetStringW(hRecordProg, 2, m_sValue ); + ::MsiRecordSetInteger(hRecordProg, 3, dwError ); + ::MsiProcessMessage(pSession->m_hInstall, INSTALLMESSAGE_ERROR, hRecordProg); + return AtlHresultFromWin32(dwError); + } +} + + +//////////////////////////////////////////////////////////////////////////// +// COpSvcStop +//////////////////////////////////////////////////////////////////////////// + +COpSvcStop::COpSvcStop(LPCWSTR pszService, int iTicks) : COpTypeSingleString(pszService, iTicks) +{ +} + + +HRESULT COpSvcStop::Execute(CSession *pSession) +{ + DWORD dwError; + SC_HANDLE hSCM; + + // Open Service Control Manager. + hSCM = ::OpenSCManager(NULL, SERVICES_ACTIVE_DATABASE, SC_MANAGER_CONNECT); + if (hSCM) { + SC_HANDLE hService; + + // Open the specified service. + hService = ::OpenServiceW(hSCM, m_sValue, SERVICE_STOP); + if (hService) { + SERVICE_STATUS ss; + // Stop the service. + if (::ControlService(hService, SERVICE_CONTROL_STOP, &ss)) { + if (pSession->m_bRollbackEnabled) { + // Order rollback action to start the service. + pSession->m_olRollback.AddHead(new COpSvcStart(m_sValue)); + } + dwError = NO_ERROR; + } else { + dwError = ::GetLastError(); + if (dwError == ERROR_SERVICE_NOT_ACTIVE) { + // Service is already stopped. Not an error. + dwError = NO_ERROR; + } + } + } else + dwError = ::GetLastError(); + } else + dwError = ::GetLastError(); + + if (dwError == NO_ERROR) + return S_OK; + else { + PMSIHANDLE hRecordProg = ::MsiCreateRecord(3); + ::MsiRecordSetInteger(hRecordProg, 1, ERROR_INSTALL_SVC_STOP_FAILED); + ::MsiRecordSetStringW(hRecordProg, 2, m_sValue ); + ::MsiRecordSetInteger(hRecordProg, 3, dwError ); + ::MsiProcessMessage(pSession->m_hInstall, INSTALLMESSAGE_ERROR, hRecordProg); + return AtlHresultFromWin32(dwError); + } +} + +} // namespace MSICA diff --git a/MSICALib/OpTS.cpp b/MSICALib/OpTS.cpp index 089c3d4..14900d2 100644 --- a/MSICALib/OpTS.cpp +++ b/MSICALib/OpTS.cpp @@ -447,25 +447,25 @@ UINT COpTaskCreate::SetFromRecord(MSIHANDLE hInstall, MSIHANDLE hRecord) ATL::CAtlStringW sFolder; uiResult = ::MsiRecordFormatStringW(hInstall, hRecord, 3, m_sApplicationName); - if (uiResult != ERROR_SUCCESS) return uiResult; + if (uiResult != NO_ERROR) return uiResult; uiResult = ::MsiRecordFormatStringW(hInstall, hRecord, 4, m_sParameters); - if (uiResult != ERROR_SUCCESS) return uiResult; + if (uiResult != NO_ERROR) return uiResult; uiResult = ::MsiRecordGetStringW(hRecord, 5, sFolder); - if (uiResult != ERROR_SUCCESS) return uiResult; + if (uiResult != NO_ERROR) return uiResult; uiResult = ::MsiGetTargetPathW(hInstall, sFolder, m_sWorkingDirectory); - if (uiResult != ERROR_SUCCESS) return uiResult; + if (uiResult != NO_ERROR) return uiResult; if (!m_sWorkingDirectory.IsEmpty() && m_sWorkingDirectory.GetAt(m_sWorkingDirectory.GetLength() - 1) == L'\\') { // Trim trailing backslash. m_sWorkingDirectory.Truncate(m_sWorkingDirectory.GetLength() - 1); } uiResult = ::MsiRecordFormatStringW(hInstall, hRecord, 10, m_sAuthor); - if (uiResult != ERROR_SUCCESS) return uiResult; + if (uiResult != NO_ERROR) return uiResult; uiResult = ::MsiRecordFormatStringW(hInstall, hRecord, 11, m_sComment); - if (uiResult != ERROR_SUCCESS) return uiResult; + if (uiResult != NO_ERROR) return uiResult; m_dwFlags = ::MsiRecordGetInteger(hRecord, 6); if (m_dwFlags == MSI_NULL_INTEGER) return ERROR_INVALID_FIELD; @@ -474,10 +474,10 @@ UINT COpTaskCreate::SetFromRecord(MSIHANDLE hInstall, MSIHANDLE hRecord) if (m_dwPriority == MSI_NULL_INTEGER) return ERROR_INVALID_FIELD; uiResult = ::MsiRecordFormatStringW(hInstall, hRecord, 8, m_sAccountName); - if (uiResult != ERROR_SUCCESS) return uiResult; + if (uiResult != NO_ERROR) return uiResult; uiResult = ::MsiRecordFormatStringW(hInstall, hRecord, 9, m_sPassword); - if (uiResult != ERROR_SUCCESS) return uiResult; + if (uiResult != NO_ERROR) return uiResult; iValue = ::MsiRecordGetInteger(hRecord, 12); m_wIdleMinutes = iValue != MSI_NULL_INTEGER ? (WORD)iValue : 0; @@ -488,7 +488,7 @@ UINT COpTaskCreate::SetFromRecord(MSIHANDLE hInstall, MSIHANDLE hRecord) m_dwMaxRuntimeMS = ::MsiRecordGetInteger(hRecord, 14); if (m_dwMaxRuntimeMS == MSI_NULL_INTEGER) return ERROR_INVALID_FIELD; - return ERROR_SUCCESS; + return NO_ERROR; } @@ -505,8 +505,8 @@ UINT COpTaskCreate::SetTriggersFromView(MSIHANDLE hView) // Fetch one record from the view. uiResult = ::MsiViewFetch(hView, &hRecord); - if (uiResult == ERROR_NO_MORE_ITEMS) return ERROR_SUCCESS; - else if (uiResult != ERROR_SUCCESS) return uiResult; + if (uiResult == ERROR_NO_MORE_ITEMS) return NO_ERROR; + else if (uiResult != NO_ERROR) return uiResult; ZeroMemory(&ttData, sizeof(TASK_TRIGGER)); ttData.cbTriggerSize = sizeof(TASK_TRIGGER); @@ -618,7 +618,7 @@ UINT COpTaskCreate::SetTriggersFromView(MSIHANDLE hView) m_lTriggers.AddTail(ttData); } - return ERROR_SUCCESS; + return NO_ERROR; } diff --git a/MSICATS/MSICATS.cpp b/MSICATS/MSICATS.cpp index 707a878..802e212 100644 --- a/MSICATS/MSICATS.cpp +++ b/MSICATS/MSICATS.cpp @@ -38,7 +38,7 @@ UINT MSICATS_API EvaluateSequence(MSIHANDLE hInstall) // Check and add the rollback enabled state. uiResult = ::MsiGetProperty(hInstall, _T("RollbackDisabled"), sValue); - bRollbackEnabled = uiResult == ERROR_SUCCESS ? + bRollbackEnabled = uiResult == NO_ERROR ? _ttoi(sValue) || !sValue.IsEmpty() && _totlower(sValue.GetAt(0)) == _T('y') ? FALSE : TRUE : TRUE; olExecute.AddTail(new MSICA::COpRollbackEnable(bRollbackEnabled)); @@ -53,10 +53,10 @@ UINT MSICATS_API EvaluateSequence(MSIHANDLE hInstall) // Prepare a query to get a list/view of tasks. uiResult = ::MsiDatabaseOpenView(hDatabase, _T("SELECT Task,DisplayName,Application,Parameters,Directory_,Flags,Priority,User,Password,Author,Description,IdleMin,IdleDeadline,MaxRuntime,Condition,Component_ FROM ScheduledTask"), &hViewST); - if (uiResult == ERROR_SUCCESS) { + if (uiResult == NO_ERROR) { // Execute query! uiResult = ::MsiViewExecute(hViewST, NULL); - if (uiResult == ERROR_SUCCESS) { + if (uiResult == NO_ERROR) { //ATL::CAtlString sComponent; ATL::CAtlStringW sDisplayName; @@ -67,14 +67,14 @@ UINT MSICATS_API EvaluateSequence(MSIHANDLE hInstall) // Fetch one record from the view. uiResult = ::MsiViewFetch(hViewST, &hRecord); if (uiResult == ERROR_NO_MORE_ITEMS) { - uiResult = ERROR_SUCCESS; + uiResult = NO_ERROR; break; - } else if (uiResult != ERROR_SUCCESS) + } else if (uiResult != NO_ERROR) break; // Read and evaluate task's condition. uiResult = ::MsiRecordGetString(hRecord, 15, sValue); - if (uiResult != ERROR_SUCCESS) break; + if (uiResult != NO_ERROR) break; condition = ::MsiEvaluateCondition(hInstall, sValue); if (condition == MSICONDITION_FALSE) continue; @@ -85,11 +85,11 @@ UINT MSICATS_API EvaluateSequence(MSIHANDLE hInstall) // Read task's Component ID. uiResult = ::MsiRecordGetString(hRecord, 16, sValue); - if (uiResult != ERROR_SUCCESS) break; + if (uiResult != NO_ERROR) break; // Get the component state. uiResult = ::MsiGetComponentState(hInstall, sValue, &iInstalled, &iAction); - if (uiResult != ERROR_SUCCESS) break; + if (uiResult != NO_ERROR) break; // Get task's DisplayName. uiResult = ::MsiRecordFormatStringW(hInstall, hRecord, 2, sDisplayName); @@ -101,19 +101,19 @@ UINT MSICATS_API EvaluateSequence(MSIHANDLE hInstall) // Populate the operation with task's data. uiResult = opCreateTask->SetFromRecord(hInstall, hRecord); - if (uiResult != ERROR_SUCCESS) break; + if (uiResult != NO_ERROR) break; // Perform another query to get task's triggers. uiResult = ::MsiDatabaseOpenView(hDatabase, _T("SELECT Trigger,BeginDate,EndDate,StartTime,StartTimeRand,MinutesDuration,MinutesInterval,Flags,Type,DaysInterval,WeeksInterval,DaysOfTheWeek,DaysOfMonth,WeekOfMonth,MonthsOfYear FROM TaskTrigger WHERE Task_=?"), &hViewTT); - if (uiResult != ERROR_SUCCESS) break; + if (uiResult != NO_ERROR) break; // Execute query! uiResult = ::MsiViewExecute(hViewTT, hRecord); - if (uiResult == ERROR_SUCCESS) { + if (uiResult == NO_ERROR) { // Populate trigger list. uiResult = opCreateTask->SetTriggersFromView(hViewTT); ::MsiViewClose(hViewTT); - if (uiResult != ERROR_SUCCESS) break; + if (uiResult != NO_ERROR) break; } else break; @@ -130,7 +130,7 @@ UINT MSICATS_API EvaluateSequence(MSIHANDLE hInstall) } ::MsiViewClose(hViewST); - if (uiResult == ERROR_SUCCESS) { + if (uiResult == NO_ERROR) { // Save the sequences. uiResult = MSICA::SaveSequence(hInstall, _T("InstallScheduledTasks"), _T("CommitScheduledTasks"), _T("RollbackScheduledTasks"), olExecute); } else if (uiResult != ERROR_INSTALL_USEREXIT) {