// Returns TRUE if it found an arg it recognised, FALSE if not
// Note: processing some arguments causes output to stdout to be generated.
BOOL CNTService::ParseStandardArgs(int argc, TCHAR* argv[])
{
    // See if we have any command line args we recognise
    if (argc <= 1) return FALSE;

    if (_wcsicmp(argv[1], _T("-v")) == 0) {

        // Spit out version info
        printf("%s Version %d.%d\n",
               m_szServiceName, m_iMajorVersion, m_iMinorVersion);
        printf("The service is %s installed\n",
               IsInstalled() ? "currently" : "not");
        return TRUE; // say we processed the argument

    } else if (_wcsicmp(argv[1], _T("-i")) == 0) {

        // Request to install.
        if (IsInstalled()) {
            printf("%s is already installed\n", m_szServiceName);
        } else {
            // Try and install the copy that's running
            if (Install()) {
                printf("%s installed\n", m_szServiceName);
            } else {
                printf("%s failed to install. Error %d\n", m_szServiceName, GetLastError());
            }
        }
        return TRUE; // say we processed the argument

    } else if (_wcsicmp(argv[1], _T("-u")) == 0) {

        // Request to uninstall.
        if (!IsInstalled()) {
            printf("%s is not installed\n", m_szServiceName);
        } else {
            // Try and remove the copy that's installed
            if (Uninstall()) {
                // Get the executable file path
                char szFilePath[_MAX_PATH];
                ::GetModuleFileNameA(NULL, szFilePath, sizeof(szFilePath));
                printf("%s removed. (You must delete the file (%s) yourself.)\n",
                       m_szServiceName, szFilePath);
            } else {
                printf("Could not remove %s. Error %d\n", m_szServiceName, GetLastError());
            }
        }
        return TRUE; // say we processed the argument
    
    }
         
    // Don't recognise the args
    return FALSE;
}
bool CWinRobotJNIAdapter::CheckInstall(HINSTANCE hin)
{
	bool bIsInstall = false;
	if(!IsInstalled(hin,bIsInstall))
	{
		return false;
	}
	if(bIsInstall){
		return true;
	}
	//step2.register service WinRobotHost.exe
	TCHAR curpath[MAX_PATH];
	GetModuleFileName( hin, curpath, MAX_PATH );
	PathRemoveFileSpec(curpath);
	ATL::CString file;
	file += "";
	file += curpath;
	file += "\\";
#if _WIN64
	file += "WinRobotHostx64.exe";
#else
	file += "WinRobotHostx86.exe";
#endif
	SHELLEXECUTEINFO sei = {0};
	sei.cbSize = sizeof(SHELLEXECUTEINFO);
	sei.fMask = SEE_MASK_NOCLOSEPROCESS | SEE_MASK_FLAG_NO_UI;
	sei.lpFile = file;
	if(!HasServiceInstallRights())
	{
		sei.lpVerb = _T("runas");
	}
	sei.lpDirectory = NULL;
	sei.lpParameters = _T("-I");
	sei.hwnd = GetForegroundWindow();
	if(!ShellExecuteEx(&sei))
	{
		return false;
	}

	WaitForSingleObject(sei.hProcess,-1);

	if(sei.hProcess)CloseHandle(sei.hProcess);
	
	if(!IsInstalled(hin,bIsInstall)){
		return false;
	}
	return bIsInstall;

}
Example #3
0
//*********************************************************
//Functiopn:			Install
//Description:			安装服务函数
//Calls:
//Called By:
//Table Accessed:
//Table Updated:
//Input:
//Output:
//Return:
//Others:
//History:
//			<author>niying <time>2006-8-10		<version>		<desc>
//*********************************************************
BOOL Install()
{
	if (IsInstalled())
		return TRUE;

	//打开服务控制管理器
	SC_HANDLE hSCM = ::OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
	if (hSCM == NULL)
	{
		MessageBox(NULL, _T("Couldn't open service manager"), szServiceName, MB_OK);
		return FALSE;
	}

	// Get the executable file path
	TCHAR szFilePath[MAX_PATH];
	::GetModuleFileName(NULL, szFilePath, MAX_PATH);

	//创建服务,并设置依赖关系
	SC_HANDLE hService = ::CreateService(
		hSCM, szServiceName, szServiceName,
		SERVICE_ALL_ACCESS, SERVICE_WIN32_OWN_PROCESS,
		SERVICE_DEMAND_START, SERVICE_ERROR_NORMAL,
		szFilePath, NULL, NULL, szDepend, NULL, NULL);

	if (hService == NULL)
	{
		::CloseServiceHandle(hSCM);
		MessageBox(NULL, _T("Couldn't create service"), szServiceName, MB_OK);
		return FALSE;
	}

	::CloseServiceHandle(hService);
	::CloseServiceHandle(hSCM);
	return TRUE;
}
Example #4
0
//*********************************************************
//Functiopn:			Uninstall
//Description:			删除服务函数
//Calls:
//Called By:
//Table Accessed:
//Table Updated:
//Input:
//Output:
//Return:
//Others:
//History:
//			<author>niying <time>2006-8-10		<version>		<desc>
//*********************************************************
BOOL Uninstall()
{
	if (!IsInstalled())
		return TRUE;

	SC_HANDLE hSCM = ::OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);

	if (hSCM == NULL)
	{
		MessageBox(NULL, _T("Couldn't open service manager"), szServiceName, MB_OK);
		return FALSE;
	}

	SC_HANDLE hService = ::OpenService(hSCM, szServiceName, SERVICE_STOP | DELETE);

	if (hService == NULL)
	{
		::CloseServiceHandle(hSCM);
		MessageBox(NULL, _T("Couldn't open service"), szServiceName, MB_OK);
		return FALSE;
	}
	SERVICE_STATUS status;
	::ControlService(hService, SERVICE_CONTROL_STOP, &status);

	//删除服务
	BOOL bDelete = ::DeleteService(hService);
	::CloseServiceHandle(hService);
	::CloseServiceHandle(hSCM);

	if (bDelete)
		return TRUE;

	LogEvent(_T("Service could not be deleted"));
	return FALSE;
}
Example #5
0
/* this method is called from console, when someone wants to start service */
bool TWinService::StartService() {
    if (!IsInstalled()) {
        Log(Crit) << "Unable to start. Service " << ServiceName << " is not installed." << LogEnd;
        return false;
    }

    // open a handle to the SCM
    SC_HANDLE handle = ::OpenSCManager( NULL, NULL, SC_MANAGER_ALL_ACCESS );
    if(!handle)	{
        Log(Crit) << "Could not connect to SCM dataase" << LogEnd;
        return false;
    }

    // open a handle to the service
    SC_HANDLE service = ::OpenService( handle, ServiceName, GENERIC_EXECUTE );
    if(!service) {
        ::CloseServiceHandle( handle );
        Log(Crit) << "Could not get handle to " << ServiceName << " service" << LogEnd;
        return false;
    }

    // and start the service!
    if( !::StartService( service, 0, NULL ) ) {
        Log(Crit) << "Service " << ServiceName << " startup failed. " << LogEnd;
        ::CloseServiceHandle( service );
        ::CloseServiceHandle( handle );
        return false;
    }

    Log(Notice) << "Service " << ServiceName << " started." << LogEnd;
    ::CloseServiceHandle( service );
    ::CloseServiceHandle( handle );
    return true;
}
Example #6
0
BOOL WindowsService::Install()
{
  bool ret_val= false;
  SC_HANDLE newService;
  SC_HANDLE scm;

  if (IsInstalled()) return true;

  // determine the name of the currently executing file
  char szFilePath[_MAX_PATH];
  GetModuleFileName(NULL, szFilePath, sizeof(szFilePath));

  // open a connection to the SCM
  if (!(scm= OpenSCManager(0, 0,SC_MANAGER_CREATE_SERVICE)))
    return false;

  newService= CreateService(scm, serviceName, displayName,
                            SERVICE_ALL_ACCESS, SERVICE_WIN32_OWN_PROCESS,
                            SERVICE_AUTO_START, SERVICE_ERROR_NORMAL,
                            szFilePath, NULL, NULL, NULL, username,
                            password);

  if (newService)
  {
    CloseServiceHandle(newService);
    ret_val= true;
  }

  CloseServiceHandle(scm);
  return ret_val;
}
BOOL WinService::Uninstall()
{
	if (!IsInstalled())
		return TRUE;
	
	SC_HANDLE hSCM = ::OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
	
	if (hSCM == NULL)
	{
		return FALSE;
	}
	
	SC_HANDLE hService = ::OpenService(hSCM, _servername, SERVICE_STOP | DELETE);
	
	if (hService == NULL)
	{
		::CloseServiceHandle(hSCM);
		return FALSE;
	}
	SERVICE_STATUS status;
	::ControlService(hService, SERVICE_CONTROL_STOP, &status);
	
	//删除服务
	BOOL bDelete = ::DeleteService(hService);
	::CloseServiceHandle(hService);
	::CloseServiceHandle(hSCM);
	
	if (bDelete)
		return TRUE;
	
	LogEvent("Service could not be deleted");
	return FALSE;
}
Example #8
0
inline BOOL CServiceModule::Install()
{
    if (IsInstalled())
        return TRUE;

    SC_HANDLE hSCM = ::OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
    if (hSCM == NULL)
    {
        MessageBoxA(NULL, "Couldn't open service manager", m_szServiceName, MB_OK);
        return FALSE;
    }

    // Get the executable file path
    CHAR szFilePath[_MAX_PATH];
    ::GetModuleFileNameA(NULL, szFilePath, _MAX_PATH);

    SC_HANDLE hService = ::CreateServiceA(
        hSCM, m_szServiceName, m_szServiceDesc,
        SERVICE_ALL_ACCESS, SERVICE_WIN32_OWN_PROCESS,
        SERVICE_DEMAND_START, SERVICE_ERROR_NORMAL,
        szFilePath, NULL, NULL, "RPCSS\0", NULL, NULL);

    if (hService == NULL)
    {
        ::CloseServiceHandle(hSCM);
        MessageBoxA(NULL, "Couldn't create service", m_szServiceName, MB_OK);
        return FALSE;
    }

    ::CloseServiceHandle(hService);
    ::CloseServiceHandle(hSCM);
    return TRUE;
}
Example #9
0
inline BOOL CServiceModule::Uninstall()
{
    if (!IsInstalled())
        return TRUE;

    SC_HANDLE hSCM = ::OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);

    if (hSCM == NULL)
    {
        MessageBoxA(NULL, "Couldn't open service manager", m_szServiceName, MB_OK);
        return FALSE;
    }

    SC_HANDLE hService = ::OpenServiceA(hSCM, m_szServiceName, SERVICE_STOP | DELETE);

    if (hService == NULL)
    {
        ::CloseServiceHandle(hSCM);
        MessageBoxA(NULL, "Couldn't open service", m_szServiceName, MB_OK);
        return FALSE;
    }
    SERVICE_STATUS status;
    ::ControlService(hService, SERVICE_CONTROL_STOP, &status);

    BOOL bDelete = ::DeleteService(hService);
    ::CloseServiceHandle(hService);
    ::CloseServiceHandle(hSCM);

    if (bDelete)
        return TRUE;

    MessageBoxA(NULL, "Service could not be deleted", m_szServiceName, MB_OK);
    return FALSE;
}
BOOL WindowsService::Install(const char *szFilePath)
{
    bool ret_val= false;
    SC_HANDLE newService;
    SC_HANDLE scm;

    if (IsInstalled()) return true;

    // open a connection to the SCM
    if (!(scm= OpenSCManager(0, 0,SC_MANAGER_CREATE_SERVICE)))
        return false;

    newService= CreateService(scm, serviceName, displayName,
                              SERVICE_ALL_ACCESS, SERVICE_WIN32_OWN_PROCESS,
                              SERVICE_AUTO_START, SERVICE_ERROR_NORMAL,
                              szFilePath, NULL, NULL, NULL, username,
                              password);

    if (newService)
    {
        CloseServiceHandle(newService);
        ret_val= true;
    }

    CloseServiceHandle(scm);
    return ret_val;
}
Example #11
0
bool wxGISNTService::Install()
{
	if (IsInstalled()) 
	{
		wxFprintf(stderr, wxString::Format(_("%s is already installed\n"), m_sServiceName.c_str()));
		return false;
	}
	else
	{
		// Open the Service Control Manager
		SC_HANDLE hSCM = ::OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
		if (!hSCM) 
		{
			wxFprintf(stderr, wxString::Format(_("%s is not installed\n"), m_sServiceName.c_str()));
			return false;
		}
		// Get the executable file path
		wxStandardPaths stp;
		wxString sFilePath = stp.GetExecutablePath();

		// Create the service
		SC_HANDLE hService = ::CreateService(hSCM, m_sServiceName, wxT("wxGIS Server"), SERVICE_ALL_ACCESS, SERVICE_WIN32_OWN_PROCESS, SERVICE_AUTO_START/*SERVICE_DEMAND_START*/, SERVICE_ERROR_NORMAL, sFilePath + wxT(" -s"), NULL, NULL, NULL, NULL, NULL);

		if (!hService)
		{
			::CloseServiceHandle(hSCM);
			wxFprintf(stderr, wxString::Format(_("%s is not installed\n"), m_sServiceName.c_str()));
			return false;
		}

		// make registry entries to support logging messages
		// Add the source name as a subkey under the Application
		// key in the EventLog service portion of the registry.
		wxString szKey = wxString::Format(wxT("SYSTEM\\CurrentControlSet\\Services\\EventLog\\Application\\%s"), m_sServiceName.c_str());
		HKEY hKey = NULL;
		if (::RegCreateKey(HKEY_LOCAL_MACHINE, szKey, &hKey) != ERROR_SUCCESS)
		{
			::CloseServiceHandle(hService);
			::CloseServiceHandle(hSCM);
			wxFprintf(stderr, wxString::Format(_("%s is not installed\n"), m_sServiceName.c_str()));
			return false;
		}

		// Add the Event ID message-file name to the 'EventMessageFile' subkey.
		::RegSetValueEx(hKey, wxT("EventMessageFile"), 0, REG_EXPAND_SZ, (CONST BYTE*)sFilePath.c_str(), sFilePath.Len() + 1);     

		// Set the supported types flags.
		DWORD dwData = EVENTLOG_ERROR_TYPE | EVENTLOG_WARNING_TYPE | EVENTLOG_INFORMATION_TYPE;
		::RegSetValueEx(hKey, wxT("TypesSupported"), 0, REG_DWORD, (CONST BYTE*)&dwData, sizeof(DWORD));
		::RegCloseKey(hKey);

		LogEvent(EVENTLOG_INFORMATION_TYPE, EVMSG_INSTALLED, m_sServiceName);

		// tidy up
		::CloseServiceHandle(hService);
		::CloseServiceHandle(hSCM);
		wxFprintf(stdout, wxString::Format(_("%s installed\n"), m_sServiceName.c_str()));
		return true;
	}
}
Example #12
0
    int NtService::RunAsServiceOrInteractive()
    {
        SERVICE_TABLE_ENTRY st[] =
        {
            { (LPSTR) mServiceName.c_str(), _ServiceMain },
            { NULL, NULL }
        };

        // Run as service if we can, otherwise run as interactive process.
        if (IsInstalled())
        {
            // Try running as service
            if (!StartServiceCtrlDispatcher(st))
            {
                // Run as interactive process.
                mRunningAsService = false;
                return Start();
            }
            else
            {
                return 0;
            }
        }
        else
        {
            // Run as interactive process.
            mRunningAsService = false;
            return Start();
        }
    }
