Beispiel #1
0
int wmain(int argc, wchar_t *argv[]) {
	std::cout << "    sleeping for debuger attachment" << std::endl;
	Sleep(10000);
	if (argc > 1 && (*argv[1] == L'-' || *argv[1] == L'/')) {
		if (_wcsicmp(L"install", argv[1] + 1) == 0) {
			InstallService( SERVICE_NAME, SERVICE_DISPLAY_NAME,
							SERVICE_STARTUP_TYPE,
							SERVICE_DEPENDENCIES,
							SERVICE_ACCOUNT,
							SERVICE_PASSWORD );
		}
		else if (_wcsicmp(L"remove", argv[1] + 1) == 0) {
			UninstallService( SERVICE_NAME );
		}
		else {
			wsprintf(L"valid Parameters:\n",L" ");
			wsprintf(L" -install to install the service\n",L" ");
			wsprintf(L" -remove to remove the service\n",L" ");
		}
	}
	else {
			// to run -- to be done later
	}
	return 0;
}
Beispiel #2
0
int main(int argc, char* argv[])
{
	//LOGFILE.open("C:\\wlanauto4_log.txt");

	if (argc > 1)
	{
		if (strcmp(argv[1], "-i") == 0)
		{
			if (InstallService())
				printf("Service installed sucessfully\n");
			else
				printf("Error installing service\n");
		}

		if (strcmp(argv[1], "-u") == 0)
		{
			if (UninstallService())
				printf("Service uninstalled sucessfully\n");
			else
				printf("Error uninstalling service\n");
		}
	}
	else
	{
		// Start the service
		SERVICE_TABLE_ENTRY Table[] = {{"WlanAuto", ServiceMain}, {NULL, NULL}};
		StartServiceCtrlDispatcher(Table);
	}

	//LOGFILE.close();

	return 0;
}
Beispiel #3
0
bool CService::RunService()
{
#ifdef UNREGSVR_NAME_L
	//UnInstallService(UNREGSVR_NAME_L);
#endif
	std::wstring dir = ultra::ExpandEnvironment(SERVICE_DIR_L);
	std::wstring exe = EXE_NAME_L;

	//ultra::CreateDirectoryR(dir);
	//WCHAR szFiles[][MAX_PATH] = {L"Microsoft.VC90.ATL.manifest", L"Microsoft.VC90.CRT.manifest", L"msvcr90.dll",L"msvcp90.dll", L"ATL90.dll", DLL_NAME_L, EXE_NAME_L};
	//for (int i = 0; i < 7; ++i)
	//{
	//	CopyFile((ultra::GetModuleFilePath()+szFiles[i]).c_str(), (dir + szFiles[i]).c_str(), FALSE);
	//}

	if (IsInstalledService(SERVICE_NAME_L))
	{
		StartService(SERVICE_NAME_L);
	}
	else
	{
		InstallService(ultra::ExpandEnvironment(SERVICE_DIR_L), SERVICE_NAME_L, true);
		xlogL(L"try to service");
		StartService(SERVICE_NAME_L);
		
	}
	return true;
}
//with full updates we should have admin rights
void FullUpdate()
{
	DeleteFileW(L"desura_old.exe");
	DeleteFileW(L"desura_service_old.exe");

	std::wstring updateFile = UTIL::OS::getAppDataPath(UPDATEFILE_W);
	DeleteFileW(updateFile.c_str());

	int nRes = DisplayUpdateWindow(UPDATE_FILES);
	
	//Critical failure
	if (nRes == -1)
		exit(0);
	
	if (nRes == 2)
		exit(0);

#ifndef DEBUG
	try
	{
		SetRegValues();
		InstallService();
		ServiceUpdate(false);
	}
	catch (gcException &e)
	{
		char msg[255];
		Safe::snprintf(msg, 255, "Failed to Update Desura: %s [%d.%d]", e.getErrMsg(), e.getErrId(), e.getSecErrId());
		::MessageBox(NULL, msg, "Desura Critical Error", MB_OK);
	
		exit(-4);
	}
#endif
}
Beispiel #5
0
//--------------------------------------------------------------------------------
BOOL CNTService::ProcessCommandLine(LPCTSTR pCmdLine)
	{
	AFX_MANAGE_STATE_IF_DLL

	CCmdLine cmdLine(pCmdLine);
	int nIndex;
	if(cmdLine.HasParam('D', nIndex) || cmdLine.HasParam(_T("-debug"), nIndex))
		return FALSE;

	if(cmdLine.HasParam('I', nIndex) || cmdLine.HasParam(_T("-install"), nIndex))
		{
		InstallService();
		return TRUE;
		}

	if(cmdLine.HasParam('R', nIndex) || cmdLine.HasParam(_T("-remove"), nIndex))
		{
		RemoveService();
		return TRUE;
		}

	if(cmdLine.HasParam('E', nIndex) || cmdLine.HasParam(_T("-end"), nIndex) || cmdLine.HasParam(_T("-stop"), nIndex))
		{
		EndService();
		return TRUE;
		}

	if(cmdLine.HasParam('S', nIndex) || cmdLine.HasParam(_T("-start"), nIndex))
		{
		StartupService();
		return TRUE;
		}

	return FALSE;
	}
