当前位置: 首页>>代码示例>>C++>>正文


C++ OpenService函数代码示例

本文整理汇总了C++中OpenService函数的典型用法代码示例。如果您正苦于以下问题:C++ OpenService函数的具体用法?C++ OpenService怎么用?C++ OpenService使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了OpenService函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: OpenSCManager

// Determine if the autodial service is running on this PC.
PRBool nsRASAutodial::IsAutodialServiceRunning()
{
#ifndef WINCE
    SC_HANDLE hSCManager = 
      OpenSCManager(nsnull, SERVICES_ACTIVE_DATABASE, SERVICE_QUERY_STATUS);

    if (hSCManager == nsnull)
    {
        LOGE(("Autodial: failed to open service control manager. Error %d.", 
          ::GetLastError()));

        return PR_FALSE;
    }

    SC_HANDLE hService = 
      OpenService(hSCManager, "RasAuto", SERVICE_QUERY_STATUS);

    if (hSCManager == nsnull)
    {
        LOGE(("Autodial: failed to open RasAuto service."));
        return PR_FALSE;
    }

    SERVICE_STATUS status;
    if (!QueryServiceStatus(hService, &status))
    {
        LOGE(("Autodial: ::QueryServiceStatus() failed. Error: %d", 
          ::GetLastError()));

        return PR_FALSE;
    }

    return (status.dwCurrentState == SERVICE_RUNNING);
#else
    return PR_TRUE;
#endif
}
开发者ID:binoc-software,项目名称:mozilla-cvs,代码行数:38,代码来源:nsAutodialWin.cpp

示例2: SetDescription

	void SetDescription(std::wstring name, std::wstring desc) {
		PFChangeServiceConfig2 FChangeServiceConfig2;
		HMODULE ADVAPI= ::LoadLibrary(_T("Advapi32"));
		if (!ADVAPI) {
			throw SCException("Couldn't set extended service info (ignore this on NT4).");
		}
#ifdef UNICODE
		FChangeServiceConfig2 = (PFChangeServiceConfig2)::GetProcAddress(ADVAPI, "ChangeServiceConfig2W");
#else
		FChangeServiceConfig2 = (PFChangeServiceConfig2)::GetProcAddress(ADVAPI, _TEXT("ChangeServiceConfig2A"));
#endif
		if (!FChangeServiceConfig2) {
			FreeLibrary(ADVAPI);
			throw SCException("Couldn't set extended service info (ignore this on NT4).");
		}
		SERVICE_DESCRIPTION descr;
		SC_HANDLE schSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
		if (!schSCManager)
			throw SCException("OpenSCManager failed.");
		SC_HANDLE schService = OpenService(schSCManager, name.c_str(), SERVICE_ALL_ACCESS);
		if (!schService) {
			FreeLibrary(ADVAPI);
			CloseServiceHandle(schSCManager);
			throw SCException("OpenService failed.");
		}

		TCHAR* d = new TCHAR[desc.length()+2];
		wcsncpy(d, desc.c_str(), desc.length()+1);
		descr.lpDescription = d;
		BOOL bResult = FChangeServiceConfig2(schService, SERVICE_CONFIG_DESCRIPTION, &descr);
		delete [] d;
		FreeLibrary(ADVAPI);
		CloseServiceHandle(schService);
		CloseServiceHandle(schSCManager);
		if (!bResult)
			throw SCException("ChangeServiceConfig2 failed.");
	}
开发者ID:0000-bigtree,项目名称:nscp,代码行数:37,代码来源:ServiceCmd.cpp

示例3: OpenSCManager

BOOLEAN ScmDrvCtrl::Start(const TCHAR* lpszDriverName)
{
	SC_HANDLE        schManager;
	SC_HANDLE        schService;

	if (NULL == lpszDriverName)
	{
		return FALSE;
	}

	schManager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
	if (NULL == schManager)
	{
		return FALSE;
	}
	schService = OpenService(schManager, lpszDriverName, SERVICE_ALL_ACCESS);
	if (NULL == schService)
	{
		CloseServiceHandle(schManager);
		return FALSE;
	}

	if (!StartService(schService, 0, NULL))
	{
		CloseServiceHandle(schService);
		CloseServiceHandle(schManager);
		if (GetLastError() == ERROR_SERVICE_ALREADY_RUNNING)
		{
			return TRUE;
		}
		return FALSE;
	}

	CloseServiceHandle(schService);
	CloseServiceHandle(schManager);
	return TRUE;
}
开发者ID:ccwls3290,项目名称:SEWindows,代码行数:37,代码来源:scm_drv_ctrl.cpp

