Example #1
0
int NeedUpdate()
{
#ifdef DESURA_OFFICIAL_BUILD
	int res = NeedUpdateNonGpl();
	
	if (res != UPDATE_NONE)
		return res;
#endif

	return IsServiceInstalled();
}
Example #2
0
HRESULT InstallService()
{
	TSAUTO();
	if(IsServiceInstalled()) {
		UninstallService();
	}
	wchar_t szPath[MAX_PATH];
    if(!GetModuleFileName(g_hModule, szPath, MAX_PATH)) {
		return HRESULT_FROM_WIN32(::GetLastError());
    }
	HRESULT hr = CreateGreenShieldService(szPath);
	return hr;
}
Example #3
0
IsInstalled(HWND hwndParent, int string_size, 
            TCHAR *variables, stack_t **stacktop, void *extra)
{
  TCHAR tmp[MAX_PATH] = { L'\0' };
  WCHAR serviceName[MAX_PATH] = { '\0' };
  popstring(stacktop, tmp, MAX_PATH);

#if !defined(UNICODE)
    MultiByteToWideChar(CP_ACP, 0, tmp, -1, serviceName, MAX_PATH);
#else
    wcscpy(serviceName, tmp);
#endif

  BOOL serviceInstalled;
  if (!IsServiceInstalled(serviceName, serviceInstalled)) {
    pushstring(stacktop, TEXT("-1"), 3);
  } else {
    pushstring(stacktop, serviceInstalled ? TEXT("1") : TEXT("0"), 2);
  }
}
Example #4
0
int StartReplicServer (int hdl,  LPREPLICSERVERDATAMIN lpReplicServerDta )
{
	const LPCTSTR lpszIngresServiceName = _T("Ingres_Database_%s");
	const LPCTSTR lpszReplicServiceTempl = _T("Ingres_Replicator_%s_%d");
	int ires = RES_SUCCESS;
	TCHAR  tchszCommandLine[200];
	TCHAR* tchszCurLine;
	CString strVName = lpReplicServerDta->RunNode;
	CString msg;

#if !defined (MAINWIN)
	CString strLoc = LIBMON_getLocalHostName();
	if ( strVName.CompareNoCase(strLoc) == 0)
	{
		CString strReplicServiceName;
		CString strIngresServiceName;
		CString strII = INGRESII_QueryInstallationID(FALSE);

		if( strII.IsEmpty() )
		{
			AfxMessageBox (IDS_E_INSTALLATION_NOT_FOUND);
			return RES_ERR;
		}
		strReplicServiceName.Format(lpszReplicServiceTempl, (LPCTSTR)strII, lpReplicServerDta->serverno);
		strIngresServiceName.Format(lpszIngresServiceName,  (LPCTSTR)strII);

		if (!IsServiceInstalled ((LPCTSTR)strReplicServiceName)) 
		{
			// search max server no on local (run) node
			RESOURCEDATAMIN  ResDtaMin;
			REPLICSERVERDATAMIN ReplicSvrDta;
			int i,iservermax=0;
			LPUCHAR vnodeName = (LPUCHAR)GetVirtNodeName ( hdl );
			FillResStructFromDB(&ResDtaMin, lpReplicServerDta->ParentDataBaseName);

			/* 23-Dec-98 :  fixed "error system 3" when exiting the product, in the case       */
			/* VDBA detected that the replicator services were not installed, and proposed     */
			/* to install them automatically.                                                  */
			/* implementation: Replaced GetFirstMonInfo-GetNextMonInfo loop                    */
			/* with DBAGetFirstObject-DBAGetNextObject loop.                                   */
			/* this avoids using the cache for getting the list of servers                     */
			/* (for calculating the argument to be passed to "repinst"), because of a          */
			/* restriction of the cache for repl.servers: cache entries are attached to a node,*/
			/* but for repl.servers, the given entry needs to be connected to other nodes.     */
			/* A special management is implemented for "Monitor windows" attached cache        */
			/* entries, but in the current case, there isn't a monitor window open on the      */
			/* used node (which can be different from the open Monitor Window from which       */
			/* this stuff has been called.                                                     */

			int ires =DBAGetFirstObject (
				(LPUCHAR)vnodeName,
				OT_MON_REPLIC_SERVER,
				1,
				(LPUCHAR *)&ResDtaMin,
				TRUE,
				(LPUCHAR)&ReplicSvrDta,
				NULL,NULL);
			while (ires==RES_SUCCESS) 
			{
				if (! lstrcmpi((LPCTSTR)lpReplicServerDta->RunNode, (LPCTSTR)ReplicSvrDta.RunNode)) {
					if (ReplicSvrDta.serverno>iservermax)
						iservermax=ReplicSvrDta.serverno;
				}
				ires=DBAGetNextObject((LPUCHAR)&ReplicSvrDta,NULL,NULL);
			}
			if ( iservermax == 0 ) {
				//_T("Cannot retrieve number of server(s) - Install services Aborted."
				AfxMessageBox(IDS_E_NB_SERVERS);
				return RES_ERR;
			}
			//"The Ingres Replicator %d service is not installed.\n"
			//"Do you want to invoke 'repinst %d' in the background, "
			//"in order to install all Replicator services required by your replication scheme?"
			msg.Format(IDS_F_SERVICE_NOT_INSTALL,lpReplicServerDta->serverno,iservermax);
			int iansw;
			if (GVvista())
			{
				CMessageBox imb(NULL, msg);
				iansw=imb.DoModal();
			}
			else
				iansw = AfxMessageBox (msg, MB_YESNO|MB_ICONQUESTION);
			if (iansw == IDNO)
				return RES_ERR;
			CString Cmd;
			Cmd.Format(_T("repinst %d"),iservermax);
			if (LIBMON_Mysystem((LPTSTR)(LPCTSTR)Cmd)<0) {
				AfxMessageBox (IDS_E_REPINST_UTIL);//"Failure in invoking the repinst utility"
				return RES_ERR;
			}
			if (!IsServiceInstalled ((LPCTSTR)strReplicServiceName)) {
				AfxMessageBox (IDS_E_REPINST_INSTALL);//"The service has not been installed properly by the repinst utility"
				return RES_ERR;
			}
			//"DBA passwords are required for all services that have been created\n"
			//"Do you want to enter them now?\n"
			//"(If not, you will need to use the Control Panel Services option.)\n"
			//"(Some other settings for these services can only be changed through the control panel.)
			if (GVvista())
			{
				CString str;
				str.Format(IDS_I_PASSWORD_REQUIRED);
				CMessageBox imb(NULL, str);
				iansw = imb.DoModal();	
			}
			else
				iansw = AfxMessageBox (IDS_I_PASSWORD_REQUIRED, MB_YESNO|MB_ICONQUESTION);
			if (iansw == IDNO)
				return RES_ERR;
			// ask for user/password
			CaServiceConfig ServiceParms;
			if (!FillServiceConfig  (ServiceParms))
				return RES_ERR;
			BOOL bOK=TRUE;
			for (i=1;i<=iservermax;i++) {
				strReplicServiceName.Format(lpszReplicServiceTempl, (LPCTSTR)strII, i);
				if (GVvista())
				{
				     CString Cmd;
				     Cmd.Format(_T("repinst config %d -username:%s -password:%s"), iservermax, 
						ServiceParms.m_strAccount, ServiceParms.m_strPassword);
				     if (LIBMON_Mysystem((LPTSTR)(LPCTSTR)Cmd)<0)
				     {
				     	//"Failure in user/password setup for the 'Ingres Replicator %d' service"
					msg.Format(IDS_E_USER_PASSWORD_NB,i);
					AfxMessageBox (msg);
					bOK=FALSE;
				     }
				}
				else
				if (!SetServicePassword ((LPCTSTR) strReplicServiceName, ServiceParms)) {
					//"Failure in user/password setup for the 'Ingres Replicator %d' service"
					msg.Format(IDS_E_USER_PASSWORD_NB,i);
					AfxMessageBox (msg);
					bOK=FALSE;
				}
			}
			if (!bOK)
				return RES_ERR;
			if (!IsServiceRunning(strIngresServiceName)) {
				//"Ingres is currently not started as a service.\n"
				//"You must close all connections in VDBA (or Exit VDBA), "
				//"then stop Ingres, and restart it as a Service if you want "
				//"to start a replicator server on the local installation.\n"
				//"You must also make sure that the user/password for the Ingres service is correct.\n"
				//"Do you want to apply the user/password that you just entered for the replicator services?"
				iansw = AfxMessageBox (IDS_I_INGRES_NOT_STARTED, MB_YESNO|MB_ICONQUESTION);
				if (iansw == IDYES) {
					if (GVvista())
					{
					     CString Cmd;
					     Cmd.Format(_T("repinst config %d -username:%s -password:%s"), iservermax, 
							ServiceParms.m_strAccount, ServiceParms.m_strPassword);
					     if (LIBMON_Mysystem((LPTSTR)(LPCTSTR)Cmd)<0)
					     {
						//"Failure in user/password setup for the 'Ingres Replicator %d' service"
						msg.Format(IDS_E_USER_PASSWORD_NB,i);
						AfxMessageBox (msg);
						bOK=FALSE;
					     }
					}
					else
					if (!SetServicePassword ((LPCTSTR) strReplicServiceName, ServiceParms)) {
						//"Failure in user/password setup for the 'Ingres Replicator %d' service"
						msg.Format(IDS_E_USER_PASSWORD_NB,i);
						AfxMessageBox (msg);
						bOK=FALSE;
					}
				}
				return RES_ERR;
			}
		}
		if (!IsServiceRunning(strIngresServiceName)) {
			//"Ingres is currently not started as a service.\n"
			//"You must close all connections in VDBA (or Exit VDBA), "
			//"then stop Ingres, and restart it as a Service if you want "
			//"to start a replicator server on the local installation.\n"
			//"You must also make sure that the user/password for the Ingres service is correct.");
			AfxMessageBox (IDS_E_INGRES_NOT_STARTED);
			return RES_ERR;
		}
	}
#endif // MAINWIN

	// Verify if vnode name exist before start the remote command.
	VerifyAndUpdateVnodeName (&strVName);
	if (strVName.IsEmpty())
		return RES_ERR;

	_stprintf(tchszCommandLine, _T("ddstart %d"), lpReplicServerDta->serverno);

	if (!LIBMON_ExecRmcmdInBackground((TCHAR *)lpReplicServerDta->RunNode, tchszCommandLine, _T("")))
		return RES_ERR;

	// check for error (output line starting with a '*' character )
	ires=RES_SUCCESS;
	tchszCurLine=LIBMON_GetFirstTraceLine();
	while (tchszCurLine) {
		if (tchszCurLine[0]==_T('*'))
			CMnext(tchszCurLine);
		if (_tcslen(tchszCurLine)) {
			CString Msg;
			/* "Error from RMCMD server on '%s' :\n%s" */
			Msg.Format(IDS_E_ERROR_RMCMD, (LPCTSTR)strVName, tchszCurLine);
			AfxMessageBox(Msg, MB_ICONEXCLAMATION | MB_OK | MB_TASKMODAL);
			ires=RES_ERR;
		}
		tchszCurLine = LIBMON_GetNextSignificantTraceLine();
	}

	return ires;
}
Example #5
0
// Процедура на първия диалог (първия раздел)
BOOL CALLBACK TabHandler1(HWND Window, UINT Message, WPARAM wParam, LPARAM lParam)
{
	static HWND hComboBox;
	const char *aServiceTypes[] = {"SERVICE_AUTO_START", "SERVICE_BOOT_START",
									"SERVICE_DEMAND_START", "SERVICE_DISABLED",
									"SERVICE_SYSTEM_START"};
	static SC_HANDLE hSCManager;
	char szFile[260];
	
	switch(Message)
	{
		case WM_INITDIALOG:
		{
			int i;
			
			// Инициализиране на комбо поле от съответния ресурс
			hComboBox = GetDlgItem(Window, IDC_COMBO_TYPE);
			for(i = 0; i < 5; i++) {
				SendMessage(hComboBox, CB_ADDSTRING, 0, (LPARAM)aServiceTypes[i]);
			}
			// Селектиране на третия елемент от комбо-списъкъ
			SendMessage(hComboBox, CB_SETCURSEL, 2, 0);
			// Изкарване дръжка към SCM базата
			hSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
			if (hSCManager == INVALID_HANDLE_VALUE) {
				MessageBox(Window, GetErrorText(GetLastError()), "FileHide", MB_ICONERROR);
				break;
			}
		}
		break;

		case WM_COMMAND:
		{
			switch(LOWORD(wParam)) {
				case IDC_DRIVER_NAME_SELECT:
				{
					OPENFILENAME openFileDialog = {0};
					char szExtendedFileName[260];
					
					openFileDialog.lStructSize = sizeof(openFileDialog);
					openFileDialog.hwndOwner = GetParent(Window);
					openFileDialog.lpstrFilter = "Драйвер(*.sys)\0*.SYS\0";
					openFileDialog.nFilterIndex = 0;
					openFileDialog.lpstrFileTitle = NULL;
					openFileDialog.nMaxFileTitle = 0;
					openFileDialog.lpstrInitialDir = NULL;
					openFileDialog.lpstrFile = szFile;
					openFileDialog.lpstrFile[0] = '\0';
					openFileDialog.nMaxFile = sizeof(szFile);
					openFileDialog.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;
					// отваране на диалог за избор на *.sys файл
					if (GetOpenFileName(&openFileDialog)) {
						// Пътечката се променя с разширена дължина
						// т.е. с представка \\?\, защото драйвера няма да работи с
						// тази програма ако се намира в друга партиция (пример в D:\)
						sprintf(szExtendedFileName,"\\\\?\\%s",szFile);
						SetDlgItemText(Window, IDC_DRIVER_PATHNAME, szExtendedFileName);
						// Изваждане на името на драйвера от цялата пътечка, без разширението (.sys)
						_splitpath(szFile, NULL, NULL, DriverName, NULL);
						if (IsServiceInstalled(hSCManager, DriverName))
							SetDlgItemText(Window, IDC_STATIC_STATUS, "Installed");
						if (IsServiceRunning(Window, hSCManager, DriverName))
							SetDlgItemText(Window, IDC_STATIC_STATUS, "Installed And Running");
					}
				}
				break;
				
				case IDC_BUT_INST:
				{
					DWORD startType = 0;
					
					GetDlgItemText(Window, IDC_DRIVER_PATHNAME, szFile, 260);
					// Изваждане на името на драйвера от цялата пътечка, без разширението (.sys)
					_splitpath(szFile, NULL, NULL, DriverName, NULL);
					if (!strlen(DriverName)) {
						MessageBox(Window, "Полето за драйвера е празно", "FileHide", MB_ICONERROR);
						break;
					}
					// Промяна на startType в избраната стойност.
					// Препоръчва се SERVICE_DEMAND_START
					switch (SendMessage(hComboBox, CB_GETCURSEL, 0, 0)) {
						case 0: startType = SERVICE_AUTO_START; break;
						case 1: startType = SERVICE_BOOT_START; break;
						case 2: startType = SERVICE_DEMAND_START; break;
						case 3: startType = SERVICE_DISABLED; break;
						case 4: startType = SERVICE_SYSTEM_START; break;
					}
					// InstallServiceEx се намира в services.h
					if (InstallServiceEx(Window, hSCManager, DriverName, startType, szFile))
						SetDlgItemText(Window, IDC_STATIC_STATUS, "Installed");
				}
				break;
				
				case IDC_BUT_UNINST:
				{
					GetDlgItemText(Window, IDC_DRIVER_PATHNAME, szFile, 260);
					_splitpath(szFile, NULL, NULL, DriverName, NULL);
					if (!strlen(DriverName)) {
						MessageBox(Window, "Полето за драйвера е празно", "FileHide", MB_ICONERROR);
						break;
					}
					if (DeleteServiceEx(Window, hSCManager, DriverName))
						SetDlgItemText(Window, IDC_STATIC_STATUS, "Uninstalled");
					ZeroMemory(DriverName, sizeof(DriverName));
				}
				break;
				
				case IDC_BUT_RUN:
				{
					GetDlgItemText(Window, IDC_DRIVER_PATHNAME, szFile, 260);
					_splitpath(szFile, NULL, NULL, DriverName, NULL);
					if (!strlen(DriverName)) {
						MessageBox(Window, "Полето за драйвера е празно", "FileHide", MB_ICONERROR);
						break;
					}
					if (StartServiceEx(Window, hSCManager, DriverName))
						SetDlgItemText(Window, IDC_STATIC_STATUS, "Installed And Running");
				}
				break;
				
				case IDC_BUT_STOP:
				{
					GetDlgItemText(Window, IDC_DRIVER_PATHNAME, szFile, 260);
					_splitpath(szFile, NULL, NULL, DriverName, NULL);
					if (!strlen(DriverName)) {
						MessageBox(Window, "Полето за драйвера е празно", "FileHide", MB_ICONERROR);
						break;
					}
					if (StopServiceEx(Window, hSCManager, DriverName))
						SetDlgItemText(Window, IDC_STATIC_STATUS, "Installed");
					ZeroMemory(DriverName, sizeof(DriverName));
				}
				break;
			}
		}
		break;
		
		case WM_CLOSE:
		{
			CloseServiceHandle(hSCManager);
		}
		break;

		default:
			return FALSE;
	}
	return TRUE;
}
 bool WsGateService::ParseSpecialArgs(int argc, char **argv){
     if (argc < 2) {
         return false;
     }
     bool installed = false;
     try {
         installed = IsServiceInstalled();
     } catch (const tracing::runtime_error &e) {
         cerr << e.what() << endl;
         return true;
     }
     if (0 == strcmp(argv[1], "--query")) {
         // Report version of installed service
         cout << "The service is " << (installed ? "currently" : "not")
             << " installed." << endl;
         return true;
     }
     if (0 == strcmp(argv[1], "--start")) {
         // Start the service
         try {
             Start();
         } catch (const tracing::runtime_error &e) {
             cerr << "Failed to start " << m_sServiceName << endl;
             cerr << e.what() << endl;
         }
         return true;
     }
     if (0 == strcmp(argv[1], "--stop")) {
         // Start the service
         try {
             Stop();
         } catch (const tracing::runtime_error &e) {
             cerr << "Failed to stop " << m_sServiceName << endl;
             cerr << e.what() << endl;
         }
         return true;
     }
     if (0 == strcmp(argv[1], "--install")) {
         // Install the service
         if (installed) {
             cout << m_sServiceName << " is already installed." << endl;
         } else {
             try {
                 InstallService();
                 cout << m_sServiceName << " installed." << endl;
             } catch (const tracing::runtime_error &e) {
                 cerr << "Failed to install " << m_sServiceName << endl;
                 cerr << e.what() << endl;
             }
         }
         return true;
     }
     if (0 == strcmp(argv[1], "--remove")) {
         // Remove the service
         if (!installed) {
             cout << m_sServiceName << " is not installed." << endl;
         } else {
             try {
                 UninstallService();
                 cout << m_sServiceName << " removed." << endl;
             } catch (const tracing::runtime_error &e) {
                 cerr << "Failed to remove " << m_sServiceName << endl;
                 cerr << e.what() << endl;
             }
         }
         return true;
     }
     return false;
 }