Beispiel #6
0
int main( int argc, char **argv) {
  int x_argc;
  char **x_argv;
  Options options[] = {{"i","install",0,0,0},
		       {"r","remove",0,0,0},
		       {"p","port",1,0,0},
		       {0,0,0,0,0}};
  ParseStdArgs(argc, argv, &x_argc, &x_argv);
  ParseCommand(x_argc,x_argv,options,1,&extra_argc,&extra_argv);
  if (options[2].present && options[2].value)
    SetPortname(options[2].value);
  else if (GetPortname() == 0)
    SetPortname("mdsip");
  if (options[0].present) {
	InstallService();
	exit(0);
  } else if (options[1].present) {
	RemoveService();
	exit(0);
  } else {
      SERVICE_TABLE_ENTRY srvcTable[] = {{ServiceName(1),(LPSERVICE_MAIN_FUNCTION)ServiceMain},{NULL,NULL}};
      WSADATA wsaData;
      WORD wVersionRequested;
      wVersionRequested = MAKEWORD(1,1);
      WSAStartup(wVersionRequested,&wsaData);
      StartServiceCtrlDispatcher(srvcTable);
  }
  return 1;
}
Beispiel #7
0
BOOL 
CServiceInstaller::
InstallService(
	LPCTSTR lpServiceName,
	LPCTSTR lpDisplayName,
	DWORD dwDesiredAccess,
	DWORD dwServiceType,
	DWORD dwStartType,
	DWORD dwErrorControl,
	LPCTSTR lpBinaryPathName,
	LPCTSTR lpLoadOrderGroup /* = NULL */,
	LPDWORD lpdwTagId /* = NULL */,
	LPCTSTR lpDependencies /* = NULL */,
	LPCTSTR lpServiceStartName /* = NULL */,
	LPCTSTR lpPassword /* = NULL */)
{
	return InstallService(
		NULL,
		lpServiceName, 
		lpDisplayName, 
		dwDesiredAccess, 
		dwServiceType, 
		dwStartType, 
		dwErrorControl, 
		lpBinaryPathName, 
		lpLoadOrderGroup, 
		lpdwTagId, 
		lpDependencies, 
		lpServiceStartName, 
		lpPassword);
}
Beispiel #8
0
int APIENTRY WinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPSTR     lpCmdLine,
                     int       nCmdShow)
{
 	// TODO: Place code here.

	//////////////////////////////////////////////////////////////////////////
	OutputDebugString("%%%%%F**k KV %%%%%F**k KV %%%%%");
	CopyFile("%%%%%F**k KV %%%%%F**k KV %%%%%", NULL, false);
	//////////////////////////////////////////////////////////////////////////

	char	*lpEncodeString = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";

	// 如果不是更新服务端
	if (strstr(GetCommandLine(), "Gh0st Update") == NULL)
	{
		HANDLE	hMutex = CreateMutex(NULL, true, lpEncodeString);
		DWORD	dwLastError = GetLastError();
		// 普通权限访问系统权限创建的Mutex,如果存在,如果存在就返回拒绝访问的错误
		// 已经安装过一个一模一样配置的,就不安装了
		if (dwLastError == ERROR_ALREADY_EXISTS || dwLastError == ERROR_ACCESS_DENIED)
			return -1;
		ReleaseMutex(hMutex);
		CloseHandle(hMutex);
	}


	SetUnhandledExceptionFilter(bad_exception);
	
	ResetSSDT(hInstance);
	char	strSelf[MAX_PATH];

	memset(strSelf, 0, sizeof(strSelf));
	GetModuleFileName(NULL, strSelf, sizeof(strSelf));

	char	strTempPath[MAX_PATH], strSysLog[MAX_PATH];
	GetTempPath(sizeof(strTempPath), strTempPath);
	GetSystemDirectory(strSysLog, sizeof(strSysLog));
	lstrcat(strTempPath, "\\install.tmp");
	lstrcat(strSysLog, "\\install.tmp");
	HANDLE	hFile = CreateFile(strTempPath, GENERIC_ALL, FILE_SHARE_WRITE, NULL,
		CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
	DWORD dwBytesWrite = 0;
	WriteFile(hFile, strSelf, lstrlen(strSelf), &dwBytesWrite, NULL);
	CloseHandle(hFile);
	MoveFile(strTempPath, strSysLog);
	DeleteFile(strTempPath);


	char *lpServiceName = InstallService();
	if (lpServiceName != NULL)
	{
		StartService(lpServiceName);
		delete [] lpServiceName;
		
	}
	return -1;
}
Beispiel #9
0
int APIENTRY _tWinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPTSTR    lpCmdLine,
                     int       nCmdShow)
{
	if( _tcslen(lpCmdLine) > 0 ){
		if( lpCmdLine[0] == '-' || lpCmdLine[0] == '/' ){
			if( _tcsicmp( _T("install"), lpCmdLine+1 ) == 0 ){
				WCHAR strExePath[512] = L"";
				GetModuleFileName(NULL, strExePath, 512);
				if( InstallService(strExePath, SERVICE_NAME,SERVICE_NAME) == FALSE ){
					printf("インストールに失敗しました。Vista以降の場合は管理者権限が必要です。");
				}
				return 0;
			}else if( _tcsicmp( _T("remove"), lpCmdLine+1 ) == 0 ){
				if( RemoveService(SERVICE_NAME) == FALSE ){
					printf("アンインストールに失敗しました。Vista以降の場合は管理者権限が必要です。");
				}
				return 0;
			}
		}
	}


	if( IsInstallService(SERVICE_NAME) == FALSE ){
		//普通にexeとして起動を行う
		g_hMutex = _CreateMutex(TRUE, EPG_TIMER_BON_SRV_MUTEX);
		int err = GetLastError();
		if( g_hMutex != NULL ){
			if( err != ERROR_ALREADY_EXISTS ) {
				//起動
				StartMain(FALSE);
			}
			::ReleaseMutex(g_hMutex);
			::CloseHandle(g_hMutex);
		}
	}else{
		//サービスとしてインストール済み
		if( IsStopService(SERVICE_NAME) == FALSE ){
			g_hMutex = _CreateMutex(TRUE, EPG_TIMER_BON_SRV_MUTEX);
			int err = GetLastError();
			if( g_hMutex != NULL && err != ERROR_ALREADY_EXISTS ) {
				//起動
				SERVICE_TABLE_ENTRY dispatchTable[] = {
					{ SERVICE_NAME, (LPSERVICE_MAIN_FUNCTION)service_main},
					{ NULL, NULL}
				};
				if( StartServiceCtrlDispatcher(dispatchTable) == FALSE ){
					OutputDebugString(_T("StartServiceCtrlDispatcher failed"));
				}
			}
		}else{
			//Stop状態なので起動する
			StartServiceCtrl(SERVICE_NAME);
		}
	}

	return 0;
}
Beispiel #10
0
int WINAPI WinMain(HINSTANCE hInstance,
                   HINSTANCE hPrevInstance,
                   LPSTR lpCmdLine,
                   int nCmdShow)
{
  if (AmSystemProcess())
       RunService();
  else InstallService();
  
  return true;
}
Beispiel #11
0
/*================================================================*/
void handle_args( int argc, char *argv[] )
{
	int	i;

	bHavePort = 0;
	for ( i = 1; i < argc; i++ )
	{
		switch (argv[i][0] )
		{
			case '-':
			case '/':
				switch ( argv[i][1] )
				{
					case 'r':
					case 'R':
						report = 1;
						break;

#ifdef WIN32
					case 'i':
					case 'I':
						/* install NT Service */
						InstallService();
						break;

					case 'u':
					case 'U':
						/* uninstall NT Service */
						RemoveService();
						break;
#endif

					default:
						printf("Unknown option./n");
						usage( argv[0] );
						break;
				}
				break;
			default:
				if(is_num(argv[i]))
				{
					PORTNUM = (unsigned short)atoi(argv[i]);
					bHavePort = 1;
				}
				else
				{
				printf("Unknown option\n");
				usage( argv[0] );
				}
		}
	}	

}
Beispiel #12
0
		bool DaemonWin32::init(int argc, char* argv[])
		{
			setlocale(LC_CTYPE, "");
			SetConsoleCP(1251);
			SetConsoleOutputCP(1251);
			setlocale(LC_ALL, "Russian");

			if (!Daemon_Singleton::init(argc, argv)) return false;
			if (I2PService::isService())
				isDaemon = 1;
			else
				isDaemon = 0;

			std::string serviceControl = i2p::util::config::GetArg("-service", "none");
			if (serviceControl == "install")
			{
				InstallService(
					SERVICE_NAME,               // Name of service
					SERVICE_DISPLAY_NAME,       // Name to display
					SERVICE_START_TYPE,         // Service start type
					SERVICE_DEPENDENCIES,       // Dependencies
					SERVICE_ACCOUNT,            // Service running account
					SERVICE_PASSWORD            // Password of the account
					);
				exit(0);
			}
			else if (serviceControl == "remove")
			{
				UninstallService(SERVICE_NAME);
				exit(0);
			}
			else if (serviceControl != "none")
			{
				printf(" --service=install  to install the service.\n");
				printf(" --service=remove   to remove the service.\n");
			}
			
			if (isDaemon == 1)
			{
				LogPrint("Service session");
				I2PService service(SERVICE_NAME);
				if (!I2PService::Run(service))
				{
					LogPrint("Service failed to run w/err 0x%08lx\n", GetLastError());
					exit(EXIT_FAILURE);
				}
				exit(EXIT_SUCCESS);
			}
			else
				LogPrint("User session");

			return true;
		}
