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


C++ ChangeServiceConfig函数代码示例

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


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

示例1: enableService

static bool enableService(int enable)
{
    SC_HANDLE   svc, mgr;
    int         flag;

    mgr = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
    if (! mgr) {
        mprUserError("Can't open service manager");
        return 0;
    }
    svc = OpenService(mgr, app->serviceName, SERVICE_ALL_ACCESS);
    if (svc == NULL) {
        if (enable) {
            mprUserError("Can't access service");
        }
        CloseServiceHandle(mgr);
        return 0;
    }
    flag = (enable) ? SERVICE_AUTO_START : SERVICE_DISABLED;
    if (!ChangeServiceConfig(svc, SERVICE_NO_CHANGE, flag, SERVICE_NO_CHANGE, NULL, NULL, NULL, NULL, NULL, NULL, NULL)) {
        mprUserError("Can't change service: 0x%x == %d", GetLastError(), GetLastError());
        CloseServiceHandle(svc);
        CloseServiceHandle(mgr);
        return 0;
    }
    CloseServiceHandle(svc);
    CloseServiceHandle(mgr);
    return 1;
}
开发者ID:childhood,项目名称:appweb-4,代码行数:29,代码来源:manager.c

示例2: enable_service

static BOOL enable_service(void){
  SC_HANDLE scm;
  SC_HANDLE service;
  BOOL ret;

if(!open_service_config(&scm,&service))
    return FALSE;

    ret = ChangeServiceConfig(service,
			    SERVICE_NO_CHANGE,
			    SERVICE_AUTO_START,
			    SERVICE_NO_CHANGE,
			    NULL,
			    NULL,
			    NULL,
			    NULL,
			    NULL,
			    NULL,
			    NULL);
			    
  if(!ret){
    last_error = GetLastError();
  }
  CloseServiceHandle(service);
  CloseServiceHandle(scm);
  return ret;
}
开发者ID:0x00evil,项目名称:otp,代码行数:27,代码来源:erlsrv_interactive.c

示例3: set_interactive

static BOOL set_interactive(BOOL interactive){
    SC_HANDLE scm;
    SC_HANDLE service;
    BOOL ret;
    
    if(!open_service_config(&scm,&service))
	return FALSE;

    ret = ChangeServiceConfig(service,
			      SERVICE_WIN32_OWN_PROCESS | ((interactive) ?
			      SERVICE_INTERACTIVE_PROCESS : 0),
			      SERVICE_NO_CHANGE,
			      SERVICE_NO_CHANGE,
			      NULL,
			      NULL,
			      NULL,
			      NULL,
			      NULL,
			      NULL,
			      NULL);
    
    if(!ret){
	last_error = GetLastError();
    }
    CloseServiceHandle(service);
    CloseServiceHandle(scm);
    return ret;
}
开发者ID:0x00evil,项目名称:otp,代码行数:28,代码来源:erlsrv_interactive.c

示例4: set_service_start_type

static void set_service_start_type(SC_HANDLE hSCManager, DWORD start_type)
{
    SC_HANDLE		hService;

	printf("%s service: %-40s ... "
		,start_type==SERVICE_DISABLED ? "Disabling" : "Enabling", TITLE);

    hService = OpenService(hSCManager, NAME, SERVICE_ALL_ACCESS);

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

	if(!ChangeServiceConfig(
		hService,				// handle to service
		SERVICE_NO_CHANGE,		// type of service
		start_type,				// when to start service
		SERVICE_NO_CHANGE,		// severity if service fails to start
		NULL,					// pointer to service binary file name
		NULL,					// pointer to load ordering group name
		NULL,					// pointer to variable to get tag identifier
		NULL,					// pointer to array of dependency names
		NULL,					// pointer to account name of service
		NULL,					// pointer to password for service account
		NULL					// pointer to display name
		))
		printf("\n!ERROR %d changing service config for: %s\n",GetLastError(),NAME);
	else
		printf("Successful\n");

    CloseServiceHandle(hService);
}
开发者ID:K6BSD,项目名称:SBBSUnstable,代码行数:33,代码来源:sexpots.c

示例5: ChangeServiceConfig