HRESULT CHTFileTransferSystemServiceModule::RegisterAppId(bool bService) throw() 
{
	HRESULT hr = S_OK; 
	BOOL res = CAtlServiceModuleT<CHTFileTransferSystemServiceModule, IDS_SERVICENAME>::RegisterAppId(bService);   
	if(bService) 
	{ 
		if(IsInstalled()) 
		{                 
			SC_HANDLE hSCM = ::OpenSCManagerW(NULL, NULL, SERVICE_CHANGE_CONFIG); 
			SC_HANDLE hService = NULL; 
			if (hSCM == NULL) 
				hr = AtlHresultFromLastError(); 
			else 
			{ 
				hService = ::OpenService(hSCM, m_szServiceName, SERVICE_CHANGE_CONFIG); 
				if(hService != NULL) 
				{ 
					const int m_szServiceNameLen = 4096; 
					const int m_szServiceDescriptionLen = 2000; 
					CAString strServiceDescription = L"HTFileTransferSystemService"; 
					SERVICE_DESCRIPTION sdBuf = {strServiceDescription.GetBuffer(0)};
					strServiceDescription.ReleaseBuffer();
					res = ChangeServiceConfig2(hService, SERVICE_CONFIG_DESCRIPTION, &sdBuf); 
					if (res)
					{
						res = ChangeServiceConfig( 
							hService,        // handle of service 
							SERVICE_WIN32_OWN_PROCESS | SERVICE_INTERACTIVE_PROCESS, // service type: no change 
							SERVICE_AUTO_START,  // service start type 
							SERVICE_NO_CHANGE, // error control: no change 
							NULL,              // binary path: no change 
							NULL,              // load order group: no change 
							NULL,              // tag ID: no change 
							NULL,              // dependencies: no change 
							NULL,              // account name: no change 
							NULL,              // password: no change 
							NULL);
						if (res != 0)
						{
							hr = AtlHresultFromLastError();
						}
					}
					else
					{
						hr = AtlHresultFromLastError();
					}
					::CloseServiceHandle(hService); 
				} 
				else 
				{
					hr = AtlHresultFromLastError(); 
				}
				::CloseServiceHandle(hSCM); 
			} 
		} 
	} 
	return   hr; 
}
Example #14
0
std::wstring Environment::GetDataPath()
{
    if (IsInstalled() || IsAppContainerProcess())
    {
        return IO::Path::Combine(
                   GetKnownFolderPath(FOLDERID_LocalAppData),
                   TEXT("PicoTorrent"));
    }

    return GetApplicationPath();
}
Example #15
0
    bool NtService::Install(const tstring & commandLineArgs)
    {
        if (IsInstalled())
        {
            std::cout << "Service already installed." << std::endl;
            return true;
        }

        SC_HANDLE hSCM = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
        if (hSCM == NULL)
        {
            DWORD dwErr = GetLastError();
            std::cout << "Unable to open service manager. " + RCF::getErrorString(dwErr) << std::endl;
            return false;
        }

        // Get the executable file path
        TCHAR szFilePath[_MAX_PATH];
        GetModuleFileName(NULL, szFilePath, _MAX_PATH);

        tstring commandLine = szFilePath;
        if (commandLineArgs.size() > 0)
        {
            commandLine += _T(" ");
            commandLine += commandLineArgs;
        }

        SC_HANDLE hService = CreateService(
            hSCM,
            mServiceName.c_str(),
            mServiceDisplayName.c_str(),
            SERVICE_ALL_ACCESS,
            SERVICE_WIN32_OWN_PROCESS,
            SERVICE_DEMAND_START,
            SERVICE_ERROR_NORMAL,
            commandLine.c_str(),
            NULL, NULL, 
            NULL,
            NULL, NULL);

        if (hService == NULL)
        {
            DWORD dwErr = GetLastError();
            std::cout << "Unable to create service. " + RCF::getErrorString(dwErr) << std::endl;
            CloseServiceHandle(hSCM);
            return false;
        }

        CloseServiceHandle(hService);
        CloseServiceHandle(hSCM);
        std::cout << "Service installed." << std::endl;
        return true;
    }