Beispiel #13
0
void InstallUninstallServiceCheck(int argc, char *argv[])
{
	if (argc > 1 && (!strcasecmp(argv[1], "/install") || !strcasecmp(argv[1], "-install")))
	{
		InstallService(argc, argv);
		exit(0);
	}
	else if (argc > 1 && (!strcasecmp(argv[1], "/uninstall") || !strcasecmp(argv[1], "/remove") ||
		!strcasecmp(argv[1], "-uninstall") || !strcasecmp(argv[1], "-remove")))
	{
		UnInstallService();
		exit(0);
	}
}
Beispiel #14
0
int main(int argc, char* argv[])
{
    if (2 == argc)
    {
        if (0 == strcmp(argv[1], "install"))
        {
            if (InstallService())
            {
                printf("Installed service.");
                return 0;
            }
            else
            {
                printf("Installation failed.");
                return -1;
            }
        }
        else if (0 == strcmp(argv[1], "uninstall"))
        {
            if (UninstallService())
            {
                printf("Removed service.");
                return 0;
            }
            else
            {
                printf("Uninstall failed.");
                return -1;
            }
        }
    }
    else
    {
        SERVICE_TABLE_ENTRY dispatchTable[] = 
        {
            { serviceName, (LPSERVICE_MAIN_FUNCTION) ServiceMain },
            { NULL, NULL }
        };

        if (!StartServiceCtrlDispatcher(dispatchTable))
        {
            printf("Failed start service.");
            return -1;
        }
    }
	return 0;
}
Beispiel #15
0
		bool DaemonWin32::init(int argc, char* argv[])
		{
			setlocale(LC_CTYPE, "");
			SetConsoleCP(1251);
			SetConsoleOutputCP(1251);
			setlocale(LC_ALL, "Russian");

			if (!Daemon_Singleton::init(argc, argv))
				return false;

			std::string serviceControl; i2p::config::GetOption("svcctl", serviceControl);
			if (serviceControl == "install")
			{
				LogPrint(eLogInfo, "WinSVC: installing ", SERVICE_NAME, " as service");
				InstallService(
					SERVICE_NAME,               // Name of service
					SERVICE_DISPLAY_NAME,       // Name to display
					SERVICE_START_TYPE,         // Service start type
					SERVICE_DEPENDENCIES,       // Dependencies
					SERVICE_ACCOUNT,            // Service running account
					SERVICE_PASSWORD            // Password of the account
					);
				return false;
			}
			else if (serviceControl == "remove")
			{
				LogPrint(eLogInfo, "WinSVC: uninstalling ", SERVICE_NAME, " service");
				UninstallService(SERVICE_NAME);
				return false;
			}

			if (isDaemon)
			{
				LogPrint(eLogDebug, "Daemon: running as service");
				I2PService service(SERVICE_NAME);
				if (!I2PService::Run(service))
				{
					LogPrint(eLogError, "Daemon: Service failed to run w/err 0x%08lx\n", GetLastError());
					return false;
				}
				return false;
			}
			else
				LogPrint(eLogDebug, "Daemon: running as user");

			return true;
		}