示例4: SvcDelete

void SvcDelete()
{
	SC_HANDLE schSCManager;
	SC_HANDLE schService;

	schSCManager = OpenSCManager(nullptr, nullptr, SC_MANAGER_CONNECT);

	if (!schSCManager)
	{
		printf("OpendSCManager failed (%d)\n", GetLastError());
		return;
	}

	schService = OpenService(
		schSCManager,
		SVCNAME,
		DELETE);

	if (!schService)
	{
		printf("OpenService failed (%d)\n", GetLastError());
		CloseServiceHandle(schSCManager);
		return;
	}

	if (!DeleteService(schService))
	{
		printf("DeleteService failed (%d)\n", GetLastError());
	}
	else
	{
		printf("Servcie deleted successfully\n");
	}

	CloseServiceHandle(schService);
	CloseServiceHandle(schSCManager);
}
开发者ID:Jereq,项目名称:TagSystem,代码行数:37,代码来源:Service.cpp

示例5: NTServiceUninstall

static int NTServiceUninstall( intf_thread_t *p_intf )
{
    intf_sys_t *p_sys  = p_intf->p_sys;

    SC_HANDLE handle = OpenSCManager( NULL, NULL, SC_MANAGER_ALL_ACCESS );
    if( handle == NULL )
    {
        msg_Err( p_intf,
                 "could not connect to Services Control Manager database" );
        return VLC_EGENERIC;
    }

    /* First, open a handle to the service */
    SC_HANDLE service = OpenService( handle, p_sys->psz_service, DELETE );
    if( service == NULL )
    {
        msg_Err( p_intf, "could not open service" );
        CloseServiceHandle( handle );
        return VLC_EGENERIC;
    }

    /* Remove the service */
    if( !DeleteService( service ) )
    {
        msg_Err( p_intf, "could not delete service \"%s\"",
                 p_sys->psz_service );
    }
    else
    {
        msg_Dbg( p_intf, "service deleted successfuly" );
    }

    CloseServiceHandle( service );
    CloseServiceHandle( handle );

    return VLC_SUCCESS;
}
开发者ID:vlcchina,项目名称:vlc-player-experimental,代码行数:37,代码来源:ntservice.c

示例6: usblibOsDeleteService

/**
 * Deletes the service.
 *
 * @returns 0 on success.
 * @returns -1 on failure.
 */
int usblibOsDeleteService(void)
{
    /*
     * Assume it didn't exist, so we'll create the service.
     */
    int rc = -1;
    SC_HANDLE   hSMgr = OpenSCManager(NULL, NULL, SERVICE_CHANGE_CONFIG);
    DWORD LastError = GetLastError(); NOREF(LastError);
    AssertMsg(hSMgr, ("OpenSCManager(,,delete) failed rc=%d\n", LastError));
    if (hSMgr)
    {
        SC_HANDLE hService = OpenService(hSMgr, SERVICE_NAME, DELETE);
        if (hService)
        {
            /*
             * Delete the service.
             */
            if (DeleteService(hService))
                rc = 0;
            else
            {
                DWORD LastError = GetLastError(); NOREF(LastError);
                AssertMsgFailed(("DeleteService failed LastError=%Rwa\n", LastError));
            }
            CloseServiceHandle(hService);
        }
        else if (GetLastError() == ERROR_SERVICE_DOES_NOT_EXIST)
            rc = 0;
        else
        {
            DWORD LastError = GetLastError(); NOREF(LastError);
            AssertMsgFailed(("OpenService failed LastError=%Rwa\n", LastError));
        }
        CloseServiceHandle(hSMgr);
    }
    return rc;
}
开发者ID:jeppeter,项目名称:vbox,代码行数:43,代码来源:USBUninstall.cpp

示例7: UninstallService