Example #16
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;
}
Example #17
0
std::vector<ResourcePack*> GetLowerPriorityPacks(ResourcePack& pack)
{
  std::vector<ResourcePack*> list;
  for (auto it = std::find(packs.begin(), packs.end(), pack) + 1; it != packs.end(); it++)
  {
    auto& entry = *it;
    if (!IsInstalled(pack))
      continue;

    list.push_back(&entry);
  }

  return list;
}
Example #18
0
inline BOOL CServiceModule::Install()
{
    if (IsInstalled())
        return TRUE;

    SC_HANDLE hSCM = ::OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
    if (hSCM == NULL)
    {
        MessageBox(NULL, _T("Couldn't open service manager"), TRANSPORT_SERVICE, MB_OK);
        return FALSE;
    }

    // Get the executable file path
    TCHAR szFilePath[_MAX_PATH];
    ::GetModuleFileName(NULL, szFilePath, _MAX_PATH);

    SC_HANDLE hService = ::CreateService(
        hSCM, TRANSPORT_SERVICE, TRANSPORT_SERVICE,
        SERVICE_ALL_ACCESS, SERVICE_WIN32_SHARE_PROCESS,
        SERVICE_DEMAND_START, SERVICE_ERROR_NORMAL,
        szFilePath, NULL, NULL, TRANSPORT_SERVICE_DEPEND, NULL, NULL);

    if (hService == NULL)
    {
        ::CloseServiceHandle(hSCM);
        MessageBox(NULL, _T("Couldn't create service"), TRANSPORT_SERVICE, MB_OK);
        return FALSE;
    }
	else
	{

		HMODULE hAdvApi = ::LoadLibrary(_T("Advapi32"));
		LPFN_ChangeServiceConfig2 pfnChangeServiceConfig2 = NULL; 
		if(hAdvApi)
		{
			pfnChangeServiceConfig2 = (LPFN_ChangeServiceConfig2)GetProcAddress(hAdvApi,ChangeServiceConfig2Name);
		
			if(pfnChangeServiceConfig2)
			{
				SERVICE_DESCRIPTION sd = { (PTSTR) TRANSPORT_SERVICE_DESC };
				pfnChangeServiceConfig2(hService, SERVICE_CONFIG_DESCRIPTION, &sd);
			}

			::FreeLibrary(hAdvApi);
		}
	}
    ::CloseServiceHandle(hService);
    ::CloseServiceHandle(hSCM);
    return TRUE;
}
Example #19
0
	int Init() {
		if (!g_Config.bEnableAtrac3plus)
			return -1;

		if (!IsInstalled()) {
			// Okay, we're screwed. Let's bail.
			return -1;
		}

#ifdef _WIN32

#ifdef _M_X64
		hlib = LoadLibraryA(GetInstalledFilename().c_str());
#else
		hlib = LoadLibraryA(GetInstalledFilename().c_str());
#endif
		if (hlib) {
			frame_decoder = (ATRAC3PLUS_DECODEFRAME)GetProcAddress(hlib, "Atrac3plusDecoder_decodeFrame");
			open_context = (ATRAC3PLUS_OPENCONTEXT)GetProcAddress(hlib, "Atrac3plusDecoder_openContext");
			close_context = (ATRAC3PLUS_CLOSECONTEXT)GetProcAddress(hlib, "Atrac3plusDecoder_closeContext");
		} else {
			return -1;
		}
#else
		std::string filename = GetInstalledFilename();

		ILOG("Attempting to load atrac3plus decoder from %s", filename.c_str());
		so = dlopen(filename.c_str(), RTLD_LAZY);
		if (so) {
			frame_decoder = (ATRAC3PLUS_DECODEFRAME)dlsym(so, "Atrac3plusDecoder_decodeFrame");
			open_context = (ATRAC3PLUS_OPENCONTEXT)dlsym(so, "Atrac3plusDecoder_openContext");
			close_context = (ATRAC3PLUS_CLOSECONTEXT)dlsym(so, "Atrac3plusDecoder_closeContext");
			ILOG("Successfully loaded atrac3plus decoder from %s", filename.c_str());
			if (!frame_decoder || !open_context || !close_context) {
				ILOG("Found atrac3plus decoder at %s but failed to load functions", filename.c_str());
				return -1;
			}
		} else {
			if (errno == ENOEXEC) {
				ELOG("Failed to load atrac3plus decoder from %s. errno=%i, dlerror=%s", filename.c_str(), (int)(errno), dlerror());
			} else {
				ELOG("Failed to load atrac3plus decoder from %s. errno=%i", filename.c_str(), (int)(errno));
			}
			return -1;
		}
#endif

		return 0;
	}