Example #7
0
HRESULT SetupInstallService()
{
	TSAUTO();
	wchar_t currentDllPath[MAX_PATH];
    if(!GetModuleFileName(g_hModule, currentDllPath, MAX_PATH)) {
		return HRESULT_FROM_WIN32(::GetLastError());
    }

	wchar_t serviceDllPath[MAX_PATH];
	if(!GetAllUsersPublicPath(serviceDllPath, MAX_PATH)) {
		TSERROR4CXX("Failed to get public path.");
		return false;
	}

	std::size_t pathLength = std::wcslen(serviceDllPath);
	if(pathLength == 0 || pathLength + 1 == sizeof(serviceDllPath) / sizeof(serviceDllPath[0])) {
		return false;
	}
	if(serviceDllPath[pathLength - 1] != '\\') {
		serviceDllPath[pathLength++] = '\\';
	}

	// ADClean\\addin\\CleanSvc.dll
	const wchar_t* addinSuffix = L"ADClean\\addin\\CleanSvc.dll";
	std::size_t addinSuffixLength = std::wcslen(addinSuffix);

	if(pathLength + addinSuffixLength + 1 > sizeof(serviceDllPath) / sizeof(serviceDllPath[0])) {
		return false;
	}
	std::copy(addinSuffix, addinSuffix + addinSuffixLength + 1, serviceDllPath + pathLength);

	if(IsServiceInstalled()) {
		if(::PathFileExists(serviceDllPath)) {
			// 版本比较
			DWORD old_v1, old_v2, old_v3, old_v4;
			DWORD new_v1, new_v2, new_v3, new_v4;
			if(!GetFileVersionNumber(serviceDllPath, old_v1, old_v2, old_v3, old_v4)
				|| !GetFileVersionNumber(currentDllPath, new_v1, new_v2, new_v3, new_v4)) {
				TSERROR4CXX("Failed to get file version number.");
				if(!GetFileVersionNumber(serviceDllPath, old_v1, old_v2, old_v3, old_v4)) {
					TSINFO4CXX(serviceDllPath);
				}
				else {
					TSINFO4CXX(currentDllPath);
				}
				return false;
			}
			if(old_v1 > new_v1 || old_v2 > new_v2 || old_v3 > new_v3 || old_v4 > new_v4) {
				TSERROR4CXX("The old service dll is later than this.");
				return false;
			}
		}
		UninstallService();
	}

	if(!CopyFilesToPublicFolder()) {
		TSERROR4CXX("CopyFilesToPublicFolder return false.");
		return E_FAIL;
	}

	return CreateGreenShieldService(serviceDllPath);
}