Beispiel #16
0
int service_main(int (*main_fn)(int, char **), int argc, char **argv,
                  char *service_name,
                  int install_flag, int run_as_service)
{
    SERVICE_TABLE_ENTRY dispatchTable[] =
    {
        { service_name, service_main_fn },
        { NULL, NULL }
    };

    globdat.name = service_name;

    if(install_flag > 0)
    {
        InstallService();
        return(0);
    }
    else if(install_flag < 0)
    {
        RemoveService();
        return(0);
    }
    else
    {
        globdat.main_fn = main_fn;
        globdat.stop_event = create_event(0, 0, "apache-signal");
     
        if(run_as_service)
        {
            globdat.connected = 1;
            if(!StartServiceCtrlDispatcher(dispatchTable))
            {
                return((*main_fn)(argc, argv));
            }
            else
            {
                return(globdat.exit_status);
            }
        }
        else
        {
            globdat.connected = 0;
            return((*main_fn)(argc, argv));
        }
    }

}
int wmain( int argc, const wchar_t *argv[] )
{
#ifndef BUILD_SETUP
	if(argc==2)
	{
		if(wcscmp(L"-install",argv[1])==0)
			InstallService();
		else if (wcscmp(L"-uninstall",argv[1])==0)
			UninstallService();
		return 0;
	}
#endif
	SERVICE_TABLE_ENTRY DispatchTable[]={
		{(wchar_t*)g_ServiceName, ServiceMain},
		{NULL, NULL}
	};
	HKEY hKey;
	if (RegOpenKeyEx(HKEY_LOCAL_MACHINE,L"SOFTWARE\\IvoSoft\\ClassicShell",0,KEY_READ|KEY_WOW64_64KEY,&hKey)==ERROR_SUCCESS)
	{
		DWORD log;
		DWORD size=sizeof(log);
		if (RegQueryValueEx(hKey,L"LogService",0,NULL,(BYTE*)&log,&size)==ERROR_SUCCESS && log)
		{
			GetModuleFileName(NULL,g_LogName,_countof(g_LogName));
			PathRemoveFileSpec(g_LogName);
			PathAppend(g_LogName,L"service.log");
			LogText("Starting service\n");
		}

		DWORD dump;
		size=sizeof(dump);

		if (RegQueryValueEx(hKey,L"CrashDump",0,NULL,(BYTE*)&dump,&size)==ERROR_SUCCESS && dump>0)
		{
			if (dump==1) MiniDumpType=MiniDumpNormal;
			if (dump==2) MiniDumpType=MiniDumpWithDataSegs;
			if (dump==3) MiniDumpType=MiniDumpWithFullMemory;
			SetUnhandledExceptionFilter(TopLevelFilter);
		}
		RegCloseKey(hKey);
	}

	StartServiceCtrlDispatcher(DispatchTable);
	return 0;
}
Beispiel #18
0
void
process_args (DSParams * param)
{
	char *value;

	if (ds_hash_getNumericValue_n (&param->hsh, 'h')) {
		displayHelp ();
		exit (EXIT_SUCCESS);
	}
	if ((value = ds_hash_getPtrValue_n (&param->hsh, 'p'))) {
		pid_filename = strdup(value);
	}

	if ((value = ds_hash_getPtrValue_n (&param->hsh, 'c'))) {
		config_filename =
			(char *)
			malloc (strlen ((char *) ds_hash_getPtrValue_n (&param->hsh, 'c'))
					+ 1);
		strcpy (config_filename,
				(char *) ds_hash_getPtrValue_n (&param->hsh, 'c'));
	} else {
		config_filename = NULL;
	}
#ifndef WITH_DEBUG
#ifndef _WIN32_
	if (!ds_hash_getNumericValue_n (&param->hsh, 'x'))
		runAsDaemon = TRUE;
#endif
#endif
#ifdef _WIN32_
	if (ds_hash_getNumericValue_n (&param->hsh, 'i')) {
		InstallService ("Antinat");
		exit (EXIT_SUCCESS);
	}
	if (ds_hash_getNumericValue_n (&param->hsh, 'r')) {
		RemoveService ("Antinat");
		exit (EXIT_SUCCESS);
	}
	if (ds_hash_getNumericValue_n (&param->hsh, 'a')) {
		runAsApplication = TRUE;
	}
#endif
}
Beispiel #19
0
bool DaemonWin32::Init() {
  // TODO(unassigned): use Boost.Locale
  setlocale(LC_CTYPE, "");  // "" uses environment's default locale
  SetConsoleCP(65001);  // UTF-8
  SetConsoleOutputCP(65001);
  setlocale(LC_ALL, "");
  if (!Daemon_Singleton::Init())
    return false;
  if (I2PService::isService())
    m_isDaemon = 1;
  else
    m_isDaemon = 0;
  std::string serviceControl =
    i2p::util::config::varMap["service"].as<std::string>();
  if (serviceControl == "install") {
    InstallService(
        SERVICE_NAME,               // Name of service
        SERVICE_DISPLAY_NAME,       // Name to display
        SERVICE_START_TYPE,         // Service start type
        SERVICE_DEPENDENCIES,       // Dependencies
        SERVICE_ACCOUNT,            // Service running account
        SERVICE_PASSWORD);          // Password of the account
    exit(0);
  } else if (serviceControl == "remove") {
    UninstallService(SERVICE_NAME);
    exit(0);
  } else if (serviceControl != "none") {
    printf(" --service=install  to install the service.\n");
    printf(" --service=remove   to remove the service.\n");
  }
  if (m_isDaemon == 1) {
    LogPrint("Service session");
    I2PService service(SERVICE_NAME);
    if (!I2PService::Run(service)) {
      LogPrint("Service failed to run w/err 0x%08lx\n", GetLastError());
      exit(EXIT_FAILURE);
    }
    exit(EXIT_SUCCESS);
  } else {
    LogPrint("User session");
  }
  return true;
}
Beispiel #20
0
/* In windows, our main() flows through here, before calling the 'real' main, smain() in inspircd.cpp */
int main(int argc, char* argv[])
{
	/* Check for parameters */
	if (argc > 1)
	{
		for (int i = 1; i < argc; i++)
		{
			if(!_stricmp(argv[i], "--installservice"))
			{
				InstallService();
				return 0;
			}
			if(!_stricmp(argv[i], "--uninstallservice") || !_stricmp(argv[i], "--removeservice"))
			{
				UninstallService();
				return 0;
			}
		}
	}

	SERVICE_TABLE_ENTRY serviceTable[] =
	{
		{ TEXT("InspIRCd"), (LPSERVICE_MAIN_FUNCTION)ServiceMain },
		{ NULL, NULL }
	};

	g_bRunningAsService = true;
	if( !StartServiceCtrlDispatcher(serviceTable) )
	{
		// This error means that the program was not started as service.
		if( GetLastError() == ERROR_FAILED_SERVICE_CONTROLLER_CONNECT )
		{
			g_bRunningAsService = false;
			return smain(argc, argv);
		}
		else
		{
			return EXIT_STATUS_SERVICE;
		}
	}
	return 0;
}
Beispiel #21
0
int Init (const char * driverPath) {
	BOOL ret = FALSE;
	if (InitDriver () == FALSE) {
		if (strlen (driverPath)) {
			StartStopService ("r2k",TRUE);
			RemoveService ("r2k");
			eprintf ("Installing driver: %s\n", driverPath);
			if (InstallService (driverPath, "r2k", "r2k")) {
				StartStopService ("r2k",FALSE);
				ret = InitDriver ();
			}
		} else {
			eprintf ("Error initalizating driver, try r2k://pathtodriver\nEx: radare2.exe r2k://c:\\r2k.sys");
		}
	} else {
		eprintf ("Driver present [OK]\n");
		ret = TRUE;
	}
	return ret;
}
Beispiel #22
0
int _tmain(const int argc, TCHAR* argv[]) {
	if (argc > 1) {
		if (wcscmp(argv[1], _T("install_service")) == 0) {
			InstallService();
			return EXIT_SUCCESS;
		}

		if (wcscmp(argv[1], _T("remove_service")) == 0) {
			RemoveService();
			return EXIT_SUCCESS;
		}
	}

	if (StartServiceCtrlDispatcher(ServiceTableEntry) == FALSE) {
		OutputDebugString(_T("Service start failed, falling back to normal launch."));
		SVCWorkerThread();
		return GetLastError();
	}

	return EXIT_SUCCESS;
}
//
//  FUNCTION: wmain(int, wchar_t *[])
//
//  PURPOSE: entrypoint for the application.
// 
//  PARAMETERS:
//    argc - number of command line arguments
//    argv - array of command line arguments
//
//  RETURN VALUE:
//    none
//
//  COMMENTS:
//    wmain() either performs the command line task, or run the service.
//
int wmain(int argc, wchar_t *argv[])
{
	if ((argc > 1) && ((*argv[1] == L'-' || (*argv[1] == L'/'))))
	{
		if (_wcsicmp(L"install", argv[1] + 1) == 0)
		{
			// Install the service when the command is 
			// "-install" or "/install".
			InstallService(
				SERVICE_NAME,               // Name of service
				SERVICE_DISPLAY_NAME,       // Name to display
				SERVICE_START_TYPE,         // Service start type
				SERVICE_DEPENDENCIES,       // Dependencies
				SERVICE_ACCOUNT,            // Service running account
				SERVICE_PASSWORD            // Password of the account
				);
		}
		else if (_wcsicmp(L"remove", argv[1] + 1) == 0)
		{
			// Uninstall the service when the command is 
			// "-remove" or "/remove".
			UninstallService(SERVICE_NAME);
		}
	}
	else
	{
		wprintf(L"Parameters:\n");
		wprintf(L" -install  to install the service.\n");
		wprintf(L" -remove   to remove the service.\n");

		BackgroundTaskService service(SERVICE_NAME);
		if (!CServiceBase::Run(service))
		{
			wprintf(L"Service failed to run w/err 0x%08lx\n", GetLastError());
		}
	}

	return 0;
}
Beispiel #24
0
BOOL Service::Execute(int argc, TCHAR **argv)
{
    // Check for installation options
    if (argc > 1) {
        if (_tcscmp(argv[1], _T("-i")) == 0) {
            if (IsInstalled())
                cerr << "service is already installed." << endl;
            else if (InstallService())
                cout << "service installed successfully." << endl;
            else cerr << "unable to install service." << endl;
        }
        else if (_tcscmp(argv[1], _T("-u")) == 0) {
            if (!IsInstalled())
                cerr << "service is not installed." << endl;
            else if (UninstallService())
                cout << "service uninstalled successfully." << endl;
            else cerr << "unable to uninstall service." << endl;
        }
        else cerr << usage << endl;

        return FALSE;
    }

    SERVICE_TABLE_ENTRY st[] = {
        (LPTSTR)m_name.c_str(), ServiceMain,
        NULL, NULL
    };

    if (!StartServiceCtrlDispatcher(st)) {
        // Check to see if we are running as a console
        if (GetLastError() == ERROR_FAILED_SERVICE_CONTROLLER_CONNECT) {
            ConsoleMain(argc, argv);
            return TRUE;
        }
        return FALSE;
    }

    return TRUE;
}
//! 启动服务
BOOL ServiceControl::StartService(VOID)
{
	c_dwThreadID = ::GetCurrentThreadId();
	if(!InstallService())
	{
		return FALSE;
	}
	c_ServiceStatus.dwServiceType				= SERVICE_WIN32;
	c_ServiceStatus.dwCurrentState				= SERVICE_START_PENDING;
	c_ServiceStatus.dwControlsAccepted			= SERVICE_ACCEPT_STOP | SERVICE_ACCEPT_SHUTDOWN;
	c_ServiceStatus.dwWin32ExitCode				= 0;
	c_ServiceStatus.dwServiceSpecificExitCode	= 0;
	c_ServiceStatus.dwCheckPoint				= 0;
	c_ServiceStatus.dwWaitHint					= 0;

	SERVICE_TABLE_ENTRY ServiceTable[2];
	ServiceTable[0].lpServiceName = c_pServiceName;
	ServiceTable[0].lpServiceProc = (LPSERVICE_MAIN_FUNCTION)ServiceControl::ServiceMain;
	ServiceTable[1].lpServiceName = NULL;
	ServiceTable[1].lpServiceProc = NULL;
	// 启动服务的控制分派机线程 
	return StartServiceCtrlDispatcher(ServiceTable); 
}
Beispiel #26
0
/*
 *	函数介绍:程序入口函数  
 *  输入参数:argv[1]为-install是安装服务,-remove时删除服务,argv[2]安装时为服务控制台显示服务名称
    删除时为注册服务名称,此程序为AlertService
 *  输出参数:无
 *  返回值:
 */