Example #20
0
    bool NtService::Uninstall()
    {
        if (!IsInstalled())
        {
            std::cout << "Service not installed." << std::endl;
            return true;
        }

        SC_HANDLE hSCM = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);

        if (hSCM == NULL)
        {
            DWORD dwErr = GetLastError();
            std::cout << "Unable to open service manager. " + RCF::getErrorString(dwErr) << std::endl;
            return false;
        }

        SC_HANDLE hService = OpenService(hSCM, mServiceName.c_str(), SERVICE_STOP | DELETE);

        if (hService == NULL)
        {
            DWORD dwErr = GetLastError();
            std::cout << "Unable to open service. " + RCF::getErrorString(dwErr) << std::endl;
            CloseServiceHandle(hSCM);
            return false;
        }

        SERVICE_STATUS status;
        ControlService(hService, SERVICE_CONTROL_STOP, &status);

        BOOL bDelete = DeleteService(hService);
        if ( !bDelete )
        {
            DWORD dwErr = GetLastError();
            std::cout << "Unable to delete service. " + RCF::getErrorString(dwErr) << std::endl;
            CloseServiceHandle(hService);
            CloseServiceHandle(hSCM);
            return false;
        }

        CloseServiceHandle(hService);
        CloseServiceHandle(hSCM);

        std::cout << "Service uninstalled." << std::endl;
        return true;

    }