/*
 * Class:     sage_WindowsServiceControl
 * Method:    setServiceUser0
 * Signature: (JLjava/lang/String;Ljava/lang/String;)Z
 */
JNIEXPORT jboolean JNICALL Java_sage_WindowsServiceControl_setServiceUser0
  (JNIEnv *env, jobject jo, jlong ptr, jstring juser, jstring jpass)
{
	WinServiceInfo* svcInfo = (WinServiceInfo*) ptr;
	if (!svcInfo) return 0;
	const char* cuser = env->GetStringUTFChars(juser, NULL);
	const char* cpass = env->GetStringUTFChars(jpass, NULL);
	jboolean rv = ChangeServiceConfig(svcInfo->schService, SERVICE_NO_CHANGE, 
		SERVICE_NO_CHANGE, SERVICE_NO_CHANGE,
		NULL, NULL, NULL, NULL, cuser,/*acct*/ cpass/*passwd*/, "SageTV");
	if (rv)
	{
		// Check to make sure this account has logon as service rights and if not, then grant them.
		// If we can't grant them, then popup a warning message about not running this as an administrator
		// Strip the .\ from the beginning of the username if it's there
		char* myUser = (char*)cuser;
		if (myUser[0] == '.' && myUser[1] == '\\')
			myUser = &(myUser[2]);
		if (!CheckSingleUserPriv(myUser, L"SeServiceLogonRight", NULL))
		{
			if (!SetPrivilegeOnAccount(myUser, L"SeServiceLogonRight", TRUE))
			{
				// Failure....but there shouldn't be one since we're logged on as administrator or we wouldn't
				// have gotten here.
			}
		}
	}
	env->ReleaseStringUTFChars(juser, cuser);
	env->ReleaseStringUTFChars(jpass, cpass);
	return rv;
}
开发者ID:BOTCrusher,项目名称:sagetv,代码行数:36,代码来源:WindowsServiceControl.cpp

示例6: enableService

void enableService(const char* szName)
{
	gcWString wName(szName);
	SC_HANDLE scm, Service;
	
	//open connection to SCM
	scm = OpenSCManager(nullptr, nullptr, SC_MANAGER_CONNECT);

	if (!scm)
		throw gcException(ERR_NULLSCMANAGER, GetLastError(), "Failed to open the Service Control Manager");

	//open service
	Service = OpenService(scm, wName.c_str(), SERVICE_CHANGE_CONFIG|SERVICE_QUERY_STATUS);
	if (!Service)
	{
		CloseServiceHandle(scm);
		throw gcException(ERR_NULLSERVICE, GetLastError(), gcString("Failed to open service: {0}", szName));
	}

	BOOL res = ChangeServiceConfig(Service, SERVICE_NO_CHANGE, SERVICE_DEMAND_START, SERVICE_NO_CHANGE, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr);

	CloseServiceHandle(scm);
	CloseServiceHandle(Service); 

	if (!res)
		throw gcException(ERR_SERVICE, GetLastError(), gcString("Failed to to renable service: {0}", szName)); 
}
开发者ID:aromis,项目名称:desura-app,代码行数:27,代码来源:UtilWindows_service.cpp

示例7: throw

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; 
}
开发者ID:huatutest,项目名称:HTTransferService,代码行数:58,代码来源:HTFileTransferSystemService.cpp

示例8: OpenService

   bool
   ServiceManager::_ReconfigureService(SC_HANDLE hSCManager, const String &ServiceName)
   //---------------------------------------------------------------------------//
   // DESCRIPTION:
   // Updates an existing hMailServer service.
   //---------------------------------------------------------------------------//
   {
      // Retrieve the handle for the service.
      SC_HANDLE hService = OpenService( hSCManager, ServiceName,  SERVICE_QUERY_CONFIG | SERVICE_CHANGE_CONFIG);

      
      SC_LOCK sclLock = LockServiceDatabase(hSCManager); 

      if (sclLock == NULL)
      {
         ErrorManager::Instance()->ReportError(ErrorManager::Medium, 5056, "ServiceManager::_ReconfigureService", "Failed to obtain lock on service database.");

         CloseServiceHandle(hService);
         return false;
      }

      // Update the path to the executable
      String sPath;
      sPath = Application::GetExecutableName();
      sPath += " RunAsService";

      if (ChangeServiceConfig(
               hService,        // handle of service 
               SERVICE_NO_CHANGE , // service type: no change 
               SERVICE_NO_CHANGE, // service start type no change
               SERVICE_NO_CHANGE, // error control: no change 
               sPath,            // binary path changed
               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) == 0)             // display name: no change
      {
         String sErrorMessage;
         sErrorMessage.Format(_T("ChangeServiceConfig failed. (%d)"), GetLastError());

         ErrorManager::Instance()->ReportError(ErrorManager::Medium, 5057, "ServiceManager::_ReconfigureService", sErrorMessage);
         return false;
      }

      // Unlock and release.
      CloseServiceHandle(hService); 

      UnlockServiceDatabase(sclLock); 

      CloseServiceHandle (hSCManager);

      return true;
   }
