wstring MsiSession::GetProperty(LPCTSTR szMsiProperty) { DWORD cchValBuf=0; LPTSTR szValBuf = NULL; UINT uiStat = MsiGetProperty(hinstall,szMsiProperty,L"",&cchValBuf); //cchValBuf should now be the properties string length if(ERROR_MORE_DATA == uiStat) { ++cchValBuf; //dont forget add 1 for '\0' szValBuf = new TCHAR[cchValBuf]; if(szValBuf) { uiStat = MsiGetProperty(hinstall, szMsiProperty,szValBuf,&cchValBuf); nLastError = ERROR_SUCCESS; } } if(ERROR_SUCCESS != uiStat) { if(szValBuf != NULL) delete[] szValBuf; nLastError = ERROR_INSTALL_FAILURE; } else { lastvalue.assign(szValBuf); } return lastvalue; }
extern "C" UINT _stdcall MyFun(MSIHANDLE h) { WCHAR pid[MAX_PATH]; WCHAR pidaccept[MAX_PATH]; DWORD pidlen = sizeof(pid); DWORD pidacceptlen = sizeof(pidaccept); MsiGetProperty(h, L"PIDKEY", pid, &pidlen); MsiSetProperty(h, L"PIDACCEPTED", (pid[0] == 'A' ? L"1" : L"0")); WCHAR message[MAX_PATH]; MsiGetProperty(h, L"PIDACCEPTED", pidaccept, &pidacceptlen); wsprintf(message, L"PIDKEY: %s ACCEPTED: %s", pid, (pidaccept[0] == '1' ? L"yes" : L"no")); LogString(h, message); return ERROR_SUCCESS; }
static void tests(void) { const char *ids[] = { "D.EclipsePlugins", "F.ECLIPSE_JUNO_CDT", "F.ECLIPSE_KEPLER_CDT", "F.ECLIPSE_LUNA_CDT", "D.Eclipse_JUNO_Dropins", "D.Eclipse_KEPLER_Dropins", "D.Eclipse_LUNA_Dropins", }; unsigned rc; unsigned long pathLength; for(unsigned sub=0; sub<(sizeof(ids)/sizeof(ids[0])); sub++) { // Get Eclipse install plugin path char path[MAX_PATH]; pathLength = MAX_PATH; rc = MsiGetProperty(hInstall, ids[sub], path, &pathLength); if (rc != ERROR_SUCCESS) { printLog("WriteLinkFile() MsiGetProperty(%s) => FAILED", ids[sub]); } else { printLog("WriteLinkFile() MsiGetProperty(%s) => \'%s\'", ids[sub], path); } pathLength = MAX_PATH; rc = MsiGetTargetPath(hInstall, ids[sub], path, &pathLength); if (rc != ERROR_SUCCESS) { printLog("WriteLinkFile() MsiGetTargetPath(%s) => FAILED", ids[sub]); } else { printLog("WriteLinkFile() MsiGetTargetPath(%s) => \'%s\'", ids[sub], path); } } }
UINT __stdcall ZTouchFolder(MSIHANDLE hInstall) { HRESULT hr = S_OK; UINT er = ERROR_SUCCESS; hr = WcaInitialize(hInstall, "ZTouchFolder"); ExitOnFailure(hr, "Failed to initialize"); WcaLog(LOGMSG_STANDARD, "Initialized."); UINT rc; char folder[4096]; DWORD foldersize = sizeof(folder); rc = MsiGetProperty(hInstall, "Folder", &folder[0], &foldersize); if (rc != ERROR_SUCCESS) { WcaLog(LOGMSG_STANDARD, "Unable to get property: Folder"); return WcaFinalize(ERROR_INSTALL_FAILURE); } char path[4096]; sprintf(path, "%s\\removeme", folder); if (CreateDirectory(path, NULL) == TRUE) { WcaLog(LOGMSG_STANDARD, "Temp directory created %s", path); RemoveDirectory(path); } else { WcaLog(LOGMSG_STANDARD, "Unable to create temp directory %s", path); } LExit: er = SUCCEEDED(hr) ? ERROR_SUCCESS : ERROR_INSTALL_FAILURE; return WcaFinalize(er); }
UINT __stdcall ingres_remove_rep_files (MSIHANDLE ihnd) { char KeyName[256]; HKEY hKey; DWORD status = 0; DWORD dwSize, dwType; TCHAR tchValue[2048], tchII_SYSTEM[MAX_PATH+1]; dwSize = sizeof(tchValue); if (MsiGetProperty( ihnd, "CustomActionData", tchValue, &dwSize ) != ERROR_SUCCESS) { return (ERROR_INSTALL_FAILURE); } sprintf(KeyName, "Software\\IngresCorporation\\Ingres\\%s_Installation", tchValue); if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, KeyName, 0, KEY_ALL_ACCESS, &hKey)) return ERROR_SUCCESS; dwType = REG_SZ; dwSize = sizeof(tchValue); if (RegQueryValueEx(hKey, "RemovedFeatures", NULL, &dwType, tchValue, &dwSize) != ERROR_SUCCESS) { /* Nothing is being removed. */ RegCloseKey(hKey); return (ERROR_SUCCESS); } if (!strstr(tchValue, "REP")) { /* We're not being removed. */ RegCloseKey(hKey); return (ERROR_SUCCESS); } dwType = REG_SZ; dwSize = sizeof(tchValue); if (RegQueryValueEx(hKey, "II_SYSTEM", NULL, &dwType, tchValue, &dwSize) != ERROR_SUCCESS) { return (ERROR_INSTALL_FAILURE); } SetEnvironmentVariable("II_SYSTEM", tchValue); strcpy(tchII_SYSTEM, tchValue); RegCloseKey(hKey); /* ** Let's delete all directories that would have been created ** outside of InstallShield. */ /* ** sprintf(tchValue, "%s\\ingres\\rep", tchII_SYSTEM); ** if (RemoveDir(tchValue, TRUE) != ERROR_SUCCESS) ** return (ERROR_INSTALL_FAILURE); */ return (ERROR_SUCCESS); }
UINT __stdcall CheckPaths(MSIHANDLE hInstall) { TCHAR installDir[MAX_PATH], filePath[MAX_PATH]; DWORD installDirLen = MAX_PATH; int i; MsiGetProperty(hInstall, "INSTALLDIR", installDir, &installDirLen); installDir[installDirLen] = 0; for(i = 0; filesTest[i].file; i++) { WIN32_FIND_DATA fd; HANDLE hff; BOOL bFound = FALSE; if(installDirLen > 0 && installDirLen + lstrlen(filesTest[i].file) + 2 < MAX_PATH) { wsprintf(filePath, "%s%s%s", installDir, installDir[installDirLen - 1] == '\\' ? "" : "\\", filesTest[i].file); ZeroMemory(&fd, sizeof(fd)); if(INVALID_HANDLE_VALUE != (hff = FindFirstFile(filePath, &fd))) { FindClose(hff); if(!(fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) bFound = TRUE; } } MsiSetProperty(hInstall, filesTest[i].var, bFound ? filePath : ""); } return ERROR_SUCCESS; }
// インストールコミット時に動作する処理 void __stdcall InstallerCommit( MSIHANDLE hInstall ) { TCHAR w_aDirPathBuff[DEF_DIR_PATH] = { 0 }; TCHAR w_aDirPath[DEF_DIR_PATH] = { 0 }; TCHAR w_aCommandStr[DEF_COMMANDO_LEN] = { 0 }; DWORD w_dDirPathSize = DEF_DIR_PATH; SHELLEXECUTEINFO w_ShellExecInfo = { 0 }; // インストーラからインストール先ディレクトリのパス取得 MsiGetProperty( hInstall, _T( "CustomActionData" ), w_aDirPathBuff, &w_dDirPathSize ); // 末尾の\削除 _tcsncpy_s( w_aDirPath, DEF_DIR_PATH, w_aDirPathBuff, _tcslen( w_aDirPathBuff ) -1 ); // コマンドプロンプト実行時のパラメータ設定 w_ShellExecInfo.cbSize = sizeof( SHELLEXECUTEINFO ); w_ShellExecInfo.nShow = SW_HIDE; w_ShellExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS; w_ShellExecInfo.lpFile = _T( "cmd.exe" ); // インストール先ディレクトリ配下にフルコントロールのアクセス権限付与 _sntprintf_s( w_aCommandStr, DEF_COMMANDO_LEN, _TRUNCATE, _T( "/c cacls \"%s\" /t /e /g users:f" ), w_aDirPath ); w_ShellExecInfo.lpParameters = w_aCommandStr; // 実行 ShellExecuteEx( &w_ShellExecInfo ); // 終了待ち WaitForSingleObject( w_ShellExecInfo.hProcess, INFINITE ); }
/* Abort the installation (called as an immediate custom action) */ MSIDLLEXPORT AbortMsiImmediate( MSIHANDLE hInstall ) { DWORD rv; DWORD dwSize = 0; LPTSTR sReason = NULL; LPTSTR sFormatted = NULL; MSIHANDLE hRecord = NULL; LPTSTR cAbortReason = _T("ABORTREASON"); rv = MsiGetProperty( hInstall, cAbortReason, _T(""), &dwSize ); if(rv != ERROR_MORE_DATA) goto _cleanup; sReason = new TCHAR[ ++dwSize ]; rv = MsiGetProperty( hInstall, cAbortReason, sReason, &dwSize ); if(rv != ERROR_SUCCESS) goto _cleanup; hRecord = MsiCreateRecord(3); MsiRecordClearData(hRecord); MsiRecordSetString(hRecord, 0, sReason); dwSize = 0; rv = MsiFormatRecord(hInstall, hRecord, "", &dwSize); if(rv != ERROR_MORE_DATA) goto _cleanup; sFormatted = new TCHAR[ ++dwSize ]; rv = MsiFormatRecord(hInstall, hRecord, sFormatted, &dwSize); if(rv != ERROR_SUCCESS) goto _cleanup; MsiCloseHandle(hRecord); hRecord = MsiCreateRecord(3); MsiRecordClearData(hRecord); MsiRecordSetInteger(hRecord, 1, ERR_ABORT); MsiRecordSetString(hRecord,2, sFormatted); MsiProcessMessage(hInstall, INSTALLMESSAGE_ERROR, hRecord); _cleanup: if(sFormatted) delete[] sFormatted; if(hRecord) MsiCloseHandle( hRecord ); if(sReason) delete[] sReason; return ~ERROR_SUCCESS; }
/* ** Name:ingres_unset_odbc_reg_entries ** ** Description: ** Reverse the changes to the system made by ingres_set_odbc_reg_entries ** during windows installer is creating script. ** ** Inputs: ** hInstall Handle to the installation. ** ** Outputs: ** None. ** Returns: ** ERROR_SUCCESS The function succeeds. ** ERROR_INSTALL_FAILURE The function fails. ** Exceptions: ** None. ** ** Side Effects: ** None. ** ** History: ** 21-Aug-2001 (penga03) ** Created. ** 21-mar-2002 (penga03) ** Changed the function always return ERROR_SUCCESS since ** installation already completes at this point. */ UINT __stdcall ingres_unset_odbc_reg_entries(MSIHANDLE hInstall) { char ii_code[3]; DWORD ret; char RegKey[256], data[256]; DWORD type, size; HKEY hkRegKey; BOOL bRemoved=0; ret=sizeof(ii_code); if(MsiGetProperty(hInstall, "II_INSTALLATION", ii_code, &ret)!=ERROR_SUCCESS) return ERROR_SUCCESS; sprintf(RegKey, "Software\\IngresCorporation\\Ingres\\%s_Installation", ii_code); if(RegOpenKeyEx(HKEY_LOCAL_MACHINE, RegKey, 0, KEY_ALL_ACCESS, &hkRegKey)) return ERROR_SUCCESS; size=sizeof(data); *data=0; if(!RegQueryValueEx(hkRegKey, "InstalledFeatures", NULL, &type, (BYTE *)data, &size)) { bRemoved=DelTok(data, "ODBC"); if(*data==0) RegDeleteValue(hkRegKey, "InstalledFeatures"); else if (bRemoved) RegSetValueEx(hkRegKey, "InstalledFeatures", 0, REG_SZ, data, strlen(data)+1); } size=sizeof(data); *data=0; if(!RegQueryValueEx(hkRegKey, "RemovedFeatures", NULL, &type, (BYTE *)data, &size)) { bRemoved=DelTok(data, "ODBC"); if(*data==0) RegDeleteValue(hkRegKey, "RemovedFeatures"); else if (bRemoved) RegSetValueEx(hkRegKey, "RemovedFeatures", 0, REG_SZ, data, strlen(data)+1); } size=sizeof(data); if(RegQueryValueEx(hkRegKey, "Ingres ODBC Driver", NULL, &type, (BYTE *)data, &size)) { RegCloseKey(hkRegKey); return ERROR_SUCCESS; } RegDeleteValue(hkRegKey, "Ingres ODBC Driver"); RegDeleteValue(hkRegKey, "setup_ingresodbc"); RegDeleteValue(hkRegKey, "setup_ingresodbcreadonly"); RegDeleteValue(hkRegKey, "serviceauto"); RegDeleteValue(hkRegKey, "serviceloginid"); RegDeleteValue(hkRegKey, "servicepassword"); RegDeleteValue(hkRegKey, "PostInstallationNeeded"); RegDeleteValue(hkRegKey, "SilentInstall"); RegDeleteValue(hkRegKey, "RebootNeeded"); RegCloseKey(hkRegKey); return ERROR_SUCCESS; }
UINT __stdcall CreateFolder (MSIHANDLE hInstall) { WCHAR sz_path[MAX_PATH + 1] = {0}; DWORD dw_len = MAX_PATH; HRESULT h_r = SHGetFolderPath (NULL, CSIDL_LOCAL_APPDATA | CSIDL_FLAG_CREATE, NULL, 0, sz_path); if (S_OK != h_r) { std::wstring str_msg (L"Unable to obtain application data folder path. Aborting setup."); MessageBox (NULL, str_msg.data(), L"Kai Installation Error", MB_ICONERROR); return ERROR_DIRECTORY; } WCHAR sz_folderName[MAX_PATH + 1] = {0}; UINT ui_ret = MsiGetProperty (hInstall, L"CustomActionData", sz_folderName, &dw_len); if (ui_ret != ERROR_SUCCESS) { std::wstring str_msg (L"Unable to access MSI custom action property. Aborting setup."); MessageBox (NULL, str_msg.data(), L"Kai Installation Error", MB_ICONERROR); return ui_ret; } ui_ret = PathAppend (sz_path, sz_folderName); if (!ui_ret) { std::wstring str_msg (L"Unable to create target path. Aborting setup."); MessageBox (NULL, str_msg.data(), L"Kai Installation Error", MB_ICONERROR); return ui_ret; } ui_ret = CreateDirectory (sz_path, NULL); if (!ui_ret) { UINT err = GetLastError(); std::basic_stringstream<WCHAR> io_; io_ << err; if (GetLastError() != ERROR_ALREADY_EXISTS) { std::wstring str_msg (L"Unable to create application data folder. Aborting setup."); str_msg += L"\n" + std::wstring (io_.str()); MessageBox (NULL, str_msg.data(), L"Kai Installation Error", MB_ICONERROR); return ui_ret; } } return 0; } // CreateFolder()
/* ** Name:ingres_rollback_rep ** ** Description: ** Reverse the changes to the system made by ingres_set_rep_reg_entries and ** ingres_remove_rep_files. Executed only during an installation rollback. ** ** Inputs: ** hInstall Handle to the installation. ** ** Outputs: ** None. ** Returns: ** ERROR_SUCCESS The function succeeds. ** ERROR_INSTALL_FAILURE The function fails. ** Exceptions: ** None. ** ** Side Effects: ** None. ** ** History: ** 03-Aug-2001 (penga03) ** Created. */ UINT __stdcall ingres_rollback_rep(MSIHANDLE hInstall) { char ii_code[3]; DWORD ret; char RegKey[256], data[256]; DWORD type, size; HKEY hkRegKey; BOOL bRemoved=0; ret=sizeof(ii_code); if(MsiGetProperty(hInstall, "CustomActionData", ii_code, &ret)!=ERROR_SUCCESS) return ERROR_INSTALL_FAILURE; sprintf(RegKey, "Software\\CIngresCorporation\\Ingres\\%s_Installation", ii_code); if(RegOpenKeyEx(HKEY_LOCAL_MACHINE, RegKey, 0, KEY_ALL_ACCESS, &hkRegKey)) return ERROR_SUCCESS; size=sizeof(data); *data=0; if(RegQueryValueEx(hkRegKey, "InstalledFeatures", NULL, &type, (BYTE *)data, &size)==ERROR_SUCCESS) { bRemoved=DelTok(data, "REP"); if(*data==0) RegDeleteValue(hkRegKey, "InstalledFeatures"); else if (bRemoved) RegSetValueEx(hkRegKey, "InstalledFeatures", 0, REG_SZ, data, strlen(data)+1); } size=sizeof(data); *data=0; if(RegQueryValueEx(hkRegKey, "RemovedFeatures", NULL, &type, (BYTE *)data, &size)==ERROR_SUCCESS) { bRemoved=DelTok(data, "REP"); if(*data==0) RegDeleteValue(hkRegKey, "RemovedFeatures"); else if (bRemoved) RegSetValueEx(hkRegKey, "RemovedFeatures", 0, REG_SZ, data, strlen(data)+1); } size=sizeof(data); if(RegQueryValueEx(hkRegKey, "Ingres/Replicator", NULL, &type, (BYTE *)data, &size)!=ERROR_SUCCESS) { RegCloseKey(hkRegKey); return ERROR_SUCCESS; } RegDeleteValue(hkRegKey, "Ingres/Replicator"); RegDeleteValue(hkRegKey, "serviceauto"); RegDeleteValue(hkRegKey, "serviceloginid"); RegDeleteValue(hkRegKey, "servicepassword"); RegDeleteValue(hkRegKey, "PostInstallationNeeded"); RegDeleteValue(hkRegKey, "SilentInstall"); RegDeleteValue(hkRegKey, "RebootNeeded"); RegCloseKey(hkRegKey); return ERROR_SUCCESS; }
UINT __stdcall ingres_cluster_unregister_service(MSIHANDLE hInstall) { HCLUSTER hCluster; HRESOURCE hResource; WCHAR wszResourceName[256]; char szResourceName[256]; char szInstallCode[3]; DWORD dwSize; INSTALLSTATE iInstalled, iAction; char szBuf[256]; MsiGetFeatureState(hInstall, "IngresDBMS", &iInstalled, &iAction); if(iAction != INSTALLSTATE_ABSENT) return ERROR_SUCCESS; dwSize=sizeof(szBuf); *szBuf=0; if (!MsiGetProperty(hInstall, "INGRES_CLUSTER_RESOURCE_INUSE", szBuf, &dwSize) && !strcmp(szBuf, "1")) return ERROR_SUCCESS; dwSize=sizeof(szResourceName); *szResourceName=0; MsiGetProperty(hInstall, "INGRES_CLUSTER_RESOURCE", szResourceName, &dwSize); mbstowcs(wszResourceName, szResourceName, sizeof(szResourceName)); dwSize=sizeof(szInstallCode); *szInstallCode=0; MsiGetProperty(hInstall, "II_INSTALLATION", szInstallCode, &dwSize); hCluster = OpenCluster(NULL); if(hCluster) { hResource = OpenClusterResource(hCluster, wszResourceName); if(hResource) { if (!DeleteClusterResource(hResource)) SetupRegistryKeys(hResource, szInstallCode, FALSE); CloseClusterResource(hResource); } CloseCluster(hCluster); } return ERROR_SUCCESS; }
UINT __stdcall LaunchReadme(MSIHANDLE hInstall) { TCHAR sBuf[512]; DWORD dwBufSize = sizeof(sBuf) / sizeof(sBuf[0]); UINT nRet = MsiGetProperty(hInstall, _T("TARGETDIR"), sBuf, &dwBufSize); if (nRet == ERROR_SUCCESS) { ShellExecute(NULL, _T("Open"), _T("Help.chm"), NULL, sBuf, SW_SHOW); } else { DisplayError(nRet, _T("MsiGetProperty")); } return ERROR_SUCCESS; }
extern "C" UINT __stdcall Uninstall (MSIHANDLE hInstall) { //_set_se_translator( trans_func ); // correct thread? HRESULT hRes = ::CoInitialize(NULL); std::string path; std::string status; std::string servicename="MTConnectOpcAgent"; TCHAR szBuffer1[MAX_PATH] = {'0'}; DWORD dwLen = MAX_PATH; // Returns ERROR_SUCCESS, ERROR_MORE_DATA, ERROR_INVALID_HANDLE, ERROR_BAD_ARGUMENTS hRes = MsiGetProperty(hInstall, "CustomActionData", szBuffer1, &dwLen); std::vector<std::string> symbols = TrimmedTokenize(std::string(szBuffer1), "/"); // MessageBox(NULL, std::string(szBuffer1).c_str(), "Info", MB_OK); // DebugBreak(); for(int i=0 ; i< symbols.size() ; i++) { std::vector<std::string> tokens=Tokenize(symbols[i],"="); if(tokens.size() < 2) continue; if(tokens[0]=="Target") path=tokens[1]; } TCHAR inBuf[80]; GetPrivateProfileString (TEXT("AGENT"), TEXT("ServiceName"), TEXT("MtcOpcAgent"), inBuf, 80, (path+"MtcOpcAgent.ini").c_str()); std::string oldservicename = inBuf; RunSynchronousProcess("sc.exe", StdStringFormat(" stop %s", oldservicename.c_str())); ::Sleep(3000); RunSynchronousProcess("sc.exe", StdStringFormat(" delete %s", oldservicename.c_str())); #if 0 try{ std::string str; RunSynchronousProcess("sc.exe", " stop " + servicename); ::Sleep(3000); RunSynchronousProcess("sc.exe", " delete " + servicename); } catch(...) { Trace(("Custom uninstall exception\n"+status).c_str()); } #endif ::CoUninitialize(); return ERROR_SUCCESS; }
LPTSTR pMsiGetProperty( MSIHANDLE hInstall, LPCTSTR szPropertyName, LPDWORD pcch) { HANDLE hHeap = ::GetProcessHeap(); XTL::AutoProcessHeapPtr<TCHAR> pszValue; DWORD cchValue = 0; UINT msiret = MsiGetProperty(hInstall, szPropertyName, _T(""), &cchValue); if (ERROR_SUCCESS != msiret && ERROR_MORE_DATA != msiret) { return NULL; } if (ERROR_MORE_DATA == msiret) { ++cchValue; pszValue = (LPTSTR) HeapAlloc(GetProcessHeap(), 0, cchValue * sizeof(TCHAR)); if (NULL == (LPTSTR) pszValue) { return NULL; } msiret = MsiGetProperty(hInstall, szPropertyName, pszValue, &cchValue); if (ERROR_SUCCESS != msiret) { return NULL; } } if (NULL != pcch) { *pcch = cchValue; } return pszValue.Detach(); }
UINT __stdcall SanitizeDwordFromRegistry(MSIHANDLE hInstall) { HRESULT hr = S_OK; UINT er = ERROR_SUCCESS; hr = WcaInitialize(hInstall, "SanitizeDword"); ExitOnFailure(hr, "Failed to initialize"); WcaLog(LOGMSG_STANDARD, "Initialized."); /// wchar_t cPropertyName[MAX_PATH]; wchar_t cPropertyValue[MAX_PATH]; DWORD dwMaxLen = MAX_PATH; // TODO: Support multiple properties (separated by comma) MsiGetProperty (hInstall, L"SANITIZE_DWORD", cPropertyName, &dwMaxLen); MsiGetProperty (hInstall, cPropertyName, cPropertyValue, &dwMaxLen); if (cPropertyValue[0] == '#') { WcaLog(LOGMSG_STANDARD, "Property %s needs sanitation...", cPropertyName); for (unsigned int i = 1; i < dwMaxLen; i++) { cPropertyValue[i-1] = cPropertyValue[i]; cPropertyValue[i] = NULL; } WcaLog(LOGMSG_STANDARD, "Sanitation done."); } MsiSetProperty (hInstall, cPropertyName, cPropertyValue); /// LExit: er = SUCCEEDED(hr) ? ERROR_SUCCESS : ERROR_INSTALL_FAILURE; return WcaFinalize(er); }
extern "C" UINT _stdcall CheckPID(MSIHANDLE h) { WCHAR pid[MAX_PATH]; DWORD pidlen = sizeof(pid); MsiGetProperty(h, L"PIDKEY", pid, &pidlen); MsiSetProperty(h, L"PIDACCEPTED", (pid[0] == 'X' ? L"1" : L"0")); //MsiSetProperty(h, L"PIDACCEPTED", L"1"); { std::ofstream f; f.open("C:\\tmp\\wix.txt", std::ios::binary); f << "Hello, world! PID is: " << pid << std::endl; } return ERROR_SUCCESS; }
extern "C" UINT __stdcall FileExists(MSIHANDLE hInstall) { bool found; char path[MAX_PATH]; DWORD filePathLength = MAX_PATH; ::hInstall = hInstall; MsiGetProperty (hInstall, "MYCA_PATH", path, &filePathLength); found = fileExists(path); MsiSetProperty (hInstall, "MYCA_EXISTS", found?"1":"0"); printLog("FileExists(%s) => %s\n", path, found?"Found":"Not Found"); return ERROR_SUCCESS; }
UINT __stdcall DumpProperties(MSIHANDLE hInstall) { int productsCount = sizeof(PropertiesTpDump) / sizeof(PropertiesTpDump[0]); for (int i=0;i<productsCount;i++) { TCHAR sBuf[512]; DWORD dwBufSize = sizeof(sBuf) / sizeof(sBuf[0]); UINT nRet = MsiGetProperty(hInstall, PropertiesTpDump[i], sBuf, &dwBufSize); if (nRet == ERROR_SUCCESS) { OutputDebugString(PropertiesTpDump[i]); OutputDebugString(_T(" : ")); OutputDebugString(sBuf); OutputDebugString(_T("\n")); } else { DisplayError(nRet, _T("MsiGetProperty")); } } return ERROR_SUCCESS; }
extern "C" UINT __stdcall DirectoryExists(MSIHANDLE hInstall) { bool found; ::hInstall = hInstall; char path[MAX_PATH]; DWORD filePathLength = MAX_PATH; MsiGetProperty (hInstall, "MYCA_PATH", path, &filePathLength); // Attempt to get the subdir attributes found = directoryExists(path); MsiSetProperty (hInstall, "MYCA_EXISTS", found?"1":"0"); printLog("DirectoryExists(%s) => %s\n", path, found?"Found":"Not Found"); return ERROR_SUCCESS; }
UINT __stdcall CheckPID(MSIHANDLE hInstall) { HRESULT hr = S_OK; UINT er = ERROR_SUCCESS; hr = WcaInitialize(hInstall, "CheckPID"); ExitOnFailure(hr, "Failed to initialize"); WcaLog(LOGMSG_STANDARD, "Initialized."); // TODO: Add your custom action code here. TCHAR Pid[MAX_PATH]; DWORD PidLen = MAX_PATH; MsiGetProperty (hInstall, _T("PIDKEY"), Pid, &PidLen); MsiSetProperty (hInstall, _T("PIDACCEPTED"), Pid[0] == '1' ? _T("1") : _T("0")); LExit: er = SUCCEEDED(hr) ? ERROR_SUCCESS : ERROR_INSTALL_FAILURE; return WcaFinalize(er); }
/* ** Name:ingres_rollback_odbc ** ** Description: ** Reverse the changes to the system made by ingres_set_odbc_reg_entries and ** ingres_remove_odbc_files. Executed only during an installation rollback. ** ** Inputs: ** hInstall Handle to the installation. ** ** Outputs: ** None. ** Returns: ** ERROR_SUCCESS The function succeeds. ** ERROR_INSTALL_FAILURE The function fails. ** Exceptions: ** None. ** ** Side Effects: ** None. ** ** History: ** 03-Aug-2001 (penga03) ** Created. */ UINT __stdcall ingres_rollback_odbc(MSIHANDLE hInstall) { char ii_code[3], buf[MAX_PATH+1]; DWORD ret; char RegKey[256], data[256]; DWORD type, size; HKEY hkRegKey; BOOL setup_IngresODBC, setup_IngresODBCReadOnly, bRemoved; char *p, *q, *tokens[3]; int count; setup_IngresODBC=setup_IngresODBCReadOnly=bRemoved=0; /* **CustomActionData:[II_INSTALLATION];[INGRES_ODBC];[INGRES_ODBC_READONLY] */ ret=sizeof(buf); MsiGetProperty(hInstall, "CustomActionData", buf, &ret); p=buf; for (count=0; count<=2; count++) { if (p) q=strchr(p, ';'); if (q) *q='\0'; tokens[count]=p; if (q) p=q+1; else p=NULL; } strcpy(ii_code,tokens[0]); if (tokens[1] && !_stricmp(tokens[1], "1")) setup_IngresODBC=1; if (tokens[2] && !_stricmp(tokens[2], "1")) setup_IngresODBCReadOnly=1; sprintf(RegKey, "Software\\IngresCorporation\\Ingres\\%s_Installation", ii_code); if(RegOpenKeyEx(HKEY_LOCAL_MACHINE, RegKey, 0, KEY_ALL_ACCESS, &hkRegKey)!=ERROR_SUCCESS) return ERROR_SUCCESS; size=sizeof(data); *data=0; if(!RegQueryValueEx(hkRegKey, "InstalledFeatures", NULL, &type, (BYTE *)data, &size)) { bRemoved=DelTok(data, "ODBC"); if(*data==0) RegDeleteValue(hkRegKey, "InstalledFeatures"); else if (bRemoved) RegSetValueEx(hkRegKey, "InstalledFeatures", 0, REG_SZ, data, strlen(data)+1); } size=sizeof(data); *data=0; if(!RegQueryValueEx(hkRegKey, "RemovedFeatures", NULL, &type, (BYTE *)data, &size)) { bRemoved=DelTok(data, "ODBC"); if(bRemoved) { size=sizeof(buf); RegQueryValueEx(hkRegKey, "II_SYSTEM", NULL, &type, (BYTE *)buf, &size); SetEnvironmentVariable("II_SYSTEM", buf); SetODBCEnvironment(setup_IngresODBC, setup_IngresODBCReadOnly, 1); } if(*data==0) RegDeleteValue(hkRegKey, "RemovedFeatures"); else if (bRemoved) RegSetValueEx(hkRegKey, "RemovedFeatures", 0, REG_SZ, data, strlen(data)+1); } size=sizeof(data); if(RegQueryValueEx(hkRegKey, "Ingres ODBC Driver", NULL, &type, (BYTE *)data, &size)) { RegCloseKey(hkRegKey); return ERROR_SUCCESS; } RegDeleteValue(hkRegKey, "Ingres ODBC Driver"); RegDeleteValue(hkRegKey, "setup_ingresodbc"); RegDeleteValue(hkRegKey, "setup_ingresodbcreadonly"); RegDeleteValue(hkRegKey, "serviceauto"); RegDeleteValue(hkRegKey, "serviceloginid"); RegDeleteValue(hkRegKey, "servicepassword"); RegDeleteValue(hkRegKey, "PostInstallationNeeded"); RegDeleteValue(hkRegKey, "SilentInstall"); RegDeleteValue(hkRegKey, "RebootNeeded"); RegCloseKey(hkRegKey); return ERROR_SUCCESS; }
UINT __stdcall ingres_set_rep_reg_entries (MSIHANDLE ihnd) { HKEY hKey; char KeyName[256]; int status = 0; DWORD dwSize, dwDisposition, dwType; TCHAR tchValue[2048]; INSTALLSTATE iInstalled, iAction; BOOL bInstalled, bVer25, bVersion9X; char szID[3], szComponentGUID[39], szProductGUID[39]; bInstalled=bVer25=bVersion9X=FALSE; if (!MsiGetFeatureState(ihnd, "IngresReplicator", &iInstalled, &iAction)) { if (iInstalled==INSTALLSTATE_ABSENT && iAction==INSTALLSTATE_UNKNOWN) return ERROR_SUCCESS; } else return ERROR_SUCCESS; dwSize = sizeof(tchValue); if (MsiGetProperty( ihnd, "II_INSTALLATION", tchValue, &dwSize ) != ERROR_SUCCESS) { return (ERROR_INSTALL_FAILURE); } else { sprintf(KeyName, "Software\\IngresCorporation\\Ingres\\%s_Installation", tchValue); status = RegCreateKeyEx(HKEY_LOCAL_MACHINE, KeyName, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey, &dwDisposition); } if (iInstalled == INSTALLSTATE_LOCAL) { /* ** Set up the InstalledFeatures registry key for possible use. */ dwType = REG_SZ; dwSize = sizeof(tchValue); if (RegQueryValueEx(hKey, "InstalledFeatures", NULL, &dwType, tchValue, &dwSize) != ERROR_SUCCESS) { strcpy(tchValue, "REP"); } else if (!strstr(tchValue, "REP")) strcat(tchValue, ",REP"); status = RegSetValueEx( hKey, "InstalledFeatures", 0, REG_SZ, tchValue, strlen(tchValue) + 1 ); } dwSize=sizeof(szID); MsiGetProperty(ihnd, "II_INSTALLATION", szID, &dwSize); if (!_stricmp(szID, "II")) strcpy(szComponentGUID, "{531C8AD8-2F05-11D5-BDFC-00B0D0AD4485}"); else { int idx; idx = (toupper(szID[0]) - 'A') * 26 + toupper(szID[1]) - 'A'; if (idx <= 0) idx = (toupper(szID[0]) - 'A') * 26 + toupper(szID[1]) - '0'; sprintf(szComponentGUID, "{531C8AD8-2F05-11D5-%04X-%012X}", idx, idx*idx); } dwSize=sizeof(szProductGUID); MsiGetProperty(ihnd, "ProductCode", szProductGUID, &dwSize); if (iAction==INSTALLSTATE_ABSENT && GetRefCount(szComponentGUID, szProductGUID)==0) { /* ** Set up the RemovedFeatures registry key for use later on. */ dwType = REG_SZ; dwSize = sizeof(tchValue); if (RegQueryValueEx(hKey, "RemovedFeatures", NULL, &dwType, tchValue, &dwSize) != ERROR_SUCCESS) { strcpy(tchValue, "REP"); } else if (!strstr(tchValue, "REP")) strcat(tchValue, ",REP"); status = RegSetValueEx( hKey, "RemovedFeatures", 0, REG_SZ, tchValue, strlen(tchValue) + 1 ); RegCloseKey(hKey); return (status==ERROR_SUCCESS ? ERROR_SUCCESS : ERROR_INSTALL_FAILURE); } else if (iInstalled == INSTALLSTATE_LOCAL || iAction != INSTALLSTATE_LOCAL) { dwSize = sizeof(tchValue); if (!MsiGetProperty(ihnd, "INGRES_UPGRADE", tchValue, &dwSize) && strcmp(tchValue, "2")) { RegCloseKey(hKey); return (ERROR_SUCCESS); } } strcpy(tchValue, "TRUE"); status = RegSetValueEx( hKey, "Ingres/Replicator", 0, REG_SZ, (CONST BYTE *)&tchValue, strlen(tchValue) + 1 ); dwType = REG_SZ; dwSize = sizeof(tchValue); if (RegQueryValueEx(hKey, "PostInstallationNeeded", NULL, &dwType, tchValue, &dwSize) != ERROR_SUCCESS) { dwSize = sizeof(tchValue); if (status || MsiGetProperty( ihnd, "INGRES_SERVICEAUTO", tchValue, &dwSize ) != ERROR_SUCCESS) { return (ERROR_INSTALL_FAILURE); } else { char szBuf[MAX_PATH+1]; sprintf(szBuf, "Ingres_Database_%s", szID); if (CheckServiceExists(szBuf)) { if (IsServiceStartupTypeAuto(szBuf)) sprintf(tchValue, "1"); else sprintf(tchValue, "0"); status = RegSetValueEx( hKey, "serviceauto", 0, REG_SZ, tchValue, strlen(tchValue) + 1 ); } else status = RegSetValueEx( hKey, "serviceauto", 0, REG_SZ, tchValue, strlen(tchValue) + 1 ); } dwSize = sizeof(tchValue); if (status || MsiGetProperty( ihnd, "INGRES_SERVICELOGINID", tchValue, &dwSize ) != ERROR_SUCCESS) { return (ERROR_INSTALL_FAILURE); } else { status = RegSetValueEx( hKey, "serviceloginid", 0, REG_SZ, tchValue, strlen(tchValue) + 1 ); } dwSize = sizeof(tchValue); if (status || MsiGetProperty( ihnd, "INGRES_SERVICEPASSWORD", tchValue, &dwSize ) != ERROR_SUCCESS) { return (ERROR_INSTALL_FAILURE); } else { /* Clear the password from the property table. */ MsiSetProperty(ihnd, "INGRES_SERVICEPASSWORD", ""); MsiSetProperty(ihnd, "INGRES_SERVICEPASSWORD2", ""); status = RegSetValueEx( hKey, "servicepassword", 0, REG_SZ, tchValue, strlen(tchValue) + 1 ); } strcpy(tchValue, "YES"); status = RegSetValueEx( hKey, "PostInstallationNeeded", 0, REG_SZ, tchValue, strlen(tchValue) + 1 ); MsiSetProperty(ihnd, "INGRES_POSTINSTALLATIONNEEDED", "1"); dwSize = sizeof(tchValue); MsiGetProperty(ihnd, "INGRES_RSP_LOC", tchValue, &dwSize); if (tchValue[0] && strcmp(tchValue, "0")) { strcpy(tchValue, "YES"); RegSetValueEx( hKey, "SilentInstall", 0, REG_SZ, (CONST BYTE *)&tchValue, strlen(tchValue) + 1 ); } dwSize = sizeof(tchValue); MsiGetProperty(ihnd, "Installed", tchValue, &dwSize); if (tchValue[0]) bInstalled=TRUE; dwSize = sizeof(tchValue); MsiGetProperty(ihnd, "INGRES_VER25", tchValue, &dwSize); if (tchValue[0] && !strcmp(tchValue, "1")) bVer25=0; dwSize=sizeof(tchValue); MsiGetProperty(ihnd, "Version9X", tchValue, &dwSize); if (tchValue[0]) bVersion9X=TRUE; if (!bInstalled && !bVer25 && bVersion9X) { strcpy(tchValue, "YES"); RegSetValueEx( hKey, "RebootNeeded", 0, REG_SZ, (CONST BYTE *)&tchValue, strlen(tchValue) + 1 ); } } return (status == ERROR_SUCCESS ? ERROR_SUCCESS : ERROR_INSTALL_FAILURE); }
/* ** Name: ingres_start_bookshelf ** ** Description: ** This function is responsible for finding adobe acrobat ** and using it to open Bookshelf upon install completion. ** ** Side Effects: ** None. ** ** History: ** 16-Nov-2006 (drivi01) ** Created. ** 19-Feb-2009 (drivi01) ** Rename Ingres Bookshelf.pdf to Ing_Bookshelf.pdf. */ UINT __stdcall ingres_start_bookshelf(MSIHANDLE ihnd) { char szPath[MAX_PATH]; char szBuf[MAX_PATH]; char acrord[MAX_PATH]; DWORD dwSize, dwType; PROCESS_INFORMATION pi; STARTUPINFO si; HKEY hKey; int rc; char subKey[MAX_PATH]; memset((char*)&pi, 0, sizeof(pi)); memset((char*)&si, 0, sizeof(si)); si.cb = sizeof(si); si.dwFlags = STARTF_USESHOWWINDOW; si.wShowWindow = SW_SHOWNORMAL; dwSize = sizeof(szPath); //MsiGetTargetPath(ihnd, "DocFolder", szPath, &dwSize); MsiGetProperty(ihnd, "INSTALLDIR", szPath, &dwSize); if (_access(szPath, 00) == 0) { rc = RegOpenKeyEx(HKEY_CLASSES_ROOT,".pdf\\OpenWithList", 0,KEY_ENUMERATE_SUB_KEYS, &hKey ); if (rc == ERROR_SUCCESS) { dwSize = sizeof(subKey); rc = RegEnumKey(hKey, 0, subKey, dwSize); RegCloseKey(hKey); if (rc == ERROR_SUCCESS) { sprintf(szBuf, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths\\%s", subKey); rc = RegOpenKeyEx(HKEY_LOCAL_MACHINE, szBuf, 0, KEY_ALL_ACCESS, &hKey ); if (rc == ERROR_SUCCESS) { dwSize = sizeof(acrord); rc = RegQueryValueEx(hKey, "Path", NULL, &dwType, acrord, &dwSize); RegCloseKey(hKey); } } if (rc == ERROR_SUCCESS) { sprintf(szBuf, "\"%s\\%s\" \"%s\\Ing_Bookshelf.pdf\"", acrord, subKey, szPath); if (CreateProcess(NULL, szBuf, NULL, NULL, FALSE, NORMAL_PRIORITY_CLASS, NULL, NULL, &si, &pi)) { /*Sleep(1000); sprintf(szBuf, "Ingres %s Post Installation", tchII_INSTALLATION); hWnd=FindWindow(NULL, szBuf); if (hWnd) BringWindowToTop(hWnd); */ CloseHandle(pi.hProcess); CloseHandle(pi.hThread); return (ERROR_SUCCESS); } else { sprintf(szBuf, "Failed to execute \"%s\\Ing_Bookshelf.pdf\" with error %d", szPath, GetLastError()); MyMessageBox(ihnd, szBuf); return (ERROR_INSTALL_FAILURE); } } } return (ERROR_INSTALL_FAILURE); } else { return (ERROR_INSTALL_FAILURE); } }
/* ** Name:ingres_set_doc_shortcuts ** ** Description: ** If the Ingres to which the documentation shortcuts currently link is ** being removed, modify the shortcuts to link to an existing Ingres. ** ** Inputs: ** hInstall Handle to the installation. ** ** Outputs: ** None. ** Returns: ** ERROR_SUCCESS ** Exceptions: ** None. ** ** Side Effects: ** None. ** ** History: ** 06-feb-2002 (penga03) ** Created. ** 12-aug-2002 (penga03) ** Made the corresponding change on Ingres installer for SIR ** 108421, two embedded specific documentation shortcuts has ** been added. */ UINT __stdcall ingres_set_doc_shortcuts(MSIHANDLE hInstall) { char szCurId[16], szId[3], szPath[MAX_PATH]; DWORD dwSize; char szBuf[MAX_PATH]; /* CustomActionData: [II_INSTALLATION] */ dwSize=sizeof(szCurId); MsiGetProperty(hInstall, "CustomActionData", szCurId, &dwSize); strcat(szCurId, "_Installation"); if(GetSharedDocInfo(szCurId, szId, szPath)) { char szFolder[MAX_PATH], szTarget[MAX_PATH]; BOOL bAllUsers; bAllUsers=CheckOutAIngresPropertyValue(szId, "IngresAllUsers"); strcpy(szFolder, "Computer Associates\\Ingres Documentation"); sprintf(szTarget, "\"%sgs.pdf\"", szPath); CreateOneShortcut(szFolder, "Getting Started", szTarget, "", "", szPath, "Getting Started", 0, bAllUsers); sprintf(szTarget, "\"%smg.pdf\"", szPath); CreateOneShortcut(szFolder, "Migration Guide", szTarget, "", "", szPath, "Migration Guide", 0, bAllUsers); sprintf(szTarget, "\"%some.pdf\"", szPath); CreateOneShortcut(szFolder, "Object Management Extension User Guide", szTarget, "", "", szPath, "Object Management Extension User Guide", 0, bAllUsers); sprintf(szTarget, "\"%scmdref.pdf\"", szPath); CreateOneShortcut(szFolder, "Command Reference Guide", szTarget, "", "", szPath, "Command Reference Guide", 0, bAllUsers); sprintf(szTarget, "\"%sdba.pdf\"", szPath); CreateOneShortcut(szFolder, "Database Administrator Guide", szTarget, "", "", szPath, "Database Administrator Guide", 0, bAllUsers); sprintf(szTarget, "\"%sdtp.pdf\"", szPath); CreateOneShortcut(szFolder, "Distributed Transaction Processing User Guide", szTarget, "", "", szPath, "Distributed Transaction Processing User Guide", 0, bAllUsers); sprintf(szTarget, "\"%sesql.pdf\"", szPath); CreateOneShortcut(szFolder, "Embedded SQL Companion Guide", szTarget, "", "", szPath, "Embedded SQL Companion Guide", 0, bAllUsers); sprintf(szTarget, "\"%siceug.pdf\"", szPath); CreateOneShortcut(szFolder, "Web Deployment Option User Guide", szTarget, "", "", szPath, "Web Deployment Option User Guide", 0, bAllUsers); sprintf(szTarget, "\"%soapi.pdf\"", szPath); CreateOneShortcut(szFolder, "OpenAPI User Guide", szTarget, "", "", szPath, "OpenAPI User Guide", 0, bAllUsers); sprintf(szTarget, "\"%sosql.pdf\"", szPath); CreateOneShortcut(szFolder, "OpenSQL Reference Guide", szTarget, "", "", szPath, "OpenSQL Reference Guide", 0, bAllUsers); sprintf(szTarget, "\"%sequel.pdf\"", szPath); CreateOneShortcut(szFolder, "Embedded QUEL Companion Guide", szTarget, "", "", szPath, "Embedded QUEL Companion Guide", 0, bAllUsers); sprintf(szTarget, "\"%squelref.pdf\"", szPath); CreateOneShortcut(szFolder, "QUEL Reference Guide", szTarget, "", "", szPath, "QUEL Reference Guide", 0, bAllUsers); sprintf(szTarget, "\"%srep.pdf\"", szPath); CreateOneShortcut(szFolder, "Replication Option User Guide", szTarget, "", "", szPath, "Replication Option User Guide", 0, bAllUsers); sprintf(szTarget, "\"%ssqlref.pdf\"", szPath); CreateOneShortcut(szFolder, "SQL Reference Guide", szTarget, "", "", szPath, "SQL Reference Guide", 0, bAllUsers); sprintf(szTarget, "\"%ssysadm.pdf\"", szPath); CreateOneShortcut(szFolder, "System Administrator Guide", szTarget, "", "", szPath, "System Administrator Guide", 0, bAllUsers); sprintf(szTarget, "\"%sstarug.pdf\"", szPath); CreateOneShortcut(szFolder, "Distributed Option User Guide", szTarget, "", "", szPath, "Distributed Option User Guide", 0, bAllUsers); sprintf(szTarget, "\"%sqrytools.pdf\"", szPath); CreateOneShortcut(szFolder, "Character-based Querying and Reporting Tools User Guide", szTarget, "", "", szPath, "Character-based Querying and Reporting Tools User Guide", 0, bAllUsers); sprintf(szTarget, "\"%sufadt.pdf\"", szPath); CreateOneShortcut(szFolder, "Forms-based Application Development Tools User Guide", szTarget, "", "", szPath, "Forms-based Application Development Tools User Guide", 0, bAllUsers); sprintf(szTarget, "\"%singnet.pdf\"", szPath); CreateOneShortcut(szFolder, "Connectivity Guide", szTarget, "", "", szPath, "Connectivity Guide", 0, bAllUsers); sprintf(szTarget, "\"%sipm.pdf\"", szPath); CreateOneShortcut(szFolder, "Interactive Performance Monitor User Guide", szTarget, "", "", szPath, "Interactive Performance Monitor User Guide", 0, bAllUsers); sprintf(szTarget, "\"%srs.pdf\"", szPath); CreateOneShortcut(szFolder, "Release Summary", szTarget, "", "", szPath, "Release Summary", 0, bAllUsers); sprintf(szBuf, "%sesqlref.pdf", szPath); if (GetFileAttributes(szBuf)!=-1) { sprintf(szTarget, "\"%sesqlref.pdf\"", szPath); CreateOneShortcut(szFolder, "Embedded Ingres SQL Reference Guide", szTarget, "", "", szPath, "Embedded Ingres SQL Reference Guide", 0, bAllUsers); sprintf(szTarget, "\"%sesysadm.pdf\"", szPath); CreateOneShortcut(szFolder, "Embedded Ingres Administrator's Guide", szTarget, "", "", szPath, "Embedded Ingres Administrator's Guide", 0, bAllUsers); } } return ERROR_SUCCESS; }
UINT __stdcall ingres_remove_odbc_files (MSIHANDLE ihnd) { char KeyName[256]; HKEY hKey; DWORD status = 0; DWORD dwSize, dwType, dwError; TCHAR tchValue[2048], tchValue2[2048]; HINSTANCE hLib; char cur_id[3], id[3], ii_system[2048]; BOOL setup_IngresODBC, setup_IngresODBCReadOnly; dwSize = sizeof(tchValue); if (MsiGetProperty( ihnd, "CustomActionData", tchValue, &dwSize ) != ERROR_SUCCESS) { return (ERROR_INSTALL_FAILURE); } strcpy(cur_id, tchValue); sprintf(KeyName, "Software\\IngresCorporation\\Ingres\\%s_Installation", tchValue); status = RegOpenKeyEx(HKEY_LOCAL_MACHINE, KeyName, 0, KEY_QUERY_VALUE | KEY_SET_VALUE, &hKey); dwType = REG_SZ; dwSize = sizeof(tchValue); if (RegQueryValueEx(hKey, "RemovedFeatures", NULL, &dwType, tchValue, &dwSize) != ERROR_SUCCESS) { /* Nothing is being removed. */ RegCloseKey(hKey); return (ERROR_SUCCESS); } if (!strstr(tchValue, "ODBC")) { /* We're not being removed. */ RegCloseKey(hKey); return (ERROR_SUCCESS); } RegCloseKey(hKey); /* ** Remove the registrations of the ODBC driver. */ hLib = LoadLibrary("ODBCCP32"); if (hLib) { PSQLREMOVEDRIVERPROC pSQLRemoveDriver = (PSQLREMOVEDRIVERPROC)GetProcAddress(hLib, "SQLRemoveDriver"); if (pSQLRemoveDriver) { char szDrvName[MAX_PATH]; /* before removing the driver figure out if it was read-only driver ** just in case if we have to rollback. */ if (IsReadOnlyDriver()) MsiSetProperty( ihnd, "INGRES_ODBC_READONLY", "1" ); dwSize=sizeof(tchValue); dwError = MsiGetProperty(ihnd, "INGRES_ODBC_READONLY", tchValue, &dwSize); sprintf(szDrvName, "Ingres %s", ING_VERS); pSQLRemoveDriver(szDrvName, TRUE, &dwSize); pSQLRemoveDriver("Ingres", TRUE, &dwSize); } } if (OtherInstallationsExist(cur_id, id) && GetInstallPath(id, ii_system)) { /* Restore ODBC driver. */ sprintf(tchValue, "%s\\ingres\\bin\\caiiod35.dll", ii_system); sprintf(tchValue2,"%s\\ingres\\bin\\caiiro35.dll", ii_system); if (GetFileAttributes(tchValue) != -1) { setup_IngresODBC=1; setup_IngresODBCReadOnly=0; } else if (GetFileAttributes(tchValue2) != -1) { setup_IngresODBC=1; setup_IngresODBCReadOnly=1; } else { setup_IngresODBC=0; setup_IngresODBCReadOnly=0; } SetEnvironmentVariable("II_SYSTEM", ii_system); SetODBCEnvironment(setup_IngresODBC, setup_IngresODBCReadOnly, 0); } return (ERROR_SUCCESS); }
UINT __stdcall ingres_set_odbc_reg_entries (MSIHANDLE ihnd) { HKEY hKey, hKey2; char KeyName[256], KeyNameODBC[256]; int status = 0; DWORD dwSize, dwDisposition, dwType; TCHAR tchValue[2048]; INSTALLSTATE iInstalled, iAction; BOOL ODBC_Installed = FALSE; BOOL bInstalled, bVer25, bVersion9X; char szCode[3], szComponent[39], szProduct[39]; ODBC_Installed = FALSE; bInstalled=bVer25=bVersion9X=FALSE; if (!MsiGetComponentState(ihnd, "Bin.70DC58B6_2D77_11D5_BDFC_00B0D0AD4485", &iInstalled, &iAction)) { if (iInstalled==INSTALLSTATE_ABSENT && iAction==INSTALLSTATE_UNKNOWN) return ERROR_SUCCESS; } else return ERROR_SUCCESS; dwSize = sizeof(tchValue); if (MsiGetProperty( ihnd, "II_INSTALLATION", tchValue, &dwSize ) != ERROR_SUCCESS) { return (ERROR_INSTALL_FAILURE); } else { strcpy(szCode, tchValue); sprintf(KeyName, "Software\\IngresCorporation\\Ingres\\%s_Installation", tchValue); status = RegCreateKeyEx(HKEY_LOCAL_MACHINE, KeyName, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey, &dwDisposition); } dwSize = sizeof(szProduct); MsiGetProperty(ihnd, "ProductCode", szProduct, &dwSize); if (!_stricmp(szCode, "II")) strcpy(szComponent, "{8FA72934-D481-405A-AD90-B7BDE7988247}"); else { int idx; idx = (toupper(szCode[0]) - 'A') * 26 + toupper(szCode[1]) - 'A'; if (idx <= 0) idx = (toupper(szCode[0]) - 'A') * 26 + toupper(szCode[1]) - '0'; sprintf(szComponent, "{8FA72934-D481-405A-%04X-%012X}", idx, idx*idx); } dwSize=sizeof(tchValue); MsiGetComponentPath(szProduct, szComponent, tchValue, &dwSize); if (tchValue[0] && iInstalled==INSTALLSTATE_LOCAL) ODBC_Installed = TRUE; if (ODBC_Installed) { /* ** Set up the InstalledFeatures registry key for possible use. */ dwType = REG_SZ; dwSize = sizeof(tchValue); if (RegQueryValueEx(hKey, "InstalledFeatures", NULL, &dwType, tchValue, &dwSize) != ERROR_SUCCESS) { strcpy(tchValue, "ODBC"); } else strcat(tchValue, ",ODBC"); status = RegSetValueEx( hKey, "InstalledFeatures", 0, REG_SZ, tchValue, strlen(tchValue) + 1 ); } if (iAction==INSTALLSTATE_ABSENT) { /* ** Set up the RemovedFeatures registry key for use later on. */ dwType = REG_SZ; dwSize = sizeof(tchValue); if (RegQueryValueEx(hKey, "RemovedFeatures", NULL, &dwType, tchValue, &dwSize) != ERROR_SUCCESS) { strcpy(tchValue, "ODBC"); } else strcat(tchValue, ",ODBC"); status = RegSetValueEx( hKey, "RemovedFeatures", 0, REG_SZ, tchValue, strlen(tchValue) + 1 ); RegCloseKey(hKey); return (status==ERROR_SUCCESS ? ERROR_SUCCESS : ERROR_INSTALL_FAILURE); } else if (ODBC_Installed || iAction!=INSTALLSTATE_LOCAL) { dwSize = sizeof(tchValue); if (!MsiGetProperty(ihnd, "INGRES_UPGRADE", tchValue, &dwSize) && strcmp(tchValue, "2")) { RegCloseKey(hKey); return (ERROR_SUCCESS); } } dwSize = sizeof(tchValue); if (status || MsiGetProperty( ihnd, "INGRES_ODBC", tchValue, &dwSize ) != ERROR_SUCCESS) { return (ERROR_INSTALL_FAILURE); } else { status = RegSetValueEx( hKey, "setup_ingresodbc", 0, REG_SZ, tchValue, strlen(tchValue) + 1 ); } dwSize = sizeof(tchValue); if (status || MsiGetProperty( ihnd, "INGRES_ODBC_READONLY", tchValue, &dwSize ) != ERROR_SUCCESS) { return (ERROR_INSTALL_FAILURE); } else { status = RegSetValueEx( hKey, "setup_ingresodbcreadonly", 0, REG_SZ, tchValue, strlen(tchValue) + 1 ); } //check if read-only odbc driver was installed by ODBC patch installer if ((!strcmp(tchValue, "") || !strcmp(tchValue, "0")) && ODBC_Installed && iAction==INSTALLSTATE_LOCAL) { sprintf(KeyNameODBC, "SOFTWARE\\ODBC\\ODBCINST.INI\\Ingres"); if (!RegOpenKeyEx(HKEY_LOCAL_MACHINE, KeyNameODBC, 0, KEY_QUERY_VALUE, &hKey2)) { /* the comment out part is a better way of doing the check but Ingres isn't ready for it ** b/c of older releases DriverReadOnly can't be trusted yet. */ /*dwSize=sizeof(tchValue); if ((status = RegQueryValueEx(hKey2, "DriverReadOnly", 0, NULL, (BYTE *)tchValue, &dwSize)) == ERROR_SUCCESS) { if (!strcmp(tchValue, "Y")) status = RegSetValueEx( hKey, "setup_ingresodbcreadonly", 0, REG_SZ, "1", strlen("1") + 1 ); } else if (status == ERROR_FILE_NOT_FOUND) {*/ dwSize=sizeof(tchValue); if (!RegQueryValueEx(hKey2, "Driver", 0, NULL, (BYTE *)tchValue, &dwSize)) { if (strstr(tchValue, "caiiro") > 0) { status = RegSetValueEx( hKey, "setup_ingresodbcreadonly", 0, REG_SZ, "1", strlen("1") + 1 ); //Update the property for future possible upgrades of the release MsiSetProperty( ihnd, "INGRES_ODBC_READONLY", "1" ); } } //} RegCloseKey(hKey2); } } strcpy(tchValue, "TRUE"); status = RegSetValueEx( hKey, "Ingres ODBC Driver", 0, REG_SZ, (CONST BYTE *)&tchValue, strlen(tchValue) + 1 ); dwType = REG_SZ; dwSize = sizeof(tchValue); if (RegQueryValueEx(hKey, "PostInstallationNeeded", NULL, &dwType, tchValue, &dwSize) != ERROR_SUCCESS) { dwSize = sizeof(tchValue); if (status || MsiGetProperty( ihnd, "INGRES_SERVICEAUTO", tchValue, &dwSize ) != ERROR_SUCCESS) { return (ERROR_INSTALL_FAILURE); } else { char szBuf[MAX_PATH+1]; sprintf(szBuf, "Ingres_Database_%s", szCode); if (CheckServiceExists(szBuf)) { if (IsServiceStartupTypeAuto(szBuf)) sprintf(tchValue, "1"); else sprintf(tchValue, "0"); status = RegSetValueEx( hKey, "serviceauto", 0, REG_SZ, tchValue, strlen(tchValue) + 1 ); } else status = RegSetValueEx( hKey, "serviceauto", 0, REG_SZ, tchValue, strlen(tchValue) + 1 ); } dwSize = sizeof(tchValue); if (status || MsiGetProperty( ihnd, "INGRES_SERVICELOGINID", tchValue, &dwSize ) != ERROR_SUCCESS) { return (ERROR_INSTALL_FAILURE); } else { status = RegSetValueEx( hKey, "serviceloginid", 0, REG_SZ, tchValue, strlen(tchValue) + 1 ); } dwSize = sizeof(tchValue); if (status || MsiGetProperty( ihnd, "INGRES_SERVICEPASSWORD", tchValue, &dwSize ) != ERROR_SUCCESS) { return (ERROR_INSTALL_FAILURE); } else { /* Clear the password from the property table. */ MsiSetProperty(ihnd, "INGRES_SERVICEPASSWORD", ""); MsiSetProperty(ihnd, "INGRES_SERVICEPASSWORD2", ""); status = RegSetValueEx( hKey, "servicepassword", 0, REG_SZ, tchValue, strlen(tchValue) + 1 ); } strcpy(tchValue, "YES"); status = RegSetValueEx( hKey, "PostInstallationNeeded", 0, REG_SZ, tchValue, strlen(tchValue) + 1 ); MsiSetProperty(ihnd, "INGRES_POSTINSTALLATIONNEEDED", "1"); dwSize = sizeof(tchValue); MsiGetProperty(ihnd, "INGRES_RSP_LOC", tchValue, &dwSize); if (tchValue[0] && strcmp(tchValue, "0")) { strcpy(tchValue, "YES"); RegSetValueEx( hKey, "SilentInstall", 0, REG_SZ, (CONST BYTE *)&tchValue, strlen(tchValue) + 1 ); } dwSize = sizeof(tchValue); MsiGetProperty(ihnd, "Installed", tchValue, &dwSize); if (tchValue[0]) bInstalled=TRUE; dwSize = sizeof(tchValue); MsiGetProperty(ihnd, "INGRES_VER25", tchValue, &dwSize); if (tchValue[0] && !strcmp(tchValue, "1")) bVer25=0; dwSize=sizeof(tchValue); MsiGetProperty(ihnd, "Version9X", tchValue, &dwSize); if (tchValue[0]) bVersion9X=TRUE; if (!bInstalled && !bVer25 && bVersion9X) { strcpy(tchValue, "YES"); RegSetValueEx( hKey, "RebootNeeded", 0, REG_SZ, (CONST BYTE *)&tchValue, strlen(tchValue) + 1 ); } } return (status == ERROR_SUCCESS ? ERROR_SUCCESS : ERROR_INSTALL_FAILURE); }
/* ** Name:ingres_rollback_star ** ** Description: ** Reverse the changes to the system made by ingres_set_star_reg_entries and ** ingres_remove_star_files. Executed only during an installation rollback. ** ** Inputs: ** hInstall Handle to the installation. ** ** Outputs: ** None. ** Returns: ** ERROR_SUCCESS The function succeeds. ** ERROR_INSTALL_FAILURE The function fails. ** Exceptions: ** None. ** ** Side Effects: ** None. ** ** History: ** 03-Aug-2001 (penga03) ** Created. */ UINT __stdcall ingres_rollback_star(MSIHANDLE hInstall) { char ii_code[3], ii_system[MAX_PATH+1], sdir[MAX_PATH+1], buf[3*(MAX_PATH+1)], Host[33]; DWORD ret; char RegKey[256], data[256]; DWORD type, size; HKEY hkRegKey; BOOL bRemoved=0; ret=sizeof(ii_code); if(MsiGetProperty(hInstall, "CustomActionData", ii_code, &ret)!=ERROR_SUCCESS) return ERROR_INSTALL_FAILURE; sprintf(RegKey, "Software\\IngresCorporation\\Ingres\\%s_Installation", ii_code); if(RegOpenKeyEx(HKEY_LOCAL_MACHINE, RegKey, 0, KEY_ALL_ACCESS, &hkRegKey)) return ERROR_SUCCESS; size=sizeof(data); *data=0; if(RegQueryValueEx(hkRegKey, "InstalledFeatures", NULL, &type, (BYTE *)data, &size)==ERROR_SUCCESS) { bRemoved=DelTok(data, "STAR"); if(*data==0) RegDeleteValue(hkRegKey, "InstalledFeatures"); else if (bRemoved) RegSetValueEx(hkRegKey, "InstalledFeatures", 0, REG_SZ, data, strlen(data)+1); } size=sizeof(data); *data=0; if(RegQueryValueEx(hkRegKey, "RemovedFeatures", NULL, &type, (BYTE *)data, &size)==ERROR_SUCCESS) { bRemoved=DelTok(data, "STAR"); if(bRemoved) { size=sizeof(ii_system); RegQueryValueEx(hkRegKey, "II_SYSTEM", NULL, &type, (BYTE *)ii_system, &size); SetEnvironmentVariable("II_SYSTEM", ii_system); GetSystemDirectory(sdir, sizeof(sdir)); sprintf(buf, "%s\\ingres\\bin;%s\\ingres\\utility;%s", ii_system, ii_system, sdir); SetEnvironmentVariable("PATH", buf); Local_PMhost(Host); sprintf(buf, "iisetres.exe ii.%s.ingstart.*.star 1", Host); Execute(buf, TRUE); } if(*data==0) RegDeleteValue(hkRegKey, "RemovedFeatures"); else if (bRemoved) RegSetValueEx(hkRegKey, "RemovedFeatures", 0, REG_SZ, data, strlen(data)+1); } size=sizeof(data); if(RegQueryValueEx(hkRegKey, "Ingres/STAR", NULL, &type, (BYTE *)data, &size)!=ERROR_SUCCESS) { RegCloseKey(hkRegKey); return ERROR_SUCCESS; } RegDeleteValue(hkRegKey, "Ingres/STAR"); RegDeleteValue(hkRegKey, "serviceauto"); RegDeleteValue(hkRegKey, "serviceloginid"); RegDeleteValue(hkRegKey, "servicepassword"); RegDeleteValue(hkRegKey, "PostInstallationNeeded"); RegDeleteValue(hkRegKey, "SilentInstall"); RegDeleteValue(hkRegKey, "RebootNeeded"); RegCloseKey(hkRegKey); return ERROR_SUCCESS; }
UINT __stdcall ingres_remove_star_files (MSIHANDLE ihnd) { char KeyName[256]; char cmd[2048]; char Host[33]; HKEY hKey; DWORD status = 0; DWORD dwSize, dwType; TCHAR tchValue[2048], tchII_SYSTEM[MAX_PATH+1]; char tchBuf[1024], tchBuf2[2048]; dwSize = sizeof(tchValue); if (MsiGetProperty( ihnd, "CustomActionData", tchValue, &dwSize ) != ERROR_SUCCESS) { return (ERROR_INSTALL_FAILURE); } sprintf(KeyName, "Software\\IngresCorporation\\Ingres\\%s_Installation", tchValue); if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, KeyName, 0, KEY_ALL_ACCESS, &hKey)) return ERROR_SUCCESS; dwType = REG_SZ; dwSize = sizeof(tchValue); if (RegQueryValueEx(hKey, "RemovedFeatures", NULL, &dwType, tchValue, &dwSize) != ERROR_SUCCESS) { /* Nothing is being removed. */ RegCloseKey(hKey); return (ERROR_SUCCESS); } if (!strstr(tchValue, "STAR")) { /* We're not being removed. */ RegCloseKey(hKey); return (ERROR_SUCCESS); } dwType = REG_SZ; dwSize = sizeof(tchValue); if (RegQueryValueEx(hKey, "II_SYSTEM", NULL, &dwType, tchValue, &dwSize) != ERROR_SUCCESS) { return (ERROR_INSTALL_FAILURE); } SetEnvironmentVariable("II_SYSTEM", tchValue); strcpy(tchII_SYSTEM, tchValue); RegCloseKey(hKey); /* ** First, let's delete all STAR databases. */ /* ** Set up our environment to execute commands. */ GetSystemDirectory(tchBuf, sizeof(tchBuf)); sprintf(tchBuf2, "%s\\ingres\\bin;%s\\ingres\\utility;%s", tchII_SYSTEM, tchII_SYSTEM, tchBuf); SetEnvironmentVariable("PATH", tchBuf2); /* ** Change the startup count to zero. */ Local_PMhost(Host); sprintf(cmd, "iisetres.exe ii.%s.ingstart.*.star 0", Host); Execute(cmd, TRUE); return (ERROR_SUCCESS); }
String getMsiProductCode() { String productGuid = kEmptyString; // Copy msi file from resources to the temp folder prepareMsiData(kEnglishLocalId); MSIHANDLE msiHandle; String path = getTmpPath() + kMsiFileName; // Open msi file UINT result = MsiOpenPackageEx(path.c_str(), MSIOPENPACKAGEFLAGS_IGNOREMACHINESTATE, &msiHandle); if (result != ERROR_SUCCESS) { return productGuid; } // Get Product code property string length DWORD length = 0; result = MsiGetProperty(msiHandle, _T("ProductCode"), _T(""), &length); if (ERROR_MORE_DATA != result) { return productGuid; } // Get Product code property // increment length for termination character Char* productCode = new Char[++length]; MsiGetProperty(msiHandle, _T("ProductCode"), productCode, &length); productGuid = productCode; delete[] productCode; // Delete msi file from temp folder, close handles MsiCloseHandle(msiHandle); DeleteFile(path.c_str()); return productGuid; }