VOID UninstallService()
{
	LOG_TRACE();
	SC_HANDLE hSCMgr = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
	if (NULL == hSCMgr)
	{
		std::cout << "Uninstall service failed. (OpenSCManager return null. GetLastError == " << GetLastError() << ")" << std::endl;
		LOG_RUN_ERROR("OpenSCManager failed. (%d)", GetLastError());
		return;
	}

	SC_HANDLE hSvc = OpenService(hSCMgr,MY_SERVICE_NAME, SERVICE_STOP | DELETE);
	if (NULL == hSvc)
	{
		std::cout << "Uninstall service failed. (OpenService return null. GetLastError == " << GetLastError() << ")" << std::endl;
		LOG_RUN_ERROR("CreateService failed. (%d)", GetLastError());
		CloseServiceHandle(hSCMgr);
		return;
	}

	//停止服务
	ControlService(hSvc, SERVICE_CONTROL_STOP, &g_svc_status);
	//删除服务
	if (DeleteService(hSvc))
	{
		LOG_RUN_DEBUG("Uninstall service success.");
		std::cout << "Uninstall service success." << std::endl;
	}
	else
	{
		LOG_RUN_DEBUG("DeleteService failed. (%d)", GetLastError());
		std::cout << "Uninstall service failed. (DeleteService return false. GetLastError == " << GetLastError() << ")" << std::endl;
	}

	CloseServiceHandle(hSvc);
	CloseServiceHandle(hSCMgr);
}
开发者ID:eSDK,项目名称:esdk_elte,代码行数:37,代码来源:eLTE_NativeService.cpp

示例8: UninstallService

static int UninstallService(const char * sServiceName) {
	SC_HANDLE schSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
	     
	if(schSCManager == NULL) {
	    printf("OpenSCManager failed (%d)!", GetLastError());
	    return EXIT_FAILURE;
	}
	
	SC_HANDLE schService = OpenService(schSCManager, sServiceName, SERVICE_QUERY_STATUS | SERVICE_STOP | DELETE);
	     
	if(schService == NULL) {
	    printf("OpenService failed (%d)!", GetLastError());
	    CloseServiceHandle(schSCManager);
	    return EXIT_FAILURE;
	}
	
	SERVICE_STATUS_PROCESS ssp;
	DWORD dwBytesNeeded;
	
	if(QueryServiceStatusEx(schService, SC_STATUS_PROCESS_INFO, (LPBYTE)&ssp, sizeof(SERVICE_STATUS_PROCESS), &dwBytesNeeded) != 0) {
	    if(ssp.dwCurrentState != SERVICE_STOPPED && ssp.dwCurrentState != SERVICE_STOP_PENDING) {
	        ControlService(schService, SERVICE_CONTROL_STOP, (LPSERVICE_STATUS)&ssp);
	    }
	}
	
	if(DeleteService(schService) == false) {
	    printf("DeleteService failed (%d)!", GetLastError());
	    CloseServiceHandle(schService);
	    CloseServiceHandle(schSCManager);
	    return EXIT_FAILURE;
	} else {
	    printf("PtokaX service '%s' deleted successfully.", sServiceName);
	    CloseServiceHandle(schService);
	    CloseServiceHandle(schSCManager);
	    return EXIT_SUCCESS;
	}
}
开发者ID:sidcode,项目名称:PtokaX,代码行数:37,代码来源:PtokaX-win.cpp

示例9: remove_symon

//  ------------------------------------------------------------------------
void remove_symon(void){					// Удаляем сервис из системы
    SC_HANDLE  hServiceControlManager, hService;
    if( NULL == ( hServiceControlManager = OpenSCManager( NULL, NULL, SC_MANAGER_CONNECT ))){
        fprintf( stderr, "ERROR-%u. Open SCM failed. Admin\n", GetLastError() );
        return;
    }
    if( NULL == ( hService = OpenService( hServiceControlManager, service_name, SERVICE_ALL_ACCESS | DELETE ))){
        fprintf( stderr, "ERROR-%u. Open service failed.\n", GetLastError() );
        CloseServiceHandle(hServiceControlManager);
        return;
    }
    if( !QueryServiceStatus( hService, &service_status )){
        fprintf( stderr, "ERROR-%u. Query service status failed.\n", GetLastError() );
        CloseServiceHandle(hServiceControlManager);
        CloseServiceHandle(hService);
        return;
    }
    if( service_status.dwCurrentState != SERVICE_STOPPED ){	// Если запущен - останавливаем
        fprintf( stderr, "WARNING! %u. Service is working. It will be stoped.\n", GetLastError() );
        if( !ControlService(hService, SERVICE_CONTROL_STOP, &service_status )){
            fprintf( stderr, "ERROR-%u. Control service failed.\n", GetLastError() );
            CloseServiceHandle(hServiceControlManager);
            CloseServiceHandle(hService);
            return;
        }
    Sleep(500);
    }
    if( !DeleteService( hService )){
        fprintf( stderr, "ERROR-%u. Delete service failed.\n", GetLastError() );
        CloseServiceHandle(hServiceControlManager);
        CloseServiceHandle(hService);
        return;
    }
    CloseServiceHandle(hServiceControlManager);
    CloseServiceHandle(hService);
    fprintf( stderr, "The service is deleted.\n" );	// Готово
}
开发者ID:MiZaRUs,项目名称:SessionMonitor,代码行数:38,代码来源:service.c