开发者ID:bogri5520,项目名称:hMailServer,代码行数:55,代码来源:ServiceManager.cpp

示例9: DoEnableSvc

//
// Purpose: 
//   Enables the service.
//
// Parameters:
//   None
// 
// Return value:
//   None
//
VOID __stdcall DoEnableSvc()
{
    SC_HANDLE schSCManager;
    SC_HANDLE schService;

    // Get a handle to the SCM database. 
 
    schSCManager = OpenSCManager( 
        NULL,                    // local computer
        NULL,                    // ServicesActive database 
        SC_MANAGER_ALL_ACCESS);  // full access rights 
 
    if (NULL == schSCManager) 
    {
        printf("OpenSCManager failed (%d)\n", GetLastError());
        return;
    }

    // Get a handle to the service.

    schService = OpenService( 
        schSCManager,            // SCM database 
        szSvcName,               // name of service 
        SERVICE_CHANGE_CONFIG);  // need change config access 
 
    if (schService == NULL)
    { 
        printf("OpenService failed (%d)\n", GetLastError()); 
        CloseServiceHandle(schSCManager);
        return;
    }    

    // Change the service start type.

    if (! ChangeServiceConfig( 
        schService,            // handle of service 
        SERVICE_NO_CHANGE,     // service type: no change 
        SERVICE_DEMAND_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) )                // display name: no change
    {
        printf("ChangeServiceConfig failed (%d)\n", GetLastError()); 
    }
    else printf("Service enabled successfully.\n"); 

    CloseServiceHandle(schService); 
    CloseServiceHandle(schSCManager);
}
开发者ID:terryfan1109,项目名称:win32-test,代码行数:64,代码来源:winServiceDemoConfig.cpp

示例10: SetServiceConfig

BOOL
SetServiceConfig(LPQUERY_SERVICE_CONFIG pServiceConfig,
                 LPTSTR lpServiceName,
                 LPTSTR lpPassword)
{
    SC_HANDLE hSCManager;
    SC_HANDLE hSc;
    SC_LOCK scLock;
    BOOL bRet = FALSE;

    hSCManager = OpenSCManager(NULL,
                               NULL,
                               SC_MANAGER_LOCK);
    if (hSCManager)
    {
        scLock = LockServiceDatabase(hSCManager);
        if (scLock)
        {
            hSc = OpenService(hSCManager,
                              lpServiceName,
                              SERVICE_CHANGE_CONFIG);
            if (hSc)
            {
                if (ChangeServiceConfig(hSc,
                                        pServiceConfig->dwServiceType,
                                        pServiceConfig->dwStartType,
                                        pServiceConfig->dwErrorControl,
                                        pServiceConfig->lpBinaryPathName,
                                        pServiceConfig->lpLoadOrderGroup,
                                        pServiceConfig->dwTagId ? &pServiceConfig->dwTagId : NULL,
                                        pServiceConfig->lpDependencies,
                                        pServiceConfig->lpServiceStartName,
                                        lpPassword,
                                        pServiceConfig->lpDisplayName))
                {
                    bRet = TRUE;
                }

                CloseServiceHandle(hSc);
            }

            UnlockServiceDatabase(scLock);
        }

        CloseServiceHandle(hSCManager);
    }

    if (!bRet)
        GetError();

    return bRet;
}
开发者ID:RareHare,项目名称:reactos,代码行数:52,代码来源:query.c