Example #21
0
	bool ServiceModule::Install(void)
	{
		LOG4CPLUS_TRACE(log,"install service starting...");
		if (IsInstalled())
			return true;

		SERVICE_DESCRIPTION desc;
		desc.lpDescription = SERVICEDESCRIPTION;

		SC_HANDLE hSCM = ::OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
		if (hSCM == NULL)
		{
			LOG4CPLUS_ERROR(log, _T("Couldn't open service manager"));
			return FALSE;
		}

		// Get the executable file path
		TCHAR szFilePath[_MAX_PATH];
		::GetModuleFileName(NULL, szFilePath, _MAX_PATH);

		strcat_s(szFilePath," -startservice");
		
		LOG4CPLUS_TRACE(log, "servicename (" << m_szServiceName << ")" << std::endl);
		LOG4CPLUS_TRACE(log," FilePath (" << szFilePath << ")" << std::endl);

		SC_HANDLE hService = ::CreateService(
			hSCM, m_szServiceName, m_szServiceName,
			SERVICE_ALL_ACCESS, SERVICE_WIN32_OWN_PROCESS,
			SERVICE_DEMAND_START, SERVICE_ERROR_NORMAL,
			szFilePath, NULL, NULL, _T("RPCSS\0"), NULL, NULL);
	
		if (hService == NULL) {
			LOG4CPLUS_ERROR(log, "Error creating chilli service (" << GetLastError() << ")");
			CloseServiceHandle(hSCM);
			return false;
		}

		/* Set desc, and don't care if it succeeds */
		if (!ChangeServiceConfig2(hService, SERVICE_CONFIG_DESCRIPTION, &desc)) {
			LOG4CPLUS_ERROR(log, "chilli installed, but could not set the service description (" << GetLastError() << ")");
		}

		::CloseServiceHandle(hService);
		::CloseServiceHandle(hSCM);
		return true;

	}
