예제 #1
0
void
ArchDaemonWindows::uninstallDaemon()
{
	// remove legacy services if installed.
	if (isDaemonInstalled(LEGACY_SERVER_DAEMON_NAME)) {
		uninstallDaemon(LEGACY_SERVER_DAEMON_NAME);
	}
	if (isDaemonInstalled(LEGACY_CLIENT_DAEMON_NAME)) {
		uninstallDaemon(LEGACY_CLIENT_DAEMON_NAME);
	}

	// remove new service if installed.
	if (isDaemonInstalled(DEFAULT_DAEMON_NAME)) {
		uninstallDaemon(DEFAULT_DAEMON_NAME);
	}
}
예제 #2
0
void
ArchDaemonWindows::uninstallDaemon()
{
    // remove service if installed.
    if (isDaemonInstalled(DEFAULT_DAEMON_NAME)) {
        uninstallDaemon(DEFAULT_DAEMON_NAME);
    }
}
예제 #3
0
void
ArchDaemonWindows::installDaemon(const char* name,
				const char* description,
				const char* pathname,
				const char* commandLine,
				const char* dependencies)
{
	// open service manager
	SC_HANDLE mgr = OpenSCManager(NULL, NULL, GENERIC_WRITE);
	if (mgr == NULL) {
		// can't open service manager
		throw XArchDaemonInstallFailed(new XArchEvalWindows);
	}

	// create the service
	SC_HANDLE service = CreateService(
		mgr,
		name,
		name,
		0,
		SERVICE_WIN32_OWN_PROCESS | SERVICE_INTERACTIVE_PROCESS,
		SERVICE_AUTO_START,
		SERVICE_ERROR_NORMAL,
		pathname,
		NULL,
		NULL,
		dependencies,
		NULL,
		NULL);

	if (service == NULL) {
		// can't create service
		DWORD err = GetLastError();
		if (err != ERROR_SERVICE_EXISTS) {
			CloseServiceHandle(mgr);
			throw XArchDaemonInstallFailed(new XArchEvalWindows(err));
		}
	}
	else {
		// done with service (but only try to close if not null)
		CloseServiceHandle(service);
	}

	// done with manager
	CloseServiceHandle(mgr);

	// open the registry key for this service
	HKEY key = openNTServicesKey();
	key      = ArchMiscWindows::addKey(key, name);
	if (key == NULL) {
		// can't open key
		DWORD err = GetLastError();
		try {
			uninstallDaemon(name);
		}
		catch (...) {
			// ignore
		}
		throw XArchDaemonInstallFailed(new XArchEvalWindows(err));
	}

	// set the description
	ArchMiscWindows::setValue(key, _T("Description"), description);

	// set command line
	key = ArchMiscWindows::addKey(key, _T("Parameters"));
	if (key == NULL) {
		// can't open key
		DWORD err = GetLastError();
		ArchMiscWindows::closeKey(key);
		try {
			uninstallDaemon(name);
		}
		catch (...) {
			// ignore
		}
		throw XArchDaemonInstallFailed(new XArchEvalWindows(err));
	}
	ArchMiscWindows::setValue(key, _T("CommandLine"), commandLine);

	// done with registry
	ArchMiscWindows::closeKey(key);
}
void
CArchDaemonWindows::installDaemon(const char* name,
				const char* description,
				const char* pathname,
				const char* commandLine,
				const char* dependencies,
				bool allUsers)
{
	// if not for all users then use the user's autostart registry.
	// key.  if windows 95 family then use windows 95 services key.
	if (!allUsers || CArchMiscWindows::isWindows95Family()) {
		// open registry
		HKEY key = (allUsers && CArchMiscWindows::isWindows95Family()) ?
							open95ServicesKey() : openUserStartupKey();
		if (key == NULL) {
			// can't open key
			throw XArchDaemonInstallFailed(new XArchEvalWindows);
		}

		// construct entry
		std::string value;
		value += "\"";
		value += pathname;
		value += "\" ";
		value += commandLine;

		// install entry
		CArchMiscWindows::setValue(key, name, value);

		// clean up
		CArchMiscWindows::closeKey(key);
	}

	// windows NT family services
	else {
		// open service manager
		SC_HANDLE mgr = OpenSCManager(NULL, NULL, GENERIC_WRITE);
		if (mgr == NULL) {
			// can't open service manager
			throw XArchDaemonInstallFailed(new XArchEvalWindows);
		}

		// create the service
		SC_HANDLE service = CreateService(mgr,
								name,
								name,
								0,
								SERVICE_WIN32_OWN_PROCESS |
									SERVICE_INTERACTIVE_PROCESS,
								SERVICE_AUTO_START,
								SERVICE_ERROR_NORMAL,
								pathname,
								NULL,
								NULL,
								dependencies,
								NULL,
								NULL);
		if (service == NULL) {
			// can't create service
			// FIXME -- handle ERROR_SERVICE_EXISTS
			DWORD err = GetLastError();
			CloseServiceHandle(mgr);
			throw XArchDaemonInstallFailed(new XArchEvalWindows(err));
		}

		// done with service and manager
		CloseServiceHandle(service);
		CloseServiceHandle(mgr);

		// open the registry key for this service
		HKEY key = openNTServicesKey();
		key      = CArchMiscWindows::openKey(key, name);
		if (key == NULL) {
			// can't open key
			DWORD err = GetLastError();
			try {
				uninstallDaemon(name, allUsers);
			}
			catch (...) {
				// ignore
			}
			throw XArchDaemonInstallFailed(new XArchEvalWindows(err));
		}

		// set the description
		CArchMiscWindows::setValue(key, _T("Description"), description);

		// set command line
		key = CArchMiscWindows::openKey(key, _T("Parameters"));
		if (key == NULL) {
			// can't open key
			DWORD err = GetLastError();
			CArchMiscWindows::closeKey(key);
			try {
				uninstallDaemon(name, allUsers);
			}
			catch (...) {
				// ignore
			}
			throw XArchDaemonInstallFailed(new XArchEvalWindows(err));
		}
		CArchMiscWindows::setValue(key, _T("CommandLine"), commandLine);

		// done with registry
		CArchMiscWindows::closeKey(key);
	}
}