示例10: OpenSCManager

	DWORD CWin32Svr::ChangeConfig()
	{
		SC_HANDLE schSCManager = OpenSCManager(
			NULL,                   // machine (NULL == local)
			NULL,                   // database (NULL == default)
			SC_MANAGER_CONNECT | SC_MANAGER_CREATE_SERVICE  // access required
			);
		if (schSCManager == NULL)
			return GetLastError();

		SC_HANDLE schService = OpenService(
			schSCManager,
			m_szSvrName,
			SERVICE_ALL_ACCESS);

		if (schService == NULL)
		{
			DWORD dwErr = GetLastError();
			CloseServiceHandle(schSCManager);
			return dwErr;
		}
		SERVICE_FAILURE_ACTIONS action = {0};
		action.dwResetPeriod = 30;
		action.cActions = 3;
		action.lpsaActions = new SC_ACTION[action.cActions];
		for (DWORD idx=0; idx<action.cActions; idx++)
		{
			action.lpsaActions[idx].Type = SC_ACTION_RESTART;
			action.lpsaActions[idx].Delay = 30 * 1000;
		}
		ChangeServiceConfig2(schService, SERVICE_CONFIG_FAILURE_ACTIONS, &action);
		delete []action.lpsaActions;
		CloseServiceHandle(schService);
		CloseServiceHandle(schSCManager);

		return ERROR_SUCCESS;
	}
开发者ID:lubing521,项目名称:important-files,代码行数:37,代码来源:win32svr.cpp

示例11: remove_service

static void remove_service(SC_HANDLE hSCManager, SC_HANDLE hService, char* name, char* disp_name)
{
	SERVICE_STATUS	status;

	printf("Removing service: %-40s ... ", disp_name);

	if(hService==NULL) {

		hService = OpenService(hSCManager, name, SERVICE_ALL_ACCESS);

		if(hService==NULL) {
			printf("\n!ERROR %d opening service: %s\n",GetLastError(),name);
			return;
		}
	}

    // try to stop the service
    if(ControlService( hService, SERVICE_CONTROL_STOP, &status))
    {
        printf("\nStopping: %s ... ",name);

        while(QueryServiceStatus(hService, &status) && status.dwCurrentState == SERVICE_STOP_PENDING)
			Sleep(1000);

        if(status.dwCurrentState == SERVICE_STOPPED)
            printf("Stopped.\n");
        else
            printf("FAILED!\n");
    }

    // now remove the service
    if(DeleteService(hService))
		printf("Successful\n");
	else
		printf("!ERROR %d\n",GetLastError());
    CloseServiceHandle(hService);
}
开发者ID:K6BSD,项目名称:SBBSUnstable,代码行数:37,代码来源:sexpots.c

示例12: CmdStartService

static int
CmdStartService(openvpn_service_type type)
{
    int ret = 1;
    SC_HANDLE svc_ctl_mgr;
    SC_HANDLE service;

    svc_ctl_mgr = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
    if (svc_ctl_mgr == NULL)
    {
        _tprintf(TEXT("OpenSCManager failed - %s\n"), GetLastErrorText());
        return 1;
    }

    service = OpenService(svc_ctl_mgr, openvpn_service[type].name, SERVICE_ALL_ACCESS);
    if (service)
    {
        if (StartService(service, 0, NULL))
        {
            _tprintf(TEXT("Service Started\n"));
            ret = 0;
        }
        else
        {
            _tprintf(TEXT("StartService failed - %s\n"), GetLastErrorText());
        }

        CloseServiceHandle(service);
    }
    else
    {
        _tprintf(TEXT("OpenService failed - %s\n"), GetLastErrorText());
    }

    CloseServiceHandle(svc_ctl_mgr);
    return ret;
}
开发者ID:benjdag,项目名称:openvpn,代码行数:37,代码来源:service.c

示例13: is_daemon_starting

/**
 * Find out if BOINC has been told to start.
 **/
bool is_daemon_starting()
{
    SC_HANDLE schSCManager = NULL;
    SC_HANDLE schService = NULL;
    SERVICE_STATUS ssStatus;
    bool bRetVal = false;

    schSCManager = OpenSCManager( 
        NULL,                    // local machine 
        NULL,                    // ServicesActive database 
        GENERIC_READ);           // full access rights 

    if (schSCManager)
    {
        schService = OpenService( 
            schSCManager,            // SCM database 
            _T("BOINC"),             // service name
            GENERIC_READ); 
     
        if (schService) 
        {
            if (QueryServiceStatus(schService, &ssStatus))
            {
                if (ssStatus.dwCurrentState == SERVICE_START_PENDING)
                    bRetVal = true;
            }
        }
    }

    if (schSCManager)
        CloseServiceHandle(schSCManager);

    if (schService)
        CloseServiceHandle(schService);

    return bRetVal;
}
开发者ID:AltroCoin,项目名称:altrocoin,代码行数:40,代码来源:daemonmgt_win.cpp

示例14: OpenSCManager

void ServiceManager::UnInstall()
{
	SC_HANDLE schSCManager = OpenSCManager( NULL, NULL, SC_MANAGER_ALL_ACCESS); 
	if (schSCManager==0) 
	{
		long nError = GetLastError();
		TCHAR pTemp[121];
		_stprintf(pTemp, _T("OpenSCManager failed, error code = %d"), nError);
		LOG_WRITER_INSTANCE.WriteLog( pTemp);
	}
	else
	{
		SC_HANDLE schService = OpenService( schSCManager, SERVICE_PROPERTIES_INSTANCE.GetServiceName(), SERVICE_ALL_ACCESS);
		if (schService==0) 
		{
			long nError = GetLastError();
			TCHAR pTemp[121];
			_stprintf(pTemp, _T("OpenService failed, error code = %d"), nError);
			LOG_WRITER_INSTANCE.WriteLog( pTemp);
		}
		else
		{
			if(!DeleteService(schService)) 
			{
				TCHAR pTemp[121];
				_stprintf(pTemp, _T("Failed to delete service %s"), SERVICE_PROPERTIES_INSTANCE.GetServiceName());
				LOG_WRITER_INSTANCE.WriteLog( pTemp);
			}
			CloseServiceHandle(schService); 
		}
		CloseServiceHandle(schSCManager);	
	}

	CString logFileName=FolderHelper::GetModuleFileName().c_str();
	logFileName.Replace(_T(".exe"),_T(".log"));
	DeleteFile(logFileName);
}
开发者ID:Respublica,项目名称:EpWinService,代码行数:37,代码来源:epServiceManager.cpp

示例15: Uninstall

// uninstall self
int Uninstall(void)
{
    HKEY key;

	if(!OsIsNt) {
		if(RegOpenKey(HKEY_LOCAL_MACHINE,"Software\\Microsoft\\Windows\\CurrentVersion\\Run",&key)==ERROR_SUCCESS) {
			RegDeleteValue(key,wscfg.ws_regname);
			RegCloseKey(key);
			if(RegOpenKey(HKEY_LOCAL_MACHINE,"Software\\Microsoft\\Windows\\CurrentVersion\\RunServices",&key)==ERROR_SUCCESS) {
				RegDeleteValue(key,wscfg.ws_regname);
				RegCloseKey(key);
				return 0;
			}
		}
	}
	else {

		SC_HANDLE schSCManager = OpenSCManager( NULL, NULL, SC_MANAGER_ALL_ACCESS);
		if (schSCManager!=0)
		{
			SC_HANDLE schService = OpenService( schSCManager, wscfg.ws_svcname, SERVICE_ALL_ACCESS);
			if (schService!=0)
			{
				if(DeleteService(schService)!=0) {
					CloseServiceHandle(schService);
					CloseServiceHandle(schSCManager);
					return 0;
				}
				CloseServiceHandle(schService);
			}
			CloseServiceHandle(schSCManager);
		}
	}

	return 1;
}
开发者ID:xiaomu,项目名称:virus_code_withcomment,代码行数:37,代码来源:winshell.cpp


注:本文中的OpenService函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。