示例11: _setServiceConfig

int _setServiceConfig(LPCTSTR lpServiceName,
					  DWORD dwServiceType,
					  DWORD dwStartType,
					  LPCTSTR lpBinaryPathName,
					  LPCTSTR lpServiceStartName,
					  LPCTSTR lpPassword,
					  LPCTSTR lpDisplayName){
	
	int returnValue = 0;
	
	SC_HANDLE schSCManager;
	SC_HANDLE schService;
	
	schSCManager = OpenSCManager(NULL,
								 SERVICES_ACTIVE_DATABASE, 
								 SC_MANAGER_CONNECT);
	
	if(!schSCManager){
		returnValue = GetLastError();
	}else{
		schService = OpenService( 
								 schSCManager, 
								 lpServiceName,  
								 SERVICE_CHANGE_CONFIG);
		
		if(!schService){	
			returnValue = GetLastError();
		}else{
			if(!ChangeServiceConfig(schService,
									dwServiceType,
									dwStartType,
									SERVICE_NO_CHANGE,
									NULL,	//lpBinaryPathName
									NULL,	//lpLoadOrderGroup
									NULL,	//lpdwTagId
									NULL,	//lpDependencies
									lpServiceStartName,
									lpPassword,
									lpDisplayName)){
				returnValue = GetLastError();
			}
			
			CloseServiceHandle(schService);	
			
		}
		
		CloseServiceHandle(schSCManager);
		
	}
	
	return returnValue;
}
开发者ID:UNIVERSAL-IT-SYSTEMS,项目名称:4d-plugin-windows-services,代码行数:52,代码来源:functions_wnds.cpp

示例12: ChangeServiceLogon

void ChangeServiceLogon(char * username,char * passwd,char * host,char * service)
{
  SC_HANDLE hManager;
  SC_HANDLE hService;
  int queryret,chret;
  QUERY_SERVICE_CONFIG * pServiceConfig;
  DWORD  scLen = 0;
  DWORD scNeedLen;
  DWORD err;

  hManager = OpenActiveManager(host);
  hService = OpenNamedService(hManager,service);

  queryret = QueryServiceConfig(hService,pServiceConfig,scLen,&scNeedLen);

  err = GetLastError();

  if (err != ERROR_INSUFFICIENT_BUFFER && queryret == 0 ){
    fprintf(stderr,"QueryServiceConfig Error\n");
    exit(EXIT_FAILURE);
  }

  pServiceConfig = malloc(scNeedLen);

  if(pServiceConfig == NULL){
    memallocerr();
  }
  
  scLen = scNeedLen;

  queryret = QueryServiceConfig(hService,pServiceConfig,scLen,&scNeedLen);

  /*prepare to call ChangeServiceConfig*/

  chret = ChangeServiceConfig(hService,
			      SERVICE_NO_CHANGE,
			      SERVICE_NO_CHANGE,
			      SERVICE_NO_CHANGE,
			      NULL,
			      NULL,
			      NULL,
			      NULL,
			      username,
			      passwd,
			      NULL);
  if (chret == 0){
    err = GetLastError();
    fprintf(stderr,"ChangeServiceConfig Windows error is: %d\n",err);
    exit(EXIT_FAILURE);
  }

}
开发者ID:zaharovmag,项目名称:win-util,代码行数:52,代码来源:srvcchpw.c

示例13: ATLASSUME

BOOL CNTScmService::ChangeConfig(DWORD dwServiceType,	DWORD dwStartType,
                                 DWORD dwErrorControl, LPCTSTR lpBinaryPathName,
                                 LPCTSTR lpLoadOrderGroup, LPDWORD lpdwTagId,
                                 LPCTSTR lpDependencies, LPCTSTR lpServiceStartName,
                                 LPCTSTR lpPassword, LPCTSTR lpDisplayName) const
{
  //Validate our parameters
  ATLASSUME(m_hService != NULL);
  
  return ChangeServiceConfig(m_hService, dwServiceType, dwStartType,
                             dwErrorControl, lpBinaryPathName, lpLoadOrderGroup, lpdwTagId,
                             lpDependencies, lpServiceStartName, lpPassword, lpDisplayName);
}
开发者ID:CruiseYoung,项目名称:CNTService_NoMFC,代码行数:13,代码来源:ntservScmService.cpp

