ERROR_SUCCESS => NO_ERROR

Dodal sem podporo za upravljanje sistemskih servisov.
This commit is contained in:
Simon Rozman 2014-03-20 12:17:08 +00:00
parent 4a5a306c1e
commit b4750608b3
13 changed files with 413 additions and 179 deletions

1
.gitattributes vendored
View File

@ -23,6 +23,7 @@ MSICALib/MSICALib.vcxproj.filters -text svneol=unset#text/xml
MSICALib/OpCert.cpp -text MSICALib/OpCert.cpp -text
MSICALib/OpFile.cpp -text MSICALib/OpFile.cpp -text
MSICALib/OpReg.cpp -text MSICALib/OpReg.cpp -text
MSICALib/OpSvc.cpp -text
MSICALib/OpTS.cpp -text MSICALib/OpTS.cpp -text
MSICALib/stdafx.cpp -text MSICALib/stdafx.cpp -text
MSICALib/stdafx.h -text MSICALib/stdafx.h -text

View File

@ -40,7 +40,7 @@ UINT MSICACERT_API EvaluateSequence(MSIHANDLE hInstall)
// Check and add the rollback enabled state. // Check and add the rollback enabled state.
uiResult = ::MsiGetProperty(hInstall, _T("RollbackDisabled"), sValue); 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 : _ttoi(sValue) || !sValue.IsEmpty() && _totlower(sValue.GetAt(0)) == _T('y') ? FALSE : TRUE :
TRUE; TRUE;
olExecute.AddTail(new MSICA::COpRollbackEnable(bRollbackEnabled)); 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. // Prepare a query to get a list/view of certificates.
uiResult = ::MsiDatabaseOpenView(hDatabase, _T("SELECT Binary_,Store,Flags,Encoding,Condition,Component_ FROM Certificate"), &hViewCert); uiResult = ::MsiDatabaseOpenView(hDatabase, _T("SELECT Binary_,Store,Flags,Encoding,Condition,Component_ FROM Certificate"), &hViewCert);
if (uiResult == ERROR_SUCCESS) { if (uiResult == NO_ERROR) {
// Execute query! // Execute query!
uiResult = ::MsiViewExecute(hViewCert, NULL); uiResult = ::MsiViewExecute(hViewCert, NULL);
if (uiResult == ERROR_SUCCESS) { if (uiResult == NO_ERROR) {
//ATL::CAtlString sComponent; //ATL::CAtlString sComponent;
ATL::CAtlStringW sStore; ATL::CAtlStringW sStore;
int iFlags, iEncoding; int iFlags, iEncoding;
@ -72,14 +72,14 @@ UINT MSICACERT_API EvaluateSequence(MSIHANDLE hInstall)
// Fetch one record from the view. // Fetch one record from the view.
uiResult = ::MsiViewFetch(hViewCert, &hRecord); uiResult = ::MsiViewFetch(hViewCert, &hRecord);
if (uiResult == ERROR_NO_MORE_ITEMS) { if (uiResult == ERROR_NO_MORE_ITEMS) {
uiResult = ERROR_SUCCESS; uiResult = NO_ERROR;
break; break;
} else if (uiResult != ERROR_SUCCESS) } else if (uiResult != NO_ERROR)
break; break;
// Read and evaluate certificate's condition. // Read and evaluate certificate's condition.
uiResult = ::MsiRecordGetString(hRecord, 5, sValue); uiResult = ::MsiRecordGetString(hRecord, 5, sValue);
if (uiResult != ERROR_SUCCESS) break; if (uiResult != NO_ERROR) break;
condition = ::MsiEvaluateCondition(hInstall, sValue); condition = ::MsiEvaluateCondition(hInstall, sValue);
if (condition == MSICONDITION_FALSE) if (condition == MSICONDITION_FALSE)
continue; continue;
@ -90,25 +90,25 @@ UINT MSICACERT_API EvaluateSequence(MSIHANDLE hInstall)
// Perform another query to get certificate's binary data. // Perform another query to get certificate's binary data.
uiResult = ::MsiDatabaseOpenView(hDatabase, _T("SELECT Data FROM Binary WHERE Name=?"), &hViewBinary); uiResult = ::MsiDatabaseOpenView(hDatabase, _T("SELECT Data FROM Binary WHERE Name=?"), &hViewBinary);
if (uiResult != ERROR_SUCCESS) break; if (uiResult != NO_ERROR) break;
// Execute query! // Execute query!
uiResult = ::MsiViewExecute(hViewBinary, hRecord); uiResult = ::MsiViewExecute(hViewBinary, hRecord);
if (uiResult == ERROR_SUCCESS) { if (uiResult == NO_ERROR) {
PMSIHANDLE hRecord; PMSIHANDLE hRecord;
// Fetch one record from the view. // Fetch one record from the view.
uiResult = ::MsiViewFetch(hViewBinary, &hRecord); uiResult = ::MsiViewFetch(hViewBinary, &hRecord);
if (uiResult == ERROR_SUCCESS) if (uiResult == NO_ERROR)
uiResult = ::MsiRecordGetStream(hRecord, 1, binCert); uiResult = ::MsiRecordGetStream(hRecord, 1, binCert);
::MsiViewClose(hViewBinary); ::MsiViewClose(hViewBinary);
if (uiResult != ERROR_SUCCESS) break; if (uiResult != NO_ERROR) break;
} else } else
break; break;
// Read certificate's store. // Read certificate's store.
uiResult = ::MsiRecordGetString(hRecord, 2, sStore); uiResult = ::MsiRecordGetString(hRecord, 2, sStore);
if (uiResult != ERROR_SUCCESS) break; if (uiResult != NO_ERROR) break;
// Read certificate's flags. // Read certificate's flags.
iFlags = ::MsiRecordGetInteger(hRecord, 3); iFlags = ::MsiRecordGetInteger(hRecord, 3);
@ -126,11 +126,11 @@ UINT MSICACERT_API EvaluateSequence(MSIHANDLE hInstall)
// Read certificate's Component ID. // Read certificate's Component ID.
uiResult = ::MsiRecordGetString(hRecord, 6, sValue); uiResult = ::MsiRecordGetString(hRecord, 6, sValue);
if (uiResult != ERROR_SUCCESS) break; if (uiResult != NO_ERROR) break;
// Get the component state. // Get the component state.
uiResult = ::MsiGetComponentState(hInstall, sValue, &iInstalled, &iAction); uiResult = ::MsiGetComponentState(hInstall, sValue, &iInstalled, &iAction);
if (uiResult != ERROR_SUCCESS) break; if (uiResult != NO_ERROR) break;
if (iAction >= INSTALLSTATE_LOCAL) { if (iAction >= INSTALLSTATE_LOCAL) {
// Component is or should be installed. Install the certificate. // Component is or should be installed. Install the certificate.
@ -147,7 +147,7 @@ UINT MSICACERT_API EvaluateSequence(MSIHANDLE hInstall)
} }
::MsiViewClose(hViewCert); ::MsiViewClose(hViewCert);
if (uiResult == ERROR_SUCCESS) { if (uiResult == NO_ERROR) {
// Save the sequences. // Save the sequences.
uiResult = MSICA::SaveSequence(hInstall, _T("InstallCertificates"), _T("CommitCertificates"), _T("RollbackCertificates"), olExecute); uiResult = MSICA::SaveSequence(hInstall, _T("InstallCertificates"), _T("CommitCertificates"), _T("RollbackCertificates"), olExecute);
} else if (uiResult != ERROR_INSTALL_USEREXIT) { } else if (uiResult != ERROR_INSTALL_USEREXIT) {

View File

@ -37,6 +37,9 @@ i2 L0
2559 Error [4] copying "[2]" scheduled task to "[3]". Please, contact your support personnel. 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. 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. 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.
<<NOKEEP <<NOKEEP
"De.$(PLAT).$(CFG).Error-2.idt" : "En.$(PLAT).$(CFG).Error-2.idtx" "..\L10N\de_DE.po" "De.$(PLAT).$(CFG).Error-2.idt" : "En.$(PLAT).$(CFG).Error-2.idtx" "..\L10N\de_DE.po"

View File

@ -208,16 +208,16 @@ UINT SaveSequence(MSIHANDLE hInstall, LPCTSTR szActionExecute, LPCTSTR szActionC
if (SUCCEEDED(hr)) { if (SUCCEEDED(hr)) {
// Store sequence script file names to properties for deferred custiom actions. // Store sequence script file names to properties for deferred custiom actions.
uiResult = ::MsiSetProperty(hInstall, szActionExecute, sSequenceFilename); uiResult = ::MsiSetProperty(hInstall, szActionExecute, sSequenceFilename);
if (uiResult == ERROR_SUCCESS) { if (uiResult == NO_ERROR) {
LPCTSTR pszExtension = ::PathFindExtension(sSequenceFilename); LPCTSTR pszExtension = ::PathFindExtension(sSequenceFilename);
ATL::CAtlString sSequenceFilename2; ATL::CAtlString sSequenceFilename2;
sSequenceFilename2.Format(_T("%.*ls-rb%ls"), pszExtension - (LPCTSTR)sSequenceFilename, (LPCTSTR)sSequenceFilename, pszExtension); sSequenceFilename2.Format(_T("%.*ls-rb%ls"), pszExtension - (LPCTSTR)sSequenceFilename, (LPCTSTR)sSequenceFilename, pszExtension);
uiResult = ::MsiSetProperty(hInstall, szActionRollback, sSequenceFilename2); uiResult = ::MsiSetProperty(hInstall, szActionRollback, sSequenceFilename2);
if (uiResult == ERROR_SUCCESS) { if (uiResult == NO_ERROR) {
sSequenceFilename2.Format(_T("%.*ls-cm%ls"), pszExtension - (LPCTSTR)sSequenceFilename, (LPCTSTR)sSequenceFilename, pszExtension); sSequenceFilename2.Format(_T("%.*ls-cm%ls"), pszExtension - (LPCTSTR)sSequenceFilename, (LPCTSTR)sSequenceFilename, pszExtension);
uiResult = ::MsiSetProperty(hInstall, szActionCommit, sSequenceFilename2); uiResult = ::MsiSetProperty(hInstall, szActionCommit, sSequenceFilename2);
if (uiResult != ERROR_SUCCESS) { if (uiResult != NO_ERROR) {
::MsiRecordSetInteger(hRecordProg, 1, ERROR_INSTALL_PROPERTY_SET); ::MsiRecordSetInteger(hRecordProg, 1, ERROR_INSTALL_PROPERTY_SET);
::MsiRecordSetString (hRecordProg, 2, szActionCommit ); ::MsiRecordSetString (hRecordProg, 2, szActionCommit );
::MsiRecordSetInteger(hRecordProg, 3, uiResult ); ::MsiRecordSetInteger(hRecordProg, 3, uiResult );
@ -235,7 +235,7 @@ UINT SaveSequence(MSIHANDLE hInstall, LPCTSTR szActionExecute, LPCTSTR szActionC
::MsiRecordSetInteger(hRecordProg, 3, uiResult ); ::MsiRecordSetInteger(hRecordProg, 3, uiResult );
::MsiProcessMessage(hInstall, INSTALLMESSAGE_ERROR, hRecordProg); ::MsiProcessMessage(hInstall, INSTALLMESSAGE_ERROR, hRecordProg);
} }
if (uiResult != ERROR_SUCCESS) ::DeleteFile(sSequenceFilename); if (uiResult != NO_ERROR) ::DeleteFile(sSequenceFilename);
} else { } else {
uiResult = ERROR_INSTALL_SCRIPT_WRITE; uiResult = ERROR_INSTALL_SCRIPT_WRITE;
::MsiRecordSetInteger(hRecordProg, 1, uiResult ); ::MsiRecordSetInteger(hRecordProg, 1, uiResult );
@ -256,7 +256,7 @@ UINT ExecuteSequence(MSIHANDLE hInstall)
ATL::CAtlString sSequenceFilename; ATL::CAtlString sSequenceFilename;
uiResult = ::MsiGetProperty(hInstall, _T("CustomActionData"), sSequenceFilename); uiResult = ::MsiGetProperty(hInstall, _T("CustomActionData"), sSequenceFilename);
if (uiResult == ERROR_SUCCESS) { if (uiResult == NO_ERROR) {
MSICA::COpList lstOperations; MSICA::COpList lstOperations;
BOOL bIsCleanup = ::MsiGetMode(hInstall, MSIRUNMODE_COMMIT) || ::MsiGetMode(hInstall, MSIRUNMODE_ROLLBACK); BOOL bIsCleanup = ::MsiGetMode(hInstall, MSIRUNMODE_COMMIT) || ::MsiGetMode(hInstall, MSIRUNMODE_ROLLBACK);
@ -304,7 +304,7 @@ UINT ExecuteSequence(MSIHANDLE hInstall)
// Save rollback file next. // Save rollback file next.
hr = session.m_olRollback.SaveToFile(sSequenceFilenameRB); hr = session.m_olRollback.SaveToFile(sSequenceFilenameRB);
if (SUCCEEDED(hr)) { if (SUCCEEDED(hr)) {
uiResult = ERROR_SUCCESS; uiResult = NO_ERROR;
} else { } else {
// Saving rollback file failed. // Saving rollback file failed.
PMSIHANDLE hRecordProg = ::MsiCreateRecord(3); PMSIHANDLE hRecordProg = ::MsiCreateRecord(3);
@ -324,7 +324,7 @@ UINT ExecuteSequence(MSIHANDLE hInstall)
::MsiProcessMessage(hInstall, INSTALLMESSAGE_ERROR, hRecordProg); ::MsiProcessMessage(hInstall, INSTALLMESSAGE_ERROR, hRecordProg);
} }
if (uiResult != ERROR_SUCCESS) { if (uiResult != NO_ERROR) {
// The commit and/or rollback scripts were not written to file successfully. Perform the cleanup immediately. // The commit and/or rollback scripts were not written to file successfully. Perform the cleanup immediately.
session.m_bContinueOnError = TRUE; session.m_bContinueOnError = TRUE;
session.m_bRollbackEnabled = FALSE; session.m_bRollbackEnabled = FALSE;
@ -333,7 +333,7 @@ UINT ExecuteSequence(MSIHANDLE hInstall)
} }
} else { } else {
// No cleanup after cleanup support. // No cleanup after cleanup support.
uiResult = ERROR_SUCCESS; uiResult = NO_ERROR;
} }
if (FAILED(hr)) { if (FAILED(hr)) {
@ -346,7 +346,7 @@ UINT ExecuteSequence(MSIHANDLE hInstall)
// Sequence file not found and this is rollback/commit action. Either of the following scenarios are possible: // Sequence file not found and this is rollback/commit action. Either of the following scenarios are possible:
// - The delayed action failed to save the rollback/commit file. The delayed action performed cleanup itself. No further action is required. // - The delayed action failed to save the rollback/commit file. The delayed action performed cleanup itself. No further action is required.
// - Somebody removed the rollback/commit file between delayed action and rollback/commit action. No further action is possible. // - Somebody removed the rollback/commit file between delayed action and rollback/commit action. No further action is possible.
uiResult = ERROR_SUCCESS; uiResult = NO_ERROR;
} else { } else {
// Sequence loading failed. Probably, LOCAL SYSTEM doesn't have read access to user's temp directory. // Sequence loading failed. Probably, LOCAL SYSTEM doesn't have read access to user's temp directory.
PMSIHANDLE hRecordProg = ::MsiCreateRecord(3); PMSIHANDLE hRecordProg = ::MsiCreateRecord(3);

View File

@ -12,7 +12,7 @@
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Error codes (next unused 2571L) // Error codes (next unused 2574L)
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
#define ERROR_INSTALL_DATABASE_OPEN 2550L #define ERROR_INSTALL_DATABASE_OPEN 2550L
@ -36,6 +36,9 @@
#define ERROR_INSTALL_TASK_COPY_FAILED 2559L #define ERROR_INSTALL_TASK_COPY_FAILED 2559L
#define ERROR_INSTALL_CERT_INSTALL_FAILED 2569L #define ERROR_INSTALL_CERT_INSTALL_FAILED 2569L
#define ERROR_INSTALL_CERT_REMOVE_FAILED 2570L #define ERROR_INSTALL_CERT_REMOVE_FAILED 2570L
#define ERROR_INSTALL_SVC_SET_START_FAILED 2571L
#define ERROR_INSTALL_SVC_START_FAILED 2572L
#define ERROR_INSTALL_SVC_STOP_FAILED 2573L
namespace MSICA { namespace MSICA {
@ -455,6 +458,48 @@ public:
}; };
////////////////////////////////////////////////////////////////////////////
// COpSvcSetStart
////////////////////////////////////////////////////////////////////////////
class COpSvcSetStart : public COpTypeSingleString
{
public:
COpSvcSetStart(LPCWSTR pszService = L"", DWORD dwStartType = SERVICE_DEMAND_START, int iTicks = 0);
virtual HRESULT Execute(CSession *pSession);
friend inline HRESULT operator <<(ATL::CAtlFile &f, const COpSvcSetStart &op);
friend inline HRESULT operator >>(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 // COpList
//////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////
@ -490,6 +535,9 @@ protected:
OP_TASK_COPY, OP_TASK_COPY,
OP_CERT_INSTALL, OP_CERT_INSTALL,
OP_CERT_REMOVE, OP_CERT_REMOVE,
OP_SVC_SET_START,
OP_SVC_START,
OP_SVC_STOP,
OP_SUBLIST OP_SUBLIST
}; };
@ -553,12 +601,12 @@ inline UINT MsiGetPropertyA(MSIHANDLE hInstall, LPCSTR szName, ATL::CAtlStringA
LPSTR szBuffer = sValue.GetBuffer(dwSize++); LPSTR szBuffer = sValue.GetBuffer(dwSize++);
if (!szBuffer) return ERROR_OUTOFMEMORY; if (!szBuffer) return ERROR_OUTOFMEMORY;
uiResult = ::MsiGetPropertyA(hInstall, szName, szBuffer, &dwSize); uiResult = ::MsiGetPropertyA(hInstall, szName, szBuffer, &dwSize);
sValue.ReleaseBuffer(uiResult == ERROR_SUCCESS ? dwSize : 0); sValue.ReleaseBuffer(uiResult == NO_ERROR ? dwSize : 0);
return uiResult; return uiResult;
} else if (uiResult == ERROR_SUCCESS) { } else if (uiResult == NO_ERROR) {
// The string in database is empty. // The string in database is empty.
sValue.Empty(); sValue.Empty();
return ERROR_SUCCESS; return NO_ERROR;
} else { } else {
// Return error code. // Return error code.
return uiResult; return uiResult;
@ -578,12 +626,12 @@ inline UINT MsiGetPropertyW(MSIHANDLE hInstall, LPCWSTR szName, ATL::CAtlStringW
LPWSTR szBuffer = sValue.GetBuffer(dwSize++); LPWSTR szBuffer = sValue.GetBuffer(dwSize++);
if (!szBuffer) return ERROR_OUTOFMEMORY; if (!szBuffer) return ERROR_OUTOFMEMORY;
uiResult = ::MsiGetPropertyW(hInstall, szName, szBuffer, &dwSize); uiResult = ::MsiGetPropertyW(hInstall, szName, szBuffer, &dwSize);
sValue.ReleaseBuffer(uiResult == ERROR_SUCCESS ? dwSize : 0); sValue.ReleaseBuffer(uiResult == NO_ERROR ? dwSize : 0);
return uiResult; return uiResult;
} else if (uiResult == ERROR_SUCCESS) { } else if (uiResult == NO_ERROR) {
// The string in database is empty. // The string in database is empty.
sValue.Empty(); sValue.Empty();
return ERROR_SUCCESS; return NO_ERROR;
} else { } else {
// Return error code. // Return error code.
return uiResult; return uiResult;
@ -603,12 +651,12 @@ inline UINT MsiRecordGetStringA(MSIHANDLE hRecord, unsigned int iField, ATL::CAt
LPSTR szBuffer = sValue.GetBuffer(dwSize++); LPSTR szBuffer = sValue.GetBuffer(dwSize++);
if (!szBuffer) return ERROR_OUTOFMEMORY; if (!szBuffer) return ERROR_OUTOFMEMORY;
uiResult = ::MsiRecordGetStringA(hRecord, iField, szBuffer, &dwSize); uiResult = ::MsiRecordGetStringA(hRecord, iField, szBuffer, &dwSize);
sValue.ReleaseBuffer(uiResult == ERROR_SUCCESS ? dwSize : 0); sValue.ReleaseBuffer(uiResult == NO_ERROR ? dwSize : 0);
return uiResult; return uiResult;
} else if (uiResult == ERROR_SUCCESS) { } else if (uiResult == NO_ERROR) {
// The string in database is empty. // The string in database is empty.
sValue.Empty(); sValue.Empty();
return ERROR_SUCCESS; return NO_ERROR;
} else { } else {
// Return error code. // Return error code.
return uiResult; return uiResult;
@ -628,12 +676,12 @@ inline UINT MsiRecordGetStringW(MSIHANDLE hRecord, unsigned int iField, ATL::CAt
LPWSTR szBuffer = sValue.GetBuffer(dwSize++); LPWSTR szBuffer = sValue.GetBuffer(dwSize++);
if (!szBuffer) return ERROR_OUTOFMEMORY; if (!szBuffer) return ERROR_OUTOFMEMORY;
uiResult = ::MsiRecordGetStringW(hRecord, iField, szBuffer, &dwSize); uiResult = ::MsiRecordGetStringW(hRecord, iField, szBuffer, &dwSize);
sValue.ReleaseBuffer(uiResult == ERROR_SUCCESS ? dwSize : 0); sValue.ReleaseBuffer(uiResult == NO_ERROR ? dwSize : 0);
return uiResult; return uiResult;
} else if (uiResult == ERROR_SUCCESS) { } else if (uiResult == NO_ERROR) {
// The string in database is empty. // The string in database is empty.
sValue.Empty(); sValue.Empty();
return ERROR_SUCCESS; return NO_ERROR;
} else { } else {
// Return error code. // Return error code.
return uiResult; return uiResult;
@ -648,7 +696,7 @@ inline UINT MsiRecordGetStream(MSIHANDLE hRecord, unsigned int iField, ATL::CAtl
// Query the actual data length first. // Query the actual data length first.
uiResult = ::MsiRecordReadStream(hRecord, iField, NULL, &dwSize); uiResult = ::MsiRecordReadStream(hRecord, iField, NULL, &dwSize);
if (uiResult == ERROR_SUCCESS) { if (uiResult == NO_ERROR) {
if (!binData.SetCount(dwSize)) return ERROR_OUTOFMEMORY; if (!binData.SetCount(dwSize)) return ERROR_OUTOFMEMORY;
return ::MsiRecordReadStream(hRecord, iField, (char*)binData.GetData(), &dwSize); return ::MsiRecordReadStream(hRecord, iField, (char*)binData.GetData(), &dwSize);
} else { } else {
@ -670,12 +718,12 @@ inline UINT MsiFormatRecordA(MSIHANDLE hInstall, MSIHANDLE hRecord, ATL::CAtlStr
LPSTR szBuffer = sValue.GetBuffer(dwSize++); LPSTR szBuffer = sValue.GetBuffer(dwSize++);
if (!szBuffer) return ERROR_OUTOFMEMORY; if (!szBuffer) return ERROR_OUTOFMEMORY;
uiResult = ::MsiFormatRecordA(hInstall, hRecord, szBuffer, &dwSize); uiResult = ::MsiFormatRecordA(hInstall, hRecord, szBuffer, &dwSize);
sValue.ReleaseBuffer(uiResult == ERROR_SUCCESS ? dwSize : 0); sValue.ReleaseBuffer(uiResult == NO_ERROR ? dwSize : 0);
return uiResult; return uiResult;
} else if (uiResult == ERROR_SUCCESS) { } else if (uiResult == NO_ERROR) {
// The result is empty. // The result is empty.
sValue.Empty(); sValue.Empty();
return ERROR_SUCCESS; return NO_ERROR;
} else { } else {
// Return error code. // Return error code.
return uiResult; return uiResult;
@ -695,12 +743,12 @@ inline UINT MsiFormatRecordW(MSIHANDLE hInstall, MSIHANDLE hRecord, ATL::CAtlStr
LPWSTR szBuffer = sValue.GetBuffer(dwSize++); LPWSTR szBuffer = sValue.GetBuffer(dwSize++);
if (!szBuffer) return ERROR_OUTOFMEMORY; if (!szBuffer) return ERROR_OUTOFMEMORY;
uiResult = ::MsiFormatRecordW(hInstall, hRecord, szBuffer, &dwSize); uiResult = ::MsiFormatRecordW(hInstall, hRecord, szBuffer, &dwSize);
sValue.ReleaseBuffer(uiResult == ERROR_SUCCESS ? dwSize : 0); sValue.ReleaseBuffer(uiResult == NO_ERROR ? dwSize : 0);
return uiResult; return uiResult;
} else if (uiResult == ERROR_SUCCESS) { } else if (uiResult == NO_ERROR) {
// The result is empty. // The result is empty.
sValue.Empty(); sValue.Empty();
return ERROR_SUCCESS; return NO_ERROR;
} else { } else {
// Return error code. // Return error code.
return uiResult; return uiResult;
@ -715,10 +763,10 @@ inline UINT MsiRecordFormatStringA(MSIHANDLE hInstall, MSIHANDLE hRecord, unsign
// Read string to format. // Read string to format.
uiResult = ::MsiRecordGetStringA(hRecord, iField, sValue); 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 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. // Create a record.
hRecordEx = ::MsiCreateRecord(1); hRecordEx = ::MsiCreateRecord(1);
@ -726,7 +774,7 @@ inline UINT MsiRecordFormatStringA(MSIHANDLE hInstall, MSIHANDLE hRecord, unsign
// Populate record with data. // Populate record with data.
uiResult = ::MsiRecordSetStringA(hRecordEx, 0, sValue); uiResult = ::MsiRecordSetStringA(hRecordEx, 0, sValue);
if (uiResult != ERROR_SUCCESS) return uiResult; if (uiResult != NO_ERROR) return uiResult;
// Do the formatting. // Do the formatting.
return ::MsiFormatRecordA(hInstall, hRecordEx, sValue); return ::MsiFormatRecordA(hInstall, hRecordEx, sValue);
@ -740,10 +788,10 @@ inline UINT MsiRecordFormatStringW(MSIHANDLE hInstall, MSIHANDLE hRecord, unsign
// Read string to format. // Read string to format.
uiResult = ::MsiRecordGetStringW(hRecord, iField, sValue); 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 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. // Create a record.
hRecordEx = ::MsiCreateRecord(1); hRecordEx = ::MsiCreateRecord(1);
@ -751,7 +799,7 @@ inline UINT MsiRecordFormatStringW(MSIHANDLE hInstall, MSIHANDLE hRecord, unsign
// Populate record with data. // Populate record with data.
uiResult = ::MsiRecordSetStringW(hRecordEx, 0, sValue); uiResult = ::MsiRecordSetStringW(hRecordEx, 0, sValue);
if (uiResult != ERROR_SUCCESS) return uiResult; if (uiResult != NO_ERROR) return uiResult;
// Do the formatting. // Do the formatting.
return ::MsiFormatRecordW(hInstall, hRecordEx, sValue); return ::MsiFormatRecordW(hInstall, hRecordEx, sValue);
@ -776,12 +824,12 @@ inline UINT MsiGetTargetPathA(MSIHANDLE hInstall, LPCSTR szFolder, ATL::CAtlStri
LPSTR szBuffer = sValue.GetBuffer(dwSize++); LPSTR szBuffer = sValue.GetBuffer(dwSize++);
if (!szBuffer) return ERROR_OUTOFMEMORY; if (!szBuffer) return ERROR_OUTOFMEMORY;
uiResult = ::MsiGetTargetPathA(hInstall, szFolder, szBuffer, &dwSize); uiResult = ::MsiGetTargetPathA(hInstall, szFolder, szBuffer, &dwSize);
sValue.ReleaseBuffer(uiResult == ERROR_SUCCESS ? dwSize : 0); sValue.ReleaseBuffer(uiResult == NO_ERROR ? dwSize : 0);
return uiResult; return uiResult;
} else if (uiResult == ERROR_SUCCESS) { } else if (uiResult == NO_ERROR) {
// The result is empty. // The result is empty.
sValue.Empty(); sValue.Empty();
return ERROR_SUCCESS; return NO_ERROR;
} else { } else {
// Return error code. // Return error code.
return uiResult; return uiResult;
@ -801,12 +849,12 @@ inline UINT MsiGetTargetPathW(MSIHANDLE hInstall, LPCWSTR szFolder, ATL::CAtlStr
LPWSTR szBuffer = sValue.GetBuffer(dwSize++); LPWSTR szBuffer = sValue.GetBuffer(dwSize++);
if (!szBuffer) return ERROR_OUTOFMEMORY; if (!szBuffer) return ERROR_OUTOFMEMORY;
uiResult = ::MsiGetTargetPathW(hInstall, szFolder, szBuffer, &dwSize); uiResult = ::MsiGetTargetPathW(hInstall, szFolder, szBuffer, &dwSize);
sValue.ReleaseBuffer(uiResult == ERROR_SUCCESS ? dwSize : 0); sValue.ReleaseBuffer(uiResult == NO_ERROR ? dwSize : 0);
return uiResult; return uiResult;
} else if (uiResult == ERROR_SUCCESS) { } else if (uiResult == NO_ERROR) {
// The result is empty. // The result is empty.
sValue.Empty(); sValue.Empty();
return ERROR_SUCCESS; return NO_ERROR;
} else { } else {
// Return error code. // Return error code.
return uiResult; 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) inline HRESULT operator <<(ATL::CAtlFile &f, const COpList &list)
{ {
POSITION pos; POSITION pos;
@ -1411,6 +1481,12 @@ inline HRESULT operator <<(ATL::CAtlFile &f, const COpList &list)
hr = list.Save<COpCertInstall, COpList::OP_CERT_INSTALL>(f, pOp); hr = list.Save<COpCertInstall, COpList::OP_CERT_INSTALL>(f, pOp);
else if (dynamic_cast<const COpCertRemove*>(pOp)) else if (dynamic_cast<const COpCertRemove*>(pOp))
hr = list.Save<COpCertRemove, COpList::OP_CERT_REMOVE>(f, pOp); hr = list.Save<COpCertRemove, COpList::OP_CERT_REMOVE>(f, pOp);
else if (dynamic_cast<const COpSvcSetStart*>(pOp))
hr = list.Save<COpSvcSetStart, COpList::OP_SVC_SET_START>(f, pOp);
else if (dynamic_cast<const COpSvcStart*>(pOp))
hr = list.Save<COpSvcStart, COpList::OP_SVC_START>(f, pOp);
else if (dynamic_cast<const COpSvcStop*>(pOp))
hr = list.Save<COpSvcStop, COpList::OP_SVC_STOP>(f, pOp);
else if (dynamic_cast<const COpList*>(pOp)) else if (dynamic_cast<const COpList*>(pOp))
hr = list.Save<COpList, COpList::OP_SUBLIST>(f, pOp); hr = list.Save<COpList, COpList::OP_SUBLIST>(f, pOp);
else { else {
@ -1443,54 +1519,25 @@ inline HRESULT operator >>(ATL::CAtlFile &f, COpList &list)
if (FAILED(hr)) return hr; if (FAILED(hr)) return hr;
switch ((COpList::OPERATION)iTemp) { switch ((COpList::OPERATION)iTemp) {
case COpList::OP_ROLLBACK_ENABLE: case COpList::OP_ROLLBACK_ENABLE: hr = list.LoadAndAddTail<COpRollbackEnable>(f); break;
hr = list.LoadAndAddTail<COpRollbackEnable>(f); case COpList::OP_FILE_DELETE: hr = list.LoadAndAddTail<COpFileDelete >(f); break;
break; case COpList::OP_FILE_MOVE: hr = list.LoadAndAddTail<COpFileMove >(f); break;
case COpList::OP_FILE_DELETE: case COpList::OP_REG_KEY_CREATE: hr = list.LoadAndAddTail<COpRegKeyCreate >(f); break;
hr = list.LoadAndAddTail<COpFileDelete>(f); case COpList::OP_REG_KEY_COPY: hr = list.LoadAndAddTail<COpRegKeyCopy >(f); break;
break; case COpList::OP_REG_KEY_DELETE: hr = list.LoadAndAddTail<COpRegKeyDelete >(f); break;
case COpList::OP_FILE_MOVE: case COpList::OP_REG_VALUE_CREATE: hr = list.LoadAndAddTail<COpRegValueCreate>(f); break;
hr = list.LoadAndAddTail<COpFileMove>(f); case COpList::OP_REG_VALUE_COPY: hr = list.LoadAndAddTail<COpRegValueCopy >(f); break;
break; case COpList::OP_REG_VALUE_DELETE: hr = list.LoadAndAddTail<COpRegValueDelete>(f); break;
case COpList::OP_REG_KEY_CREATE: case COpList::OP_TASK_CREATE: hr = list.LoadAndAddTail<COpTaskCreate >(f); break;
hr = list.LoadAndAddTail<COpRegKeyCreate>(f); case COpList::OP_TASK_DELETE: hr = list.LoadAndAddTail<COpTaskDelete >(f); break;
break; case COpList::OP_TASK_ENABLE: hr = list.LoadAndAddTail<COpTaskEnable >(f); break;
case COpList::OP_REG_KEY_COPY: case COpList::OP_TASK_COPY: hr = list.LoadAndAddTail<COpTaskCopy >(f); break;
hr = list.LoadAndAddTail<COpRegKeyCopy>(f); case COpList::OP_CERT_INSTALL: hr = list.LoadAndAddTail<COpCertInstall >(f); break;
break; case COpList::OP_CERT_REMOVE: hr = list.LoadAndAddTail<COpCertRemove >(f); break;
case COpList::OP_REG_KEY_DELETE: case COpList::OP_SVC_SET_START: hr = list.LoadAndAddTail<COpSvcSetStart >(f); break;
hr = list.LoadAndAddTail<COpRegKeyDelete>(f); case COpList::OP_SVC_START: hr = list.LoadAndAddTail<COpSvcStart >(f); break;
break; case COpList::OP_SVC_STOP: hr = list.LoadAndAddTail<COpSvcStop >(f); break;
case COpList::OP_REG_VALUE_CREATE: case COpList::OP_SUBLIST: hr = list.LoadAndAddTail<COpList >(f); break;
hr = list.LoadAndAddTail<COpRegValueCreate>(f);
break;
case COpList::OP_REG_VALUE_COPY:
hr = list.LoadAndAddTail<COpRegValueCopy>(f);
break;
case COpList::OP_REG_VALUE_DELETE:
hr = list.LoadAndAddTail<COpRegValueDelete>(f);
break;
case COpList::OP_TASK_CREATE:
hr = list.LoadAndAddTail<COpTaskCreate>(f);
break;
case COpList::OP_TASK_DELETE:
hr = list.LoadAndAddTail<COpTaskDelete>(f);
break;
case COpList::OP_TASK_ENABLE:
hr = list.LoadAndAddTail<COpTaskEnable>(f);
break;
case COpList::OP_TASK_COPY:
hr = list.LoadAndAddTail<COpTaskCopy>(f);
break;
case COpList::OP_CERT_INSTALL:
hr = list.LoadAndAddTail<COpCertInstall>(f);
break;
case COpList::OP_CERT_REMOVE:
hr = list.LoadAndAddTail<COpCertRemove>(f);
break;
case COpList::OP_SUBLIST:
hr = list.LoadAndAddTail<COpList>(f);
break;
default: default:
// Unsupported type of operation. // Unsupported type of operation.
hr = E_UNEXPECTED; hr = E_UNEXPECTED;

View File

@ -22,6 +22,7 @@
<ClCompile Include="OpCert.cpp" /> <ClCompile Include="OpCert.cpp" />
<ClCompile Include="MSICALib.cpp" /> <ClCompile Include="MSICALib.cpp" />
<ClCompile Include="OpFile.cpp" /> <ClCompile Include="OpFile.cpp" />
<ClCompile Include="OpSvc.cpp" />
<ClCompile Include="OpTS.cpp" /> <ClCompile Include="OpTS.cpp" />
<ClCompile Include="OpReg.cpp" /> <ClCompile Include="OpReg.cpp" />
<ClCompile Include="stdafx.cpp"> <ClCompile Include="stdafx.cpp">

View File

@ -33,6 +33,9 @@
<ClCompile Include="OpCert.cpp"> <ClCompile Include="OpCert.cpp">
<Filter>Source Files</Filter> <Filter>Source Files</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="OpSvc.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="MSICALib.h"> <ClInclude Include="MSICALib.h">

View File

@ -64,12 +64,12 @@ HRESULT COpCertInstall::Execute(CSession *pSession)
// Order rollback action to delete the certificate. // 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)); 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 { } else {
dwError = ::GetLastError(); dwError = ::GetLastError();
if (dwError == CRYPT_E_EXISTS) { if (dwError == CRYPT_E_EXISTS) {
// Certificate store already contains given certificate. Nothing to install then. // Certificate store already contains given certificate. Nothing to install then.
dwError = ERROR_SUCCESS; dwError = NO_ERROR;
} }
} }
::CertFreeCertificateContext(pCertContext); ::CertFreeCertificateContext(pCertContext);
@ -79,7 +79,7 @@ HRESULT COpCertInstall::Execute(CSession *pSession)
} else } else
dwError = ::GetLastError(); dwError = ::GetLastError();
if (dwError == ERROR_SUCCESS) if (dwError == NO_ERROR)
return S_OK; return S_OK;
else { else {
PMSIHANDLE hRecordProg = ::MsiCreateRecord(3); PMSIHANDLE hRecordProg = ::MsiCreateRecord(3);
@ -130,14 +130,14 @@ HRESULT COpCertRemove::Execute(CSession *pSession)
// Order rollback action to reinstall the certificate. // 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)); 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 { } else {
dwError = ::GetLastError(); dwError = ::GetLastError();
::CertFreeCertificateContext(pCertContextExisting); ::CertFreeCertificateContext(pCertContextExisting);
} }
} else { } else {
// We haven't found the certificate. Nothing to delete then. // We haven't found the certificate. Nothing to delete then.
dwError = ERROR_SUCCESS; dwError = NO_ERROR;
} }
::CertFreeCertificateContext(pCertContext); ::CertFreeCertificateContext(pCertContext);
} else } else
@ -146,7 +146,7 @@ HRESULT COpCertRemove::Execute(CSession *pSession)
} else } else
dwError = ::GetLastError(); dwError = ::GetLastError();
if (dwError == ERROR_SUCCESS) if (dwError == NO_ERROR)
return S_OK; return S_OK;
else { else {
PMSIHANDLE hRecordProg = ::MsiCreateRecord(3); PMSIHANDLE hRecordProg = ::MsiCreateRecord(3);

View File

@ -24,9 +24,9 @@ HRESULT COpFileDelete::Execute(CSession *pSession)
do { do {
// Rename the file to make a backup. // Rename the file to make a backup.
sBackupName.Format(L"%ls (orig %u)", (LPCWSTR)m_sValue, ++uiCount); 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); } while (dwError == ERROR_ALREADY_EXISTS);
if (dwError == ERROR_SUCCESS) { if (dwError == NO_ERROR) {
// Order rollback action to restore from backup copy. // Order rollback action to restore from backup copy.
pSession->m_olRollback.AddHead(new COpFileMove(sBackupName, m_sValue)); pSession->m_olRollback.AddHead(new COpFileMove(sBackupName, m_sValue));
@ -35,10 +35,10 @@ HRESULT COpFileDelete::Execute(CSession *pSession)
} }
} else { } else {
// Delete the file. // 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; return S_OK;
else { else {
PMSIHANDLE hRecordProg = ::MsiCreateRecord(3); PMSIHANDLE hRecordProg = ::MsiCreateRecord(3);
@ -66,8 +66,8 @@ HRESULT COpFileMove::Execute(CSession *pSession)
DWORD dwError; DWORD dwError;
// Move the file. // Move the file.
dwError = ::MoveFileW(m_sValue1, m_sValue2) ? ERROR_SUCCESS : ::GetLastError(); dwError = ::MoveFileW(m_sValue1, m_sValue2) ? NO_ERROR : ::GetLastError();
if (dwError == ERROR_SUCCESS) { if (dwError == NO_ERROR) {
if (pSession->m_bRollbackEnabled) { if (pSession->m_bRollbackEnabled) {
// Order rollback action to move it back. // Order rollback action to move it back.
pSession->m_olRollback.AddHead(new COpFileMove(m_sValue2, m_sValue1)); pSession->m_olRollback.AddHead(new COpFileMove(m_sValue2, m_sValue1));

View File

@ -70,9 +70,9 @@ HRESULT COpRegKeyCreate::Execute(CSession *pSession)
// Create the key. // Create the key.
lResult = ::RegCreateKeyExW(m_hKeyRoot, sPartialName, NULL, NULL, REG_OPTION_NON_VOLATILE, KEY_ENUMERATE_SUB_KEYS | samAdditional, NULL, &hKey, NULL); 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); ::RegCloseKey(hKey);
} else if (lResult == ERROR_SUCCESS) { } else if (lResult == NO_ERROR) {
// This key already exists. Release its handle and continue. // This key already exists. Release its handle and continue.
::RegCloseKey(hKey); ::RegCloseKey(hKey);
} else } else
@ -82,7 +82,7 @@ HRESULT COpRegKeyCreate::Execute(CSession *pSession)
iStart = iStartNext + 1; iStart = iStartNext + 1;
} }
if (lResult == ERROR_SUCCESS) if (lResult == NO_ERROR)
return S_OK; return S_OK;
else { else {
PMSIHANDLE hRecordProg = ::MsiCreateRecord(4); PMSIHANDLE hRecordProg = ::MsiCreateRecord(4);
@ -133,7 +133,7 @@ HRESULT COpRegKeyCopy::Execute(CSession *pSession)
// Copy the registry key. // Copy the registry key.
lResult = CopyKeyRecursively(m_hKeyRoot, m_sValue1, m_sValue2, samAdditional); lResult = CopyKeyRecursively(m_hKeyRoot, m_sValue1, m_sValue2, samAdditional);
if (lResult == ERROR_SUCCESS) if (lResult == NO_ERROR)
return S_OK; return S_OK;
else { else {
PMSIHANDLE hRecordProg = ::MsiCreateRecord(5); PMSIHANDLE hRecordProg = ::MsiCreateRecord(5);
@ -155,7 +155,7 @@ LONG COpRegKeyCopy::CopyKeyRecursively(HKEY hKeyRoot, LPCWSTR pszKeyNameSrc, LPC
// Open source key. // Open source key.
lResult = ::RegOpenKeyExW(hKeyRoot, pszKeyNameSrc, 0, READ_CONTROL | KEY_READ | samAdditional, &hKeySrc); 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; 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. // Get source key class length and security descriptor size.
lResult = ::RegQueryInfoKeyW(hKeySrc, pszClass, &dwClassLen, NULL, NULL, NULL, NULL, NULL, NULL, NULL, &dwSecurityDescriptorSize, NULL); lResult = ::RegQueryInfoKeyW(hKeySrc, pszClass, &dwClassLen, NULL, NULL, NULL, NULL, NULL, NULL, NULL, &dwSecurityDescriptorSize, NULL);
if (lResult != ERROR_SUCCESS) { if (lResult != NO_ERROR) {
delete [] pszClass; delete [] pszClass;
return lResult; return lResult;
} }
@ -173,7 +173,7 @@ LONG COpRegKeyCopy::CopyKeyRecursively(HKEY hKeyRoot, LPCWSTR pszKeyNameSrc, LPC
// Get source key security descriptor. // Get source key security descriptor.
sa.lpSecurityDescriptor = (PSECURITY_DESCRIPTOR)(new BYTE[dwSecurityDescriptorSize]); sa.lpSecurityDescriptor = (PSECURITY_DESCRIPTOR)(new BYTE[dwSecurityDescriptorSize]);
lResult = ::RegGetKeySecurity(hKeySrc, DACL_SECURITY_INFORMATION, sa.lpSecurityDescriptor, &dwSecurityDescriptorSize); lResult = ::RegGetKeySecurity(hKeySrc, DACL_SECURITY_INFORMATION, sa.lpSecurityDescriptor, &dwSecurityDescriptorSize);
if (lResult != ERROR_SUCCESS) { if (lResult != NO_ERROR) {
delete [] (LPBYTE)(sa.lpSecurityDescriptor); delete [] (LPBYTE)(sa.lpSecurityDescriptor);
delete [] pszClass; delete [] pszClass;
return lResult; 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); lResult = ::RegCreateKeyExW(hKeyRoot, pszKeyNameDst, 0, pszClass, REG_OPTION_NON_VOLATILE, KEY_WRITE | samAdditional, &sa, &hKeyDst, NULL);
delete [] (LPBYTE)(sa.lpSecurityDescriptor); delete [] (LPBYTE)(sa.lpSecurityDescriptor);
delete [] pszClass; delete [] pszClass;
if (lResult != ERROR_SUCCESS) return lResult; if (lResult != NO_ERROR) return lResult;
} }
// Copy subkey recursively. // Copy subkey recursively.
@ -200,7 +200,7 @@ LONG COpRegKeyCopy::CopyKeyRecursively(HKEY hKeySrc, HKEY hKeyDst, REGSAM samAdd
// Query the source key. // Query the source key.
lResult = ::RegQueryInfoKeyW(hKeySrc, NULL, NULL, NULL, NULL, &dwMaxSubKeyLen, &dwMaxClassLen, NULL, &dwMaxValueNameLen, &dwMaxDataSize, NULL, NULL); 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. // Copy values first.
dwMaxValueNameLen++; dwMaxValueNameLen++;
@ -212,19 +212,19 @@ LONG COpRegKeyCopy::CopyKeyRecursively(HKEY hKeySrc, HKEY hKeyDst, REGSAM samAdd
// Read value. // Read value.
lResult = ::RegEnumValueW(hKeySrc, dwIndex, pszName, &dwNameLen, NULL, &dwType, lpData, &dwValueSize); lResult = ::RegEnumValueW(hKeySrc, dwIndex, pszName, &dwNameLen, NULL, &dwType, lpData, &dwValueSize);
if (lResult == ERROR_NO_MORE_ITEMS) { if (lResult == ERROR_NO_MORE_ITEMS) {
lResult = ERROR_SUCCESS; lResult = NO_ERROR;
break; break;
} else if (lResult != ERROR_SUCCESS) } else if (lResult != NO_ERROR)
break; break;
// Save value. // Save value.
lResult = ::RegSetValueExW(hKeyDst, pszName, 0, dwType, lpData, dwValueSize); lResult = ::RegSetValueExW(hKeyDst, pszName, 0, dwType, lpData, dwValueSize);
if (lResult != ERROR_SUCCESS) if (lResult != NO_ERROR)
break; break;
} }
delete [] lpData; delete [] lpData;
delete [] pszName; delete [] pszName;
if (lResult != ERROR_SUCCESS) return lResult; if (lResult != NO_ERROR) return lResult;
// Iterate over all subkeys and copy them. // Iterate over all subkeys and copy them.
dwMaxSubKeyLen++; dwMaxSubKeyLen++;
@ -238,14 +238,14 @@ LONG COpRegKeyCopy::CopyKeyRecursively(HKEY hKeySrc, HKEY hKeyDst, REGSAM samAdd
// Read subkey. // Read subkey.
lResult = ::RegEnumKeyExW(hKeySrc, dwIndex, pszName, &dwNameLen, NULL, pszClass, &dwClassLen, NULL); lResult = ::RegEnumKeyExW(hKeySrc, dwIndex, pszName, &dwNameLen, NULL, pszClass, &dwClassLen, NULL);
if (lResult == ERROR_NO_MORE_ITEMS) { if (lResult == ERROR_NO_MORE_ITEMS) {
lResult = ERROR_SUCCESS; lResult = NO_ERROR;
break; break;
} else if (lResult != ERROR_SUCCESS) } else if (lResult != NO_ERROR)
break; break;
// Open source subkey. // Open source subkey.
lResult = ::RegOpenKeyExW(hKeySrc, pszName, 0, READ_CONTROL | KEY_READ | samAdditional, &hKeySrcSub); lResult = ::RegOpenKeyExW(hKeySrc, pszName, 0, READ_CONTROL | KEY_READ | samAdditional, &hKeySrcSub);
if (lResult != ERROR_SUCCESS) break; if (lResult != NO_ERROR) break;
{ {
DWORD dwSecurityDescriptorSize; DWORD dwSecurityDescriptorSize;
@ -253,12 +253,12 @@ LONG COpRegKeyCopy::CopyKeyRecursively(HKEY hKeySrc, HKEY hKeyDst, REGSAM samAdd
// Get source subkey security descriptor size. // Get source subkey security descriptor size.
lResult = ::RegQueryInfoKeyW(hKeySrcSub, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, &dwSecurityDescriptorSize, NULL); 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. // Get source subkey security descriptor.
sa.lpSecurityDescriptor = (PSECURITY_DESCRIPTOR)(new BYTE[dwSecurityDescriptorSize]); sa.lpSecurityDescriptor = (PSECURITY_DESCRIPTOR)(new BYTE[dwSecurityDescriptorSize]);
lResult = ::RegGetKeySecurity(hKeySrc, DACL_SECURITY_INFORMATION, sa.lpSecurityDescriptor, &dwSecurityDescriptorSize); lResult = ::RegGetKeySecurity(hKeySrc, DACL_SECURITY_INFORMATION, sa.lpSecurityDescriptor, &dwSecurityDescriptorSize);
if (lResult != ERROR_SUCCESS) { if (lResult != NO_ERROR) {
delete [] (LPBYTE)(sa.lpSecurityDescriptor); delete [] (LPBYTE)(sa.lpSecurityDescriptor);
break; break;
} }
@ -266,12 +266,12 @@ LONG COpRegKeyCopy::CopyKeyRecursively(HKEY hKeySrc, HKEY hKeyDst, REGSAM samAdd
// Create new destination subkey of the same class and security. // 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); lResult = ::RegCreateKeyExW(hKeyDst, pszName, 0, pszClass, REG_OPTION_NON_VOLATILE, KEY_WRITE | samAdditional, &sa, &hKeyDstSub, NULL);
delete [] (LPBYTE)(sa.lpSecurityDescriptor); delete [] (LPBYTE)(sa.lpSecurityDescriptor);
if (lResult != ERROR_SUCCESS) break; if (lResult != NO_ERROR) break;
} }
// Copy subkey recursively. // Copy subkey recursively.
lResult = CopyKeyRecursively(hKeySrcSub, hKeyDstSub, samAdditional); lResult = CopyKeyRecursively(hKeySrcSub, hKeyDstSub, samAdditional);
if (lResult != ERROR_SUCCESS) break; if (lResult != NO_ERROR) break;
} }
delete [] pszClass; delete [] pszClass;
delete [] pszName; delete [] pszName;
@ -304,7 +304,7 @@ HRESULT COpRegKeyDelete::Execute(CSession *pSession)
// Probe to see if the key exists. // Probe to see if the key exists.
lResult = ::RegOpenKeyExW(m_hKeyRoot, m_sValue, 0, DELETE | samAdditional, &hKey); lResult = ::RegOpenKeyExW(m_hKeyRoot, m_sValue, 0, DELETE | samAdditional, &hKey);
if (lResult == ERROR_SUCCESS) { if (lResult == NO_ERROR) {
::RegCloseKey(hKey); ::RegCloseKey(hKey);
if (pSession->m_bRollbackEnabled) { if (pSession->m_bRollbackEnabled) {
@ -320,7 +320,7 @@ HRESULT COpRegKeyDelete::Execute(CSession *pSession)
HKEY hKey; HKEY hKey;
sBackupName.Format(L"%.*ls (orig %u)", iLength, (LPCWSTR)m_sValue, ++uiCount); sBackupName.Format(L"%.*ls (orig %u)", iLength, (LPCWSTR)m_sValue, ++uiCount);
lResult = ::RegOpenKeyExW(m_hKeyRoot, sBackupName, 0, KEY_ENUMERATE_SUB_KEYS | samAdditional, &hKey); lResult = ::RegOpenKeyExW(m_hKeyRoot, sBackupName, 0, KEY_ENUMERATE_SUB_KEYS | samAdditional, &hKey);
if (lResult != ERROR_SUCCESS) break; if (lResult != NO_ERROR) break;
::RegCloseKey(hKey); ::RegCloseKey(hKey);
} }
if (lResult == ERROR_FILE_NOT_FOUND) { if (lResult == ERROR_FILE_NOT_FOUND) {
@ -349,7 +349,7 @@ HRESULT COpRegKeyDelete::Execute(CSession *pSession)
lResult = DeleteKeyRecursively(m_hKeyRoot, m_sValue, samAdditional); 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; return S_OK;
else { else {
PMSIHANDLE hRecordProg = ::MsiCreateRecord(4); PMSIHANDLE hRecordProg = ::MsiCreateRecord(4);
@ -370,12 +370,12 @@ LONG COpRegKeyDelete::DeleteKeyRecursively(HKEY hKeyRoot, LPCWSTR pszKeyName, RE
// Open the key. // Open the key.
lResult = ::RegOpenKeyExW(hKeyRoot, pszKeyName, 0, DELETE | KEY_READ | samAdditional, &hKey); lResult = ::RegOpenKeyExW(hKeyRoot, pszKeyName, 0, DELETE | KEY_READ | samAdditional, &hKey);
if (lResult == ERROR_SUCCESS) { if (lResult == NO_ERROR) {
DWORD dwMaxSubKeyLen; DWORD dwMaxSubKeyLen;
// Determine the largest subkey name. // Determine the largest subkey name.
lResult = ::RegQueryInfoKeyW(hKey, NULL, NULL, NULL, NULL, &dwMaxSubKeyLen, NULL, NULL, NULL, NULL, NULL, NULL); lResult = ::RegQueryInfoKeyW(hKey, NULL, NULL, NULL, NULL, &dwMaxSubKeyLen, NULL, NULL, NULL, NULL, NULL, NULL);
if (lResult == ERROR_SUCCESS) { if (lResult == NO_ERROR) {
LPWSTR pszSubKeyName; LPWSTR pszSubKeyName;
// Prepare buffer to hold the subkey names (including zero terminator). // 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; ;) { for (dwIndex = 0; ;) {
DWORD dwNameLen = dwMaxSubKeyLen; DWORD dwNameLen = dwMaxSubKeyLen;
lResult = ::RegEnumKeyExW(hKey, dwIndex, pszSubKeyName, &dwNameLen, NULL, NULL, NULL, NULL); lResult = ::RegEnumKeyExW(hKey, dwIndex, pszSubKeyName, &dwNameLen, NULL, NULL, NULL, NULL);
if (lResult == ERROR_SUCCESS) { if (lResult == NO_ERROR) {
lResult = DeleteKeyRecursively(hKey, pszSubKeyName, samAdditional); lResult = DeleteKeyRecursively(hKey, pszSubKeyName, samAdditional);
if (lResult != ERROR_SUCCESS) if (lResult != NO_ERROR)
dwIndex++; dwIndex++;
} else if (lResult == ERROR_NO_MORE_ITEMS) { } else if (lResult == ERROR_NO_MORE_ITEMS) {
lResult = ERROR_SUCCESS; lResult = NO_ERROR;
break; break;
} else } else
dwIndex++; dwIndex++;
@ -410,7 +410,7 @@ LONG COpRegKeyDelete::DeleteKeyRecursively(HKEY hKeyRoot, LPCWSTR pszKeyName, RE
lResult = ::RegDeleteKeyW(hKeyRoot, pszKeyName); lResult = ::RegDeleteKeyW(hKeyRoot, pszKeyName);
} else if (lResult == ERROR_FILE_NOT_FOUND) { } else if (lResult == ERROR_FILE_NOT_FOUND) {
// The key doesn't exist. Not really an error in this case. // The key doesn't exist. Not really an error in this case.
lResult = ERROR_SUCCESS; lResult = NO_ERROR;
} }
return lResult; return lResult;
@ -508,7 +508,7 @@ HRESULT COpRegValueCreate::Execute(CSession *pSession)
// Open the key. // Open the key.
lResult = ::RegOpenKeyExW(m_hKeyRoot, m_sValue, 0, sam, &hKey); lResult = ::RegOpenKeyExW(m_hKeyRoot, m_sValue, 0, sam, &hKey);
if (lResult == ERROR_SUCCESS) { if (lResult == NO_ERROR) {
if (pSession->m_bRollbackEnabled) { if (pSession->m_bRollbackEnabled) {
// Order rollback action to delete the value. // Order rollback action to delete the value.
pSession->m_olRollback.AddHead(new COpRegValueDelete(m_hKeyRoot, m_sValue, m_sValueName)); pSession->m_olRollback.AddHead(new COpRegValueDelete(m_hKeyRoot, m_sValue, m_sValueName));
@ -545,7 +545,7 @@ HRESULT COpRegValueCreate::Execute(CSession *pSession)
::RegCloseKey(hKey); ::RegCloseKey(hKey);
} }
if (lResult == ERROR_SUCCESS) if (lResult == NO_ERROR)
return S_OK; return S_OK;
else { else {
PMSIHANDLE hRecordProg = ::MsiCreateRecord(5); PMSIHANDLE hRecordProg = ::MsiCreateRecord(5);
@ -593,16 +593,16 @@ HRESULT COpRegValueCopy::Execute(CSession *pSession)
// Open the key. // Open the key.
lResult = ::RegOpenKeyExW(m_hKeyRoot, m_sValue, 0, sam, &hKey); lResult = ::RegOpenKeyExW(m_hKeyRoot, m_sValue, 0, sam, &hKey);
if (lResult == ERROR_SUCCESS) { if (lResult == NO_ERROR) {
DWORD dwType, dwSize; DWORD dwType, dwSize;
// Query the source registry value size. // Query the source registry value size.
lResult = ::RegQueryValueExW(hKey, m_sValueName1, 0, NULL, NULL, &dwSize); lResult = ::RegQueryValueExW(hKey, m_sValueName1, 0, NULL, NULL, &dwSize);
if (lResult == ERROR_SUCCESS) { if (lResult == NO_ERROR) {
LPBYTE lpData = new BYTE[dwSize]; LPBYTE lpData = new BYTE[dwSize];
// Read the source registry value. // Read the source registry value.
lResult = ::RegQueryValueExW(hKey, m_sValueName1, 0, &dwType, lpData, &dwSize); lResult = ::RegQueryValueExW(hKey, m_sValueName1, 0, &dwType, lpData, &dwSize);
if (lResult == ERROR_SUCCESS) { if (lResult == NO_ERROR) {
if (pSession->m_bRollbackEnabled) { if (pSession->m_bRollbackEnabled) {
// Order rollback action to delete the destination copy. // Order rollback action to delete the destination copy.
pSession->m_olRollback.AddHead(new COpRegValueDelete(m_hKeyRoot, m_sValue, m_sValueName2)); pSession->m_olRollback.AddHead(new COpRegValueDelete(m_hKeyRoot, m_sValue, m_sValueName2));
@ -617,7 +617,7 @@ HRESULT COpRegValueCopy::Execute(CSession *pSession)
::RegCloseKey(hKey); ::RegCloseKey(hKey);
} }
if (lResult == ERROR_SUCCESS) if (lResult == NO_ERROR)
return S_OK; return S_OK;
else { else {
PMSIHANDLE hRecordProg = ::MsiCreateRecord(6); PMSIHANDLE hRecordProg = ::MsiCreateRecord(6);
@ -657,12 +657,12 @@ HRESULT COpRegValueDelete::Execute(CSession *pSession)
// Open the key. // Open the key.
lResult = ::RegOpenKeyExW(m_hKeyRoot, m_sValue, 0, sam, &hKey); lResult = ::RegOpenKeyExW(m_hKeyRoot, m_sValue, 0, sam, &hKey);
if (lResult == ERROR_SUCCESS) { if (lResult == NO_ERROR) {
DWORD dwType; DWORD dwType;
// See if the value exists at all. // See if the value exists at all.
lResult = ::RegQueryValueExW(hKey, m_sValueName, 0, &dwType, NULL, NULL); lResult = ::RegQueryValueExW(hKey, m_sValueName, 0, &dwType, NULL, NULL);
if (lResult == ERROR_SUCCESS) { if (lResult == NO_ERROR) {
if (pSession->m_bRollbackEnabled) { if (pSession->m_bRollbackEnabled) {
// Make a backup of the value first. // Make a backup of the value first.
ATL::CAtlStringW sBackupName; ATL::CAtlStringW sBackupName;
@ -671,7 +671,7 @@ HRESULT COpRegValueDelete::Execute(CSession *pSession)
for (;;) { for (;;) {
sBackupName.Format(L"%ls (orig %u)", (LPCWSTR)m_sValueName, ++uiCount); sBackupName.Format(L"%ls (orig %u)", (LPCWSTR)m_sValueName, ++uiCount);
lResult = ::RegQueryValueExW(hKey, sBackupName, 0, &dwType, NULL, NULL); lResult = ::RegQueryValueExW(hKey, sBackupName, 0, &dwType, NULL, NULL);
if (lResult != ERROR_SUCCESS) break; if (lResult != NO_ERROR) break;
} }
if (lResult == ERROR_FILE_NOT_FOUND) { 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. // 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); ::RegCloseKey(hKey);
} }
if (lResult == ERROR_SUCCESS || lResult == ERROR_FILE_NOT_FOUND) if (lResult == NO_ERROR || lResult == ERROR_FILE_NOT_FOUND)
return S_OK; return S_OK;
else { else {
PMSIHANDLE hRecordProg = ::MsiCreateRecord(5); PMSIHANDLE hRecordProg = ::MsiCreateRecord(5);

179
MSICALib/OpSvc.cpp Normal file
View File

@ -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

View File

@ -447,25 +447,25 @@ UINT COpTaskCreate::SetFromRecord(MSIHANDLE hInstall, MSIHANDLE hRecord)
ATL::CAtlStringW sFolder; ATL::CAtlStringW sFolder;
uiResult = ::MsiRecordFormatStringW(hInstall, hRecord, 3, m_sApplicationName); 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); uiResult = ::MsiRecordFormatStringW(hInstall, hRecord, 4, m_sParameters);
if (uiResult != ERROR_SUCCESS) return uiResult; if (uiResult != NO_ERROR) return uiResult;
uiResult = ::MsiRecordGetStringW(hRecord, 5, sFolder); uiResult = ::MsiRecordGetStringW(hRecord, 5, sFolder);
if (uiResult != ERROR_SUCCESS) return uiResult; if (uiResult != NO_ERROR) return uiResult;
uiResult = ::MsiGetTargetPathW(hInstall, sFolder, m_sWorkingDirectory); 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'\\') { if (!m_sWorkingDirectory.IsEmpty() && m_sWorkingDirectory.GetAt(m_sWorkingDirectory.GetLength() - 1) == L'\\') {
// Trim trailing backslash. // Trim trailing backslash.
m_sWorkingDirectory.Truncate(m_sWorkingDirectory.GetLength() - 1); m_sWorkingDirectory.Truncate(m_sWorkingDirectory.GetLength() - 1);
} }
uiResult = ::MsiRecordFormatStringW(hInstall, hRecord, 10, m_sAuthor); 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); uiResult = ::MsiRecordFormatStringW(hInstall, hRecord, 11, m_sComment);
if (uiResult != ERROR_SUCCESS) return uiResult; if (uiResult != NO_ERROR) return uiResult;
m_dwFlags = ::MsiRecordGetInteger(hRecord, 6); m_dwFlags = ::MsiRecordGetInteger(hRecord, 6);
if (m_dwFlags == MSI_NULL_INTEGER) return ERROR_INVALID_FIELD; 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; if (m_dwPriority == MSI_NULL_INTEGER) return ERROR_INVALID_FIELD;
uiResult = ::MsiRecordFormatStringW(hInstall, hRecord, 8, m_sAccountName); 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); uiResult = ::MsiRecordFormatStringW(hInstall, hRecord, 9, m_sPassword);
if (uiResult != ERROR_SUCCESS) return uiResult; if (uiResult != NO_ERROR) return uiResult;
iValue = ::MsiRecordGetInteger(hRecord, 12); iValue = ::MsiRecordGetInteger(hRecord, 12);
m_wIdleMinutes = iValue != MSI_NULL_INTEGER ? (WORD)iValue : 0; 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); m_dwMaxRuntimeMS = ::MsiRecordGetInteger(hRecord, 14);
if (m_dwMaxRuntimeMS == MSI_NULL_INTEGER) return ERROR_INVALID_FIELD; 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. // Fetch one record from the view.
uiResult = ::MsiViewFetch(hView, &hRecord); uiResult = ::MsiViewFetch(hView, &hRecord);
if (uiResult == ERROR_NO_MORE_ITEMS) return ERROR_SUCCESS; if (uiResult == ERROR_NO_MORE_ITEMS) return NO_ERROR;
else if (uiResult != ERROR_SUCCESS) return uiResult; else if (uiResult != NO_ERROR) return uiResult;
ZeroMemory(&ttData, sizeof(TASK_TRIGGER)); ZeroMemory(&ttData, sizeof(TASK_TRIGGER));
ttData.cbTriggerSize = sizeof(TASK_TRIGGER); ttData.cbTriggerSize = sizeof(TASK_TRIGGER);
@ -618,7 +618,7 @@ UINT COpTaskCreate::SetTriggersFromView(MSIHANDLE hView)
m_lTriggers.AddTail(ttData); m_lTriggers.AddTail(ttData);
} }
return ERROR_SUCCESS; return NO_ERROR;
} }

View File

@ -38,7 +38,7 @@ UINT MSICATS_API EvaluateSequence(MSIHANDLE hInstall)
// Check and add the rollback enabled state. // Check and add the rollback enabled state.
uiResult = ::MsiGetProperty(hInstall, _T("RollbackDisabled"), sValue); 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 : _ttoi(sValue) || !sValue.IsEmpty() && _totlower(sValue.GetAt(0)) == _T('y') ? FALSE : TRUE :
TRUE; TRUE;
olExecute.AddTail(new MSICA::COpRollbackEnable(bRollbackEnabled)); 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. // 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); 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! // Execute query!
uiResult = ::MsiViewExecute(hViewST, NULL); uiResult = ::MsiViewExecute(hViewST, NULL);
if (uiResult == ERROR_SUCCESS) { if (uiResult == NO_ERROR) {
//ATL::CAtlString sComponent; //ATL::CAtlString sComponent;
ATL::CAtlStringW sDisplayName; ATL::CAtlStringW sDisplayName;
@ -67,14 +67,14 @@ UINT MSICATS_API EvaluateSequence(MSIHANDLE hInstall)
// Fetch one record from the view. // Fetch one record from the view.
uiResult = ::MsiViewFetch(hViewST, &hRecord); uiResult = ::MsiViewFetch(hViewST, &hRecord);
if (uiResult == ERROR_NO_MORE_ITEMS) { if (uiResult == ERROR_NO_MORE_ITEMS) {
uiResult = ERROR_SUCCESS; uiResult = NO_ERROR;
break; break;
} else if (uiResult != ERROR_SUCCESS) } else if (uiResult != NO_ERROR)
break; break;
// Read and evaluate task's condition. // Read and evaluate task's condition.
uiResult = ::MsiRecordGetString(hRecord, 15, sValue); uiResult = ::MsiRecordGetString(hRecord, 15, sValue);
if (uiResult != ERROR_SUCCESS) break; if (uiResult != NO_ERROR) break;
condition = ::MsiEvaluateCondition(hInstall, sValue); condition = ::MsiEvaluateCondition(hInstall, sValue);
if (condition == MSICONDITION_FALSE) if (condition == MSICONDITION_FALSE)
continue; continue;
@ -85,11 +85,11 @@ UINT MSICATS_API EvaluateSequence(MSIHANDLE hInstall)
// Read task's Component ID. // Read task's Component ID.
uiResult = ::MsiRecordGetString(hRecord, 16, sValue); uiResult = ::MsiRecordGetString(hRecord, 16, sValue);
if (uiResult != ERROR_SUCCESS) break; if (uiResult != NO_ERROR) break;
// Get the component state. // Get the component state.
uiResult = ::MsiGetComponentState(hInstall, sValue, &iInstalled, &iAction); uiResult = ::MsiGetComponentState(hInstall, sValue, &iInstalled, &iAction);
if (uiResult != ERROR_SUCCESS) break; if (uiResult != NO_ERROR) break;
// Get task's DisplayName. // Get task's DisplayName.
uiResult = ::MsiRecordFormatStringW(hInstall, hRecord, 2, sDisplayName); uiResult = ::MsiRecordFormatStringW(hInstall, hRecord, 2, sDisplayName);
@ -101,19 +101,19 @@ UINT MSICATS_API EvaluateSequence(MSIHANDLE hInstall)
// Populate the operation with task's data. // Populate the operation with task's data.
uiResult = opCreateTask->SetFromRecord(hInstall, hRecord); uiResult = opCreateTask->SetFromRecord(hInstall, hRecord);
if (uiResult != ERROR_SUCCESS) break; if (uiResult != NO_ERROR) break;
// Perform another query to get task's triggers. // 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); 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! // Execute query!
uiResult = ::MsiViewExecute(hViewTT, hRecord); uiResult = ::MsiViewExecute(hViewTT, hRecord);
if (uiResult == ERROR_SUCCESS) { if (uiResult == NO_ERROR) {
// Populate trigger list. // Populate trigger list.
uiResult = opCreateTask->SetTriggersFromView(hViewTT); uiResult = opCreateTask->SetTriggersFromView(hViewTT);
::MsiViewClose(hViewTT); ::MsiViewClose(hViewTT);
if (uiResult != ERROR_SUCCESS) break; if (uiResult != NO_ERROR) break;
} else } else
break; break;
@ -130,7 +130,7 @@ UINT MSICATS_API EvaluateSequence(MSIHANDLE hInstall)
} }
::MsiViewClose(hViewST); ::MsiViewClose(hViewST);
if (uiResult == ERROR_SUCCESS) { if (uiResult == NO_ERROR) {
// Save the sequences. // Save the sequences.
uiResult = MSICA::SaveSequence(hInstall, _T("InstallScheduledTasks"), _T("CommitScheduledTasks"), _T("RollbackScheduledTasks"), olExecute); uiResult = MSICA::SaveSequence(hInstall, _T("InstallScheduledTasks"), _T("CommitScheduledTasks"), _T("RollbackScheduledTasks"), olExecute);
} else if (uiResult != ERROR_INSTALL_USEREXIT) { } else if (uiResult != ERROR_INSTALL_USEREXIT) {