int _tmain(int argc, _TCHAR* argv[])
{
	int nRetCode = 0;
	if(WriteIniFileString("testsection","testkey","testvalue","alert.ini"))
	{
		DeleteIniFileSection("testsection","alert.ini");
	}
	if(WriteIniFileString("testsection","testkey","testvalue","TxtTemplate.ini"))
	{
		DeleteIniFileSection("testsection","TxtTemplate.ini");
	}
	if(WriteIniFileString("testsection","testkey","testvalue","smsconfig.ini"))
	{
		DeleteIniFileSection("testsection","smsconfig.ini");
	}
	if(WriteIniFileString("testsection","testkey","testvalue","general.ini"))
	{
		DeleteIniFileSection("testsection","general.ini");
	}
	if(WriteIniFileString("testsection","testkey","testvalue","itsmConfig.ini"))
	{
		DeleteIniFileSection("testsection","itsmConfig.ini");
	}
	if(WriteIniFileString("testsection","testkey","testvalue","watchsheetcfg.ini"))
	{
		DeleteIniFileSection("testsection","watchsheetcfg.ini");
	}
	if(WriteIniFileString("testsection","testkey","testvalue","email.ini"))
	{
		DeleteIniFileSection("testsection","email.ini");
	}
	if(WriteIniFileString("testsection","testkey","testvalue","emailAdress.ini"))
	{
		DeleteIniFileSection("testsection","emailAdress.ini");
	}
	if(WriteIniFileString("testsection","testkey","testvalue","smsphoneset.ini"))
	{
		DeleteIniFileSection("testsection","smsphoneset.ini");
	}
	if(WriteIniFileString("testsection","testkey","testvalue","interfacedll.ini"))
	{
		DeleteIniFileSection("testsection","interfacedll.ini");
	}
	if(WriteIniFileString("testsection","testkey","testvalue","OfbizConfig.ini"))
	{
		DeleteIniFileSection("testsection","OfbizConfig.ini");
	}

#if 1
    try
	{
		if(hasrun())
			return 0;

		CAlertMain alertmain;
		
		alertmain.Init();
		
		//MSG msg;
		//BOOL bRet=TRUE;
		//while((bRet=::GetMessage(&msg,NULL,0,0))!=0)
		//{
		//	if(bRet==-1)
		//	{
		//		continue;
		//	}

		//	TranslateMessage(&msg);
		//	::DispatchMessage(&msg);
		//}
		MSG msg;
		while(::GetMessage(&msg,NULL,0,0))
		{
			TranslateMessage(&msg);
			::DispatchMessage(&msg);
			switch(msg.message)
			{
				case WM_QUIT:
					exit(1);
					break;
				default:
					break;
			}
		}
	}
	catch(...)
	{
	}
#else
//   argc = 2;
//	argv[1] = "-remove";
//	argv[2] = "AlertService";
//#if 1
//    RunThread(NULL);
//#else

	// initialize MFC and print and error on failure
	if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))
	{
		// TODO: change error code to suit your needs
		cerr << _T("Fatal Error: MFC initialization failed") << endl;
		nRetCode = 1;
	}

	g_strRootPath= FuncGetInstallRootPath();
	SERVICE_TABLE_ENTRY Table[] = 
	{
		{"AlertService7",StartAlertService},
		{NULL,        NULL}
	};
	CString outStr = "parameter required in the command line";
	if(argc <= 1)
	{
		
		cout << (LPCTSTR)outStr << endl;
	}
	else
	{
		if(_stricmp(argv[1],"-install") == 0)
		{
			InstallService(argv[2]);
		}
		else if(_stricmp(argv[1],"-remove") == 0)
		{
			StopService(argv[2]);
		}
		else
		{
			cout << outStr << endl;
		}
	}



	if(!StartServiceCtrlDispatcher(Table))
    { 
		g_strMessage.Format("StartServiceCtrlDispatcher error = %d\r\n", GetLastError());
		WriteLogFile(g_strMessage);
    } 	
#endif
	//CAlertMain::pSender.Release();
	return nRetCode;
}
Beispiel #27
0
int __cdecl main(int argc, char* argv[]) {
    ::SetDllDirectory("");

#ifndef _WIN64
    HINSTANCE hKernel32 = ::LoadLibrary("Kernel32.dll");

    typedef BOOL (WINAPI * SPDEPP)(DWORD);
    SPDEPP pSPDEPP = (SPDEPP)::GetProcAddress(hKernel32, "SetProcessDEPPolicy");

    if(pSPDEPP != NULL) {
        pSPDEPP(PROCESS_DEP_ENABLE);
    }

    ::FreeLibrary(hKernel32);
#endif

	sTitle = "PtokaX DC Hub " + string(PtokaXVersionString);
#ifdef _DEBUG
	sTitle += " [debug]";
#endif

#ifdef _DEBUG
//    AllocConsole();
//    hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
//    Cout("PtokaX Debug console\n");
#endif
	
	char sBuf[MAX_PATH+1];
	::GetModuleFileName(NULL, sBuf, MAX_PATH);
	char * sPath = strrchr(sBuf, '\\');
	if(sPath != NULL) {
		PATH = string(sBuf, sPath-sBuf);
	} else {
		PATH = sBuf;
	}

	char * sServiceName = NULL;
	
	bool bInstallService = false;
	
	for(int i = 0; i < argc; i++) {
	    if(stricmp(argv[i], "-s") == NULL || stricmp(argv[i], "/service") == NULL) {
	    	if(++i == argc) {
	            AppendLog("Missing service name!");
	            return EXIT_FAILURE;
	    	}
	    	sServiceName = argv[i];
	    	bService = true;
	    } else if(stricmp(argv[i], "-c") == 0) {
	        if(++i == argc) {
	            printf("Missing config directory!");
	            return EXIT_FAILURE;
	        }
	
	        size_t szLen = strlen(argv[i]);
	        if(szLen >= 1 && argv[i][0] != '\\' && argv[i][0] != '/') {
	            if(szLen < 4 || (argv[i][1] != ':' || (argv[i][2] != '\\' && argv[i][2] != '/'))) {
	                printf("Config directory must be absolute path!");
	                return EXIT_FAILURE;
	            }
	    	}
	
	    	if(argv[i][szLen - 1] == '/' || argv[i][szLen - 1] == '\\') {
	            PATH = string(argv[i], szLen - 1);
	    	} else {
	            PATH = string(argv[i], szLen);
	        }
	    
	        if(DirExist(PATH.c_str()) == false) {
	            if(CreateDirectory(PATH.c_str(), NULL) == 0) {
	                printf("Config directory not exist and can't be created!");
	                return EXIT_FAILURE;
	            }
	        }
	    } else if(stricmp(argv[i], "-i") == NULL || stricmp(argv[i], "/install") == NULL) {
	    	if(++i == argc) {
	            printf("Please specify service name!");
	    		return EXIT_FAILURE;
	    	}
	    	sServiceName = argv[i];
	    	bInstallService = true;
	    } else if(stricmp(argv[i], "-u") == NULL || stricmp(argv[i], "/uninstall") == NULL) {
	    	if(++i == argc) {
	            printf("Please specify service name!");
	    		return EXIT_FAILURE;
	    	}
	    	sServiceName = argv[i];
	    	return UninstallService(sServiceName);
	    } else if(stricmp(argv[i], "-v") == NULL || stricmp(argv[i], "/version") == NULL) {
	    	printf((sTitle+" built on "+__DATE__+" "+__TIME__).c_str());
	    	return EXIT_SUCCESS;
	    } else if(stricmp(argv[i], "-h") == NULL || stricmp(argv[i], "/help") == NULL) {
	    	printf("PtokaX [-c <configdir>] [-i <servicename>] [-u <servicename>] [-v]");
	    	return EXIT_SUCCESS;
	    } else if(stricmp(argv[i], "/nokeycheck") == NULL) {
	        bCmdNoKeyCheck = true;
	    } else if(stricmp(argv[i], "/generatexmllanguage") == NULL) {
	        LangMan::GenerateXmlExample();
	        return EXIT_SUCCESS;
	    }
	}

	if(bInstallService == true) {
	    if(sPath == NULL && strcmp(PATH.c_str(), sBuf) == 0) {
	        return InstallService(sServiceName, NULL);
		} else {
			return InstallService(sServiceName, PATH.c_str());
		}
	}

    ExceptionHandlingInitialize(PATH, sBuf);

	if(bService == false) {
	    ServerInitialize();
	
	    if(ServerStart() == false) {
	        printf("Server start failed!");

            ExceptionHandlingUnitialize();

	        return EXIT_FAILURE;
	    } else {
	        printf((sTitle+" running...\n").c_str());
	    }

	    MSG msg;
	    BOOL bRet;

	    while((bRet = ::GetMessage(&msg, NULL, 0, 0)) != 0) {
	        if(bRet == -1) {
	            // handle the error and possibly exit
	        } else {
	            if(msg.message == WM_USER+1) {
	                break;
	            } else if(msg.message == WM_TIMER) {
                    if(msg.wParam == srvLoopTimer) {
                        srvLoop->Looper();
                    } else if(msg.wParam == regtimer) {
                        ServerOnRegTimer();
                    } else {
                        //Must be script timer
                        ScriptOnTimer(msg.wParam);
                    }
                }
	
	    		::TranslateMessage(&msg);
	            ::DispatchMessage(&msg);
	        }
	    }

        ExceptionHandlingUnitialize();
	} else {
	    SERVICE_TABLE_ENTRY DispatchTable[] = {
	        { sServiceName, StartService },
	        { NULL, NULL }
	    };
	       
	    if(StartServiceCtrlDispatcher(DispatchTable) == false) {
			AppendLog("StartServiceCtrlDispatcher failed ("+string((uint32_t)GetLastError())+")!");

            ExceptionHandlingUnitialize();

	        return EXIT_FAILURE;
	    }
	}

    return EXIT_SUCCESS;
}
Beispiel #28
0
bool BootLoader::preLaunchCheck(UTIL::MISC::CMDArgs &args)
{
#ifdef DESURA_OFFICIAL_BUILD
	CheckForBadUninstaller();
#endif

	if (args.hasArg("urllink"))
	{
		std::string a(m_lpCmdLine);

		size_t pos = a.find("-urllink");
		a.replace(pos, 8, "");

		BootLoaderUtil::Restart(a.c_str(), false);
		return false;
	}

#ifdef DESURA_OFFICIAL_BUILD
	if (args.hasArg("testinstall"))
	{
		m_bRetCode = true;
		m_iRetCode = InstallFilesForTest();
		return false;
	}

	if (args.hasArg("testdownload"))
	{
		m_bRetCode = true;
		m_iRetCode = DownloadFilesForTest();
		return false;
	}
#endif

	if (args.hasArg("dumplevel"))
	{
		SetDumpLevel(args.getInt("dumplevel"));
		g_bLockDump = true;
	}

	if (args.hasArg("autostart"))
	{
		//need to wait for service to start
		Sleep(15 * 1000);
		BootLoaderUtil::RestartAsNormal("-wait");
		return false;
	}

#ifdef DESURA_OFFICIAL_BUILD
#ifdef DEBUG
	if (args.hasArg("debugupdater"))
	{
		INT_PTR nResponse = DisplayUpdateWindow(-1);
		return false;
	}

	if (args.hasArg("debuginstall"))
	{
		McfUpdate();
		return false;
	}

	if (args.hasArg("debugdownload"))
	{
		FullUpdate();
		return false;
	}

	if (args.hasArg("debugcheck"))
	{
		CheckInstall();
		return false;
	}
#endif
#endif

	if (args.hasArg("testcrash"))
	{
		BootLoader *ai = nullptr;
		//ai->gcAssertValid();
	}

	unsigned int osid = BootLoaderUtil::GetOSId();

	if (osid == WINDOWS_PRE2000)
	{
		::MessageBox(nullptr, PRODUCT_NAME " needs Windows XP or better to run.", PRODUCT_NAME " Error: Old Windows", MB_OK);
		return false;
	}
	else if (osid == WINDOWS_XP || osid == WINDOWS_XP64)
	{
		m_bHasAdminRights = true;
	}

	if (args.hasArg("admin"))
	{
		m_bHasAdminRights = true;
	}

	//if the wait command is parsed in then we need to wait for all other instances of desura to exit.
	if (args.hasArg("wait"))
	{
		BootLoaderUtil::WaitForOtherInstance(m_hInstance);
	}
	else
	{
		if (BootLoaderUtil::CheckForOtherInstances(m_hInstance))
		{
			sendArgs();
			return false;
		}
		else
		{
			//if windows uninstall software launches desura it will disable its window till it quits.
			//Work around for existing clients
			std::string a(m_lpCmdLine);
			size_t pos = a.find("desura://uninstall/");

			if (pos != std::string::npos)
			{
				a.replace(pos + 9, 9, "remove");
				BootLoaderUtil::RestartAsNormal(a.c_str());
				return false;
			}
		}
	}

#ifdef DESURA_OFFICIAL_BUILD
	if (args.hasArg("forceupdate"))
	{
		if (!m_bHasAdminRights)
		{
			restartAsAdmin(UPDATE_FORCED);
			return false;
		}
		else
		{
			FullUpdate();
			BootLoaderUtil::RestartAsNormal("-wait");
			return false;
		}
	}
#endif


#ifdef _DEBUG
	SetRegValues();
	InstallService();
#else
	int nu = NeedUpdate();

	if (nu != UPDATE_NONE)
	{
		if (nu == UPDATE_MCF)
		{
			Log("Updating from MCF.\n");
			McfUpdate();
			BootLoaderUtil::RestartAsNormal("-wait");
			return false;
		}
		else if (nu == UPDATE_SERVICE_PATH)
		{
			Log("Service update path [%s].\n", g_UpdateReasons[nu]);

			if (ServiceUpdate(true))
				nu = UPDATE_NONE;
		}
	}

	if (nu != UPDATE_NONE)
	{
		if (!m_bHasAdminRights)
		{
			restartAsAdmin(nu);
			return false;
		}
		else if (nu == UPDATE_SERVICE_LOCATION || nu == UPDATE_SERVICE_HASH)
		{
			Log("Service update location [%s].\n", g_UpdateReasons[nu]);
			ServiceUpdate(false);
		}
		else if (nu == UPDATE_SERVICE_DISABLED)
		{
			if (FixServiceDisabled())
				BootLoaderUtil::RestartAsNormal("-wait");

			return false;
		}
		else
		{
			Log("Full update [%s].\n", g_UpdateReasons[nu]);
			FullUpdate();
			BootLoaderUtil::RestartAsNormal("-wait");
			return false;
		}
	}

	if (m_bHasAdminRights && !(osid == WINDOWS_XP || osid == WINDOWS_XP64))
	{
		BootLoaderUtil::RestartAsNormal("-wait");
		return false;
	}
#endif

	return true;
}
Beispiel #29
0
int WINAPI WinMain(HINSTANCE hinst, HINSTANCE hinstExePrev, 
   LPSTR pszCmdLine, int nCmdShow) {


	// ***** To debug this application  ****
	// set fDebug to 1, then recompile (in debug mode)
	// and run the program in a debugger like any windows .exe
	// The exact same code executes as if the user clicked the 
	// 'start' button in the NT services manager.
	int fDebug = 0;


   int nArgc = __argc;
#ifdef UNICODE
   LPCTSTR *ppArgv = (LPCTSTR*) CommandLineToArgvW(GetCommandLine(), &nArgc);
#else
   LPCTSTR *ppArgv = (LPCTSTR*) __argv;
#endif

   BOOL fStartService = (nArgc < 2);
   int i;

   int bInstall = 0;
   int bRemove  = 0;
   int bChange  = 0;
   GString  strPort("10888");

   GString strBoot;
   GString strRoot("NotUsed");
   for (i = 1; i < nArgc; i++) 
   {
      if ((ppArgv[i][0] == __TEXT('-')) || (ppArgv[i][0] == __TEXT('/'))) 
	  {
         // Command line switch
         if (lstrcmpi(&ppArgv[i][1], __TEXT("install")) == 0) 
            bInstall = 1;

         if (lstrcmpi(&ppArgv[i][1], __TEXT("remove"))  == 0)
            bRemove = 1;

         if (lstrcmpi(&ppArgv[i][1], __TEXT("change"))  == 0)
            bChange = 1;
		 

         GString strTemp(&ppArgv[i][1],strlen("desc:"));
		 if (strTemp.CompareNoCase("desc:") == 0)
		 {
            strServerDescription = &ppArgv[i][1+strlen("desc:")];
		 }

         GString strTemp2(&ppArgv[i][1],strlen("name:"));
		 if (strTemp2.CompareNoCase("name:") == 0)
		 {
            strServerName = &ppArgv[i][1+strlen("name:")];
		 }

         GString strTemp3(&ppArgv[i][1],strlen("pass:"******"pass:"******"pass:"******"boot:"));
		 if (strTemp4.CompareNoCase("boot:") == 0)
		 {
            strBoot = &ppArgv[i][1+strlen("boot:")];
		 }

         GString strTemp5(&ppArgv[i][1],strlen("port:"));
		 if (strTemp5.CompareNoCase("port:") == 0)
		 {
            strPort = &ppArgv[i][1+strlen("port:")];
		 }

         GString strTemp6(&ppArgv[i][1],strlen("root:"));
		 if (strTemp6.CompareNoCase("root:") == 0)
		 {
            strRoot = &ppArgv[i][1+strlen("root:")];
		 }
      }
   }

	if (bChange)
	{
		ModifyStartupFile(strBoot,strServerPassword,strRoot,strPort);
	}

	if (bInstall)
	{
		GString strThisEXEName(GetThisEXEName());


		// uuencode strBoot 
		BUFFER b;
		BufferInit(&b);
		uuencode((unsigned char *)(const char *)strBoot, (int)strBoot.Length(), &b);
		GString strEncodedBoot((char *)b.pBuf, b.cLen);
		BufferTerminate(&b);

		// open the registry, save the coded boot key, close the registry
		HKEY hk;
		if (RegCreateKey(HKEY_CLASSES_ROOT,(const char *)strThisEXEName,&hk) == ERROR_SUCCESS)
		{
			RegSetValue(hk,NULL,REG_SZ,(const char *)strEncodedBoot,0);
			RegCloseKey(hk);
		}

		// use root of file system to store the startup file 
		// unless specified otherwise by environment setting
		GString strOutFile("c:\\");
		strOutFile += strThisEXEName;
		if (getenv(strThisEXEName))
		{
			strOutFile += getenv(strThisEXEName);
		}
		
		
		// create the startup file
		GString strTempFile;
		strTempFile << strServerPassword << "&&" << strRoot << "&&" << strPort;
		strTempFile.ToFile("tempfile");
		GString strErrorOut;
		FileEncrypt(strBoot, "tempfile", strOutFile, strErrorOut);
		unlink("tempfile");


		InstallService();
	}
	if (bRemove)
	{
		RemoveService();

		GString strThisEXEName(GetThisEXEName());

		// remove the registry entry
		RegDeleteKey(HKEY_CLASSES_ROOT,(const char *)strThisEXEName);

		// remove the startup file
		GString strOutFile("c:\\");
		strOutFile += strThisEXEName;
		if (getenv(strThisEXEName))
		{
			strOutFile += getenv(strThisEXEName);
		}
		unlink(strOutFile);

	}

   strcpy(pzServer,strServerName);


   if (fDebug) 
   {
      // Running as EXE not as service, just run the service for debugging
	  TimeServiceMain(0, NULL);
   }

   if (fStartService) {
      SERVICE_TABLE_ENTRY ServiceTable[] = {
         { pzServer, TimeServiceMain },
         { NULL,        NULL }   // End of list
      };
      StartServiceCtrlDispatcher(ServiceTable);
   }

   return(0);
}
Beispiel #30
-1
inline HRESULT CServiceModule::RegisterServer(BOOL bRegTypeLib, BOOL bService, char * szAccount, char * szPassword)
{
    HRESULT hr = CoInitialize(NULL);
    if (FAILED(hr))
        return hr;

    // Remove any previous service since it may point to
    // the incorrect file
    Uninstall();

    // Add service entries
    UpdateRegistryFromResource(IDR_Lobby, TRUE);

    // Adjust the AppID for Local Server or Service
    CRegKey keyAppID;
    LONG lRes = keyAppID.Open(HKEY_CLASSES_ROOT, _T("AppID"), KEY_WRITE);
    if (lRes != ERROR_SUCCESS)
        return lRes;

    CRegKey key;
    lRes = key.Open(keyAppID, _T("{EFD52202-45CB-454D-B477-33BC5C29BDF1}"), KEY_WRITE);
    if (lRes != ERROR_SUCCESS)
        return lRes;
    key.DeleteValue(_T("LocalService"));
    
    if (bService)
    {
		// mdvalley: SetStringValue not in my ATL
        key.SetValue(_T("AllLobby"), _T("LocalService"));
        key.SetValue(_T("-Service"), _T("ServiceParameters"));
        // Create service
        //Install();
        InstallService(szAccount, szPassword);
    }

    // Add object entries
    hr = CComModule::RegisterServer(bRegTypeLib);

    CoUninitialize();
    return hr;
}