示例14: suplibOsUpdateService

/**
 * Creates the service.
 *
 * @returns 0 on success.
 * @returns -1 on failure.
 */
static int suplibOsUpdateService(void)
{
    /*
     * Assume it didn't exist, so we'll create the service.
     */
    SC_HANDLE   hSMgr = OpenSCManager(NULL, NULL, SERVICE_CHANGE_CONFIG);
    DWORD LastError = GetLastError(); NOREF(LastError);
    AssertMsg(hSMgr, ("OpenSCManager(,,delete) failed LastError=%Rwa\n", LastError));
    if (hSMgr)
    {
        SC_HANDLE hService = OpenService(hSMgr, SERVICE_NAME, SERVICE_CHANGE_CONFIG);
        if (hService)
        {
            char szDriver[RTPATH_MAX];
            int rc = RTPathExecDir(szDriver, sizeof(szDriver) - sizeof("\\VBoxDrv.sys"));
            if (RT_SUCCESS(rc))
            {
                strcat(szDriver, "\\VBoxDrv.sys");

                SC_LOCK hLock = LockServiceDatabase(hSMgr);
                if (ChangeServiceConfig(hService,
                                        SERVICE_KERNEL_DRIVER,
                                        SERVICE_DEMAND_START,
                                        SERVICE_ERROR_NORMAL,
                                        szDriver,
                                        NULL, NULL, NULL, NULL, NULL, NULL))
                {

                    UnlockServiceDatabase(hLock);
                    CloseServiceHandle(hService);
                    CloseServiceHandle(hSMgr);
                    return 0;
                }
                else
                {
                    DWORD LastError = GetLastError(); NOREF(LastError);
                    AssertMsgFailed(("ChangeServiceConfig failed LastError=%Rwa\n", LastError));
                }
            }
            UnlockServiceDatabase(hLock);
            CloseServiceHandle(hService);
        }
        else
        {
            DWORD LastError = GetLastError(); NOREF(LastError);
            AssertMsgFailed(("OpenService failed LastError=%Rwa\n", LastError));
        }
        CloseServiceHandle(hSMgr);
    }
    return -1;
}
开发者ID:jeppeter,项目名称:vbox,代码行数:57,代码来源:SUPLib-win.cpp

示例15: SetCurrent

void
CBINDInstallDlg::UpdateService(CString StartName) {
	SC_HANDLE hSCManager;
	SC_HANDLE hService;

	if(m_toolsOnly)
		return;

	SetCurrent(IDS_OPEN_SCM);
	hSCManager= OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
	if (!hSCManager) {
		MsgBox(IDS_ERR_OPEN_SCM, GetErrMessage());
		return;
	}

	DWORD dwStart = SERVICE_DEMAND_START;
	if (m_autoStart)
		dwStart = SERVICE_AUTO_START;

	DWORD dwServiceType = SERVICE_WIN32_OWN_PROCESS;

	CString namedLoc;
	namedLoc.Format("%s\\bin\\named.exe", m_targetDir);

	SetCurrent(IDS_OPEN_SERVICE);
	hService = OpenService(hSCManager, BIND_SERVICE_NAME,
			       SERVICE_CHANGE_CONFIG);
	if (!hService)
	{
		MsgBox(IDS_ERR_OPEN_SERVICE, GetErrMessage());
		if (hSCManager)
			CloseServiceHandle(hSCManager);
		return;
	} else {
		if (ChangeServiceConfig(hService, dwServiceType, dwStart,
			SERVICE_ERROR_NORMAL, namedLoc, NULL, NULL, NULL,
			StartName, m_accountPassword, BIND_DISPLAY_NAME)
			!= TRUE) {
			DWORD err = GetLastError();
			MsgBox(IDS_ERR_UPDATE_SERVICE, GetErrMessage());
		}
	}

	if (hService)
		CloseServiceHandle(hService);

	if (hSCManager)
		CloseServiceHandle(hSCManager);

	SetItemStatus(IDC_REG_SERVICE);
}
开发者ID:donnerhacke,项目名称:bind9,代码行数:51,代码来源:BINDInstallDlg.cpp


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