bool CBaseCloudStorage::RetrieveTasklist(ITS_TASKLISTINFO* pFInfo, ITaskList* /*pDestTaskFile*/, IPreferences* /*pPrefs*/, LPCTSTR /*szKey*/, bool bSilent)
{
	CString sUserFolder;
	
	if (IsInstalled(sUserFolder))
	{
		CString sSrcPath = pFInfo->szTasklistID;
		CString sDestPath = pFInfo->szLocalFileName;
		
		if (bSilent && sSrcPath.IsEmpty())
			return false;
		
		if (sSrcPath.IsEmpty())
		{
			CFileOpenDialog	dialog(GetMenuText(), 
									_T("tdl"), 
									NULL, 
									EOFN_DEFAULTOPEN, 
									_T("Tasklists (*.tdl)|*.tdl"));

			dialog.m_ofn.lpstrInitialDir = sUserFolder;
			
			if (dialog.DoModal() != IDOK)
				return false;
			
			// else
			sSrcPath = dialog.GetPathName();

			if (sDestPath.IsEmpty())
				sDestPath = sSrcPath;
		}
		
		if (FileMisc::IsSameFile(sSrcPath, sDestPath) || ::CopyFile(sSrcPath, sDestPath, FALSE))
		{
			// return information to caller
			UpdateTaskListInfo(pFInfo, sDestPath);
			return true;
		}
	}
	
	return false;
}
Example #23
0
inline BOOL CServiceModule::Uninstall()
{
    if (!IsInstalled())
        return TRUE;

    SC_HANDLE hSCM = ::OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);

    if (hSCM == NULL)
    {
        MessageBox(NULL, _T("Couldn't open service manager"), TRANSPORT_SERVICE, MB_OK);
        return FALSE;
    }

    SC_HANDLE hService = ::OpenService(hSCM, TRANSPORT_SERVICE, SERVICE_STOP | DELETE);

    if (hService == NULL)
    {
        ::CloseServiceHandle(hSCM);
        MessageBox(NULL, _T("Couldn't open service"), TRANSPORT_SERVICE, MB_OK);
        return FALSE;
    }
    SERVICE_STATUS status;
    ::ControlService(hService, SERVICE_CONTROL_STOP, &status);

    BOOL bDelete = ::DeleteService(hService);

	if(!bDelete)
	{
		DWORD dwErr = GetLastError();
		if(ERROR_SERVICE_MARKED_FOR_DELETE == dwErr)
			bDelete = TRUE;
	}
    ::CloseServiceHandle(hService);
    ::CloseServiceHandle(hSCM);

    if(bDelete)
        return TRUE;

    MessageBox(NULL, _T("Service could not be deleted"), TRANSPORT_SERVICE, MB_OK);
    return FALSE;
}
inline BOOL CServiceModule::Uninstall()
{
    if (!IsInstalled())
        return TRUE;

    SC_HANDLE hSCM = ::OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);

    if (hSCM == NULL)
    {
        MessageBox(NULL, _T("Couldn't open service manager"), m_szServiceDisplayName, MB_OK);
        return FALSE;
    }

    SC_HANDLE hService = ::OpenService(hSCM, m_szServiceName, SERVICE_STOP | DELETE);

    if (hService == NULL)
    {
	DWORD err = GetLastError();
        ::CloseServiceHandle(hSCM);
	if (err == ERROR_SERVICE_DOES_NOT_EXIST)
	    return TRUE;
	DisplayMessage(err, "Opening service");
        return FALSE;
    }
    SERVICE_STATUS status;
    ::ControlService(hService, SERVICE_CONTROL_STOP, &status);

    BOOL bDelete = ::DeleteService(hService);
    ::CloseServiceHandle(hService);
    ::CloseServiceHandle(hSCM);

    if (bDelete)
        return TRUE;
    DWORD err = GetLastError();
    if (err = ERROR_SERVICE_MARKED_FOR_DELETE)
	return TRUE;

    DisplayMessage(GetLastError(), "Deleting service");
    return FALSE;
}
BOOL WinService::Install()
{
	if (IsInstalled())
		return TRUE;
	
	//打开服务控制管理器
	SC_HANDLE hSCM = ::OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
	if (hSCM == NULL)
	{
		return FALSE;
	}
	
	// Get the executable file path
	TCHAR szFilePath[MAX_PATH];
	::GetModuleFileName(NULL, szFilePath, MAX_PATH);
	
	//创建服务
	SC_HANDLE hService = ::CreateService(
		hSCM, _servername, _serverdisplayname,
		SERVICE_ALL_ACCESS, SERVICE_WIN32_OWN_PROCESS,
		SERVICE_AUTO_START, SERVICE_ERROR_NORMAL,
		szFilePath, NULL, NULL, "", NULL, NULL);
	
	if (hService == NULL)
	{
		::CloseServiceHandle(hSCM);
		return FALSE;
	}
	SERVICE_DESCRIPTION sdBuf;
    sdBuf.lpDescription = _serviceDescription;

	ChangeServiceConfig2(
		hService,                // handle to service
		SERVICE_CONFIG_DESCRIPTION, // change: description
		&sdBuf) ;                  // value: new description
	
	::CloseServiceHandle(hService);
	::CloseServiceHandle(hSCM);
	return TRUE;
}
Example #26
0
bool TWinService::StopService()
{
    if (!IsInstalled()) {
        Log(Crit) << "Unable to stop. Service " << ServiceName << " is not installed." << LogEnd;
        return false;
    }

    // open a handle to the SCM
    SC_HANDLE handle = ::OpenSCManager( NULL, NULL, SC_MANAGER_ALL_ACCESS );
    if(!handle)	{
        Log(Crit) << "Could not connect to SCM database" << LogEnd;
        return false;
    }

    // open a handle to the service
    SC_HANDLE service = ::OpenService( handle, ServiceName, GENERIC_EXECUTE );
    if(!service) {
        ::CloseServiceHandle( handle );
        Log(Crit) << "Unable to open service " << ServiceName << LogEnd;
        return false;
    }

    // send the STOP control request to the service
    SERVICE_STATUS status;
    ::ControlService( service, SERVICE_CONTROL_STOP, &status );
    ::CloseServiceHandle( service );
    ::CloseServiceHandle( handle );

    if (status.dwCurrentState == SERVICE_STOP_PENDING) {
        Log(Notice) << "Service " << ServiceName << " stop process initialized." << LogEnd;
        return true;
    }

    if( status.dwCurrentState != SERVICE_STOPPED ) {
        Log(Crit) << "Service " << ServiceName << " stop failed." << LogEnd;
        return false;
    }
    Log(Notice) << "Service " << ServiceName << " stopped." << LogEnd;
    return true;
}
inline BOOL CServiceModule::Install()
{
    if (IsInstalled())
        return TRUE;

    SC_HANDLE hSCM = ::OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
    if (hSCM == NULL)
    {
        MessageBox(NULL, _T("Couldn't open service manager"), m_szServiceDisplayName, MB_OK);
        return FALSE;
    }

    // Get the executable file path
    TCHAR szFilePath[_MAX_PATH];
    ::GetModuleFileName(NULL, szFilePath, _MAX_PATH);

    SC_HANDLE hService = ::CreateService(
        hSCM, m_szServiceName, m_szServiceDisplayName,
        SERVICE_ALL_ACCESS, SERVICE_WIN32_OWN_PROCESS,
        SERVICE_DEMAND_START, SERVICE_ERROR_NORMAL,
        szFilePath, NULL, NULL, _T("RPCSS\0"), NULL, NULL);

    if (hService == NULL)
    {
	DWORD err = GetLastError();
        ::CloseServiceHandle(hSCM);

	if (err == ERROR_SERVICE_EXISTS)
	    return TRUE;
	DisplayMessage (err, "Creating service");
        return FALSE;
    }

    ::CloseServiceHandle(hService);
    ::CloseServiceHandle(hSCM);
    return TRUE;
}
Example #28
0
BOOL UnloadDriver()
{
    if (!IsInstalled())
        return TRUE;

    SC_HANDLE hSCM = ::OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);

    if (hSCM == NULL)
    {
        MessageBox(NULL, _T("不能打开服务控制管理器"), szServiceName, MB_OK);
        return FALSE;
    }

    SC_HANDLE hService = ::OpenService(hSCM, szServiceName, SERVICE_STOP | DELETE);

    if (hService == NULL)
    {
        ::CloseServiceHandle(hSCM);
        AfxMessageBox( _T("不能打开服务") );
        return FALSE;
    }
    SERVICE_STATUS status;
    ::ControlService(hService, SERVICE_CONTROL_STOP, &status);
	Sleep( 1000 );

	//删除服务
    BOOL bDelete = ::DeleteService(hService);
    ::CloseServiceHandle(hService);
    ::CloseServiceHandle(hSCM);

    if (bDelete)
        return TRUE;

    AfxMessageBox(_T("服务不能被删除"));
    return FALSE;
}
Example #29
0
	bool ServiceModule::Uninstall(void)
	{
		LOG4CPLUS_TRACE(log,"Uninstall,starting...");
		if (!IsInstalled())
			return true;

		SC_HANDLE hSCM = ::OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);

		if (hSCM == NULL)
		{
			LOG4CPLUS_ERROR(log, "Couldn't open service manager"<<m_szServiceName);
			return false;
		}

		SC_HANDLE hService = ::OpenService(hSCM, m_szServiceName, SERVICE_STOP | DELETE);

		if (hService == NULL)
		{
			::CloseServiceHandle(hSCM);
			LOG4CPLUS_ERROR(log, "Couldn't open service");
			return false;
		}
		SERVICE_STATUS status;
		::ControlService(hService, SERVICE_CONTROL_STOP, &status);

		bool bDelete = ::DeleteService(hService)?true:false;
		if (!bDelete)
		{
			LOG4CPLUS_ERROR(log,"Service could not be deleted errorcode="<<GetLastError());
		}
	
		::CloseServiceHandle(hService);
		::CloseServiceHandle(hSCM);
	
		return bDelete;
	}
Example #30
0
BOOL WindowsService::Remove()
{
  bool  ret_val= false;

  if (! IsInstalled())
    return true;

  // open a connection to the SCM
  SC_HANDLE scm= OpenSCManager(0, 0,SC_MANAGER_CREATE_SERVICE);
  if (! scm)
    return false;

  SC_HANDLE service= OpenService(scm, serviceName, DELETE);
  if (service)
  {
    if (DeleteService(service))
      ret_val= true;
    DWORD dw= ::GetLastError();
    CloseServiceHandle(service);
  }

  CloseServiceHandle(scm);
  return ret_val;
}