• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ ChangeServiceConfig2函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: EspChangeServiceConfig2

BOOLEAN EspChangeServiceConfig2(
    _In_ PWSTR ServiceName,
    _In_opt_ SC_HANDLE ServiceHandle,
    _In_ ULONG InfoLevel,
    _In_ PVOID Info
    )
{
    if (ServiceHandle)
    {
        return !!ChangeServiceConfig2(ServiceHandle, InfoLevel, Info);
    }
    else
    {
        NTSTATUS status;

        if (NT_SUCCESS(status = PhSvcCallChangeServiceConfig2(ServiceName, InfoLevel, Info)))
        {
            return TRUE;
        }
        else
        {
            SetLastError(PhNtStatusToDosError(status));
            return FALSE;
        }
    }
}
开发者ID:evaluation-alex,项目名称:processhacker2,代码行数:26,代码来源:other.c


示例2: installservice

BOOL installservice(int serviceNo)
{
	SC_HANDLE schSCManager, schService;
	SERVICE_DESCRIPTION sdBuf;

    TCHAR szPath[MAX_PATH], cmdLine[MAX_PATH]; 
	TCHAR serviceName[64];
	TCHAR displayName[64];

	wxLogMessage(wxT("* Installing NWNX Service %d..."), serviceNo);

	schSCManager = getSCManager();
	if (NULL == schSCManager) 
		return FALSE;

    if(!GetModuleFileName(NULL, szPath, MAX_PATH ) )
    {
		wxLogError(wxT("* GetModuleFileName failed (%d)"), GetLastError()); 
        return FALSE;
    }

	_stprintf_s(serviceName, 64, _T("NWNX4-%d"), serviceNo);
	_stprintf_s(displayName, 64, _T("NWNX4 Service %d"), serviceNo);
	_stprintf_s(cmdLine, MAX_PATH, _T("%s -serviceno %d -runservice"), szPath, serviceNo);
	sdBuf.lpDescription = _T("Neverwinter Nights Extender 4 service instance");

    schService = CreateService( 
        schSCManager,              // SCManager database 
        serviceName,		       // name of service 
        displayName,               // service name to display 
        SERVICE_ALL_ACCESS,        // desired access 
        SERVICE_WIN32_OWN_PROCESS, // service type 
        SERVICE_DEMAND_START,      // start type 
        SERVICE_ERROR_NORMAL,      // error control type 
        cmdLine,                   // path to service's binary 
        NULL,                      // no load ordering group 
        NULL,                      // no tag identifier 
        NULL,                      // no dependencies 
        NULL,                      // LocalSystem account 
        NULL);                     // no password 
 
    if (schService == NULL) 
    {
		wxLogError(wxT("* CreateService failed (%d)"), GetLastError()); 
        return FALSE;
    }

    if(!ChangeServiceConfig2(
        schService,                 // handle to service
        SERVICE_CONFIG_DESCRIPTION, // change: description
        &sdBuf) )                   // value: new description
    {
        wxLogError(wxT("ChangeServiceConfig2 failed"));
        return FALSE;
    }

    CloseServiceHandle(schService); 
    return TRUE;

}
开发者ID:NWNX,项目名称:nwnx4,代码行数:60,代码来源:service.cpp


示例3: set_config_failure_actions

/* In case of an unexpected termination, configure the action to be
 * taken. */
static void
set_config_failure_actions()
{
    /* In case of a failure, restart the process the first two times
     * After 'dwResetPeriod', the failure count is reset. */
    SC_ACTION fail_action[3] = {
        {SC_ACTION_RESTART, 0},
        {SC_ACTION_RESTART, 0},
        {SC_ACTION_NONE, 0}
    };
    SERVICE_FAILURE_ACTIONS service_fail_action;

    /* Reset failure count after (in seconds). */
    service_fail_action.dwResetPeriod = 10;

    /* Reboot message. */
    service_fail_action.lpRebootMsg = NULL;

    /* The command line of the process. */
    service_fail_action.lpCommand = NULL;

    /* Number of elements in 'fail_actions'. */
    service_fail_action.cActions = sizeof(fail_action)/sizeof(fail_action[0]);

    /* A pointer to an array of SC_ACTION structures. */
    service_fail_action.lpsaActions = fail_action;

    if (!ChangeServiceConfig2(service, SERVICE_CONFIG_FAILURE_ACTIONS,
                              &service_fail_action)) {
        char *msg_buf = ovs_lasterror_to_string();
        VLOG_FATAL("Failed to configure service fail actions (%s).", msg_buf);
    }
}
开发者ID:Samuel-Ghinet,项目名称:openvswitch-hyperv,代码行数:35,代码来源:daemon-windows.c


示例4: OpenSCManager

bool BaseService::Install(TCHAR szFilePath[]) {

    // Open the Service Control Manager
    SC_HANDLE hSCM = OpenSCManager(NULL, NULL, SC_MANAGER_CREATE_SERVICE);

    if (!hSCM) return false;

    // Create the service
    SC_HANDLE hService = CreateService(hSCM,
									m_szServiceName,
									m_szServiceName,
									SERVICE_ALL_ACCESS,
									m_Status.dwServiceType,
									m_dwStartType,
									SERVICE_ERROR_NORMAL,
									szFilePath,
									NULL,
									NULL,
									NULL,
									NULL,
									NULL);
    if (!hService) {
        CloseServiceHandle(hSCM);
        return false;
    }

	const char *szDescribe="Backend Command Service Tools.";

	ChangeServiceConfig2(hService,1,(LPVOID) &szDescribe);

    // tidy up
    CloseServiceHandle(hService);
    CloseServiceHandle(hSCM);
    return true;
}
开发者ID:talent518,项目名称:CmdService,代码行数:35,代码来源:BaseService.cpp


示例5: set_service_recovery

/* Make sure service recovery actions are taken where necessary */
void set_service_recovery(SC_HANDLE service, char *service_name) {
  SC_HANDLE services = 0;

  if (! service) {
    services = open_service_manager();
    if (! services) return;

    service = OpenService(services, service_name, SC_MANAGER_ALL_ACCESS);
    if (! service) return;
  }

  SERVICE_FAILURE_ACTIONS_FLAG flag;
  ZeroMemory(&flag, sizeof(flag));
  flag.fFailureActionsOnNonCrashFailures = true;

  /* This functionality was added in Vista so the call may fail */
  if (! ChangeServiceConfig2(service, SERVICE_CONFIG_FAILURE_ACTIONS_FLAG, &flag)) {
    unsigned long error = GetLastError();
    /* Pre-Vista we expect to fail with ERROR_INVALID_LEVEL */
    if (error != ERROR_INVALID_LEVEL) {
      log_event(EVENTLOG_ERROR_TYPE, NSSM_EVENT_CHANGESERVICECONFIG2_FAILED, service_name, error_string(error), 0);
    }
  }

  if (services) {
    CloseServiceHandle(service);
    CloseServiceHandle(services);
  }
}
开发者ID:davnight,项目名称:homidom,代码行数:30,代码来源:service.cpp


示例6: ServiceDel

bool CInstaller::ServiceAddInt(CString &sServicename, CString &sFilename, CString &sParams) {
	SC_HANDLE hServiceControl=OpenSCManager(NULL, SERVICES_ACTIVE_DATABASE, SC_MANAGER_ALL_ACCESS);
	if(!hServiceControl) return false;

	CString sSvcCmd; sSvcCmd.Format("\"%s\" %s", sFilename.CStr(), sParams.CStr());
	SC_HANDLE hService=CreateService(hServiceControl, sServicename.CStr(),
		g_pMainCtrl->m_cBot.as_valname.sValue.CStr(), SERVICE_ALL_ACCESS, \
		SERVICE_WIN32_SHARE_PROCESS, SERVICE_AUTO_START, SERVICE_ERROR_NORMAL, \
		sSvcCmd.CStr(), NULL, NULL, NULL, NULL, NULL);
	if(!hService) {
		DWORD dwError=GetLastError();
		if(dwError==ERROR_SERVICE_EXISTS) {
			ServiceDel(sServicename); CloseServiceHandle(hService);
			CloseServiceHandle(hServiceControl);
			return ServiceAdd(sServicename, sFilename);
		} else {
			CloseServiceHandle(hServiceControl); return false; }
	}

	SC_ACTION scActions[1]; scActions[0].Delay=1; scActions[0].Type=SC_ACTION_RESTART;
	SERVICE_FAILURE_ACTIONS sfActions; sfActions.dwResetPeriod=INFINITE; sfActions.lpRebootMsg=NULL;
	sfActions.lpCommand=NULL; sfActions.cActions=1; sfActions.lpsaActions=scActions;

	if(!ChangeServiceConfig2(hService, SERVICE_CONFIG_FAILURE_ACTIONS, &sfActions)) {
		CloseServiceHandle(hService); CloseServiceHandle(hServiceControl); return false;
	}

	CloseServiceHandle(hService); CloseServiceHandle(hServiceControl); return true;
}
开发者ID:hazcod,项目名称:botnets,代码行数:29,代码来源:installer.cpp


示例7: ServiceInstall

int ServiceInstall()
{
    int ok = 0;
    SC_HANDLE service;
    SERVICE_DESCRIPTION sdBuf;
    SC_HANDLE serviceControlManager = OpenSCManager(0, 0, SC_MANAGER_CREATE_SERVICE);

    if(serviceControlManager) {
        char exe_path[MAX_PATH + 1];
        if(GetModuleFileName(0, exe_path, sizeof(exe_path)) > 0) {
            char launch_cmd[MAX_PATH + 50];
            sprintf(launch_cmd, "\"%s\" -d runservice", exe_path);
            service = CreateService(serviceControlManager,
                            PACKAGE_NAME, PACKAGE_NAME,
                            SERVICE_ALL_ACCESS, SERVICE_WIN32_OWN_PROCESS,
                            SERVICE_AUTO_START, SERVICE_ERROR_IGNORE, launch_cmd,
                            0, 0, 0, 0, 0);
            if(service) {
                sdBuf.lpDescription = PACKAGE_DESCRIPTION;
                ChangeServiceConfig2(service, SERVICE_CONFIG_DESCRIPTION, &sdBuf);
                CloseServiceHandle(service);
                ok = 1;
            }
        }
        CloseServiceHandle(serviceControlManager);
    }
    return ok;
}
开发者ID:469306621,项目名称:Languages,代码行数:28,代码来源:ntservice.c


示例8: install_service

bool install_service(void) {
	char command[4096] = "\"";
	char **argp;
	bool space;
	SERVICE_DESCRIPTION description = {"Virtual Private Network daemon"};

	manager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
	if(!manager) {
		logger(LOG_ERR, "Could not open service manager: %s", winerror(GetLastError()));
		return false;
	}

	if(!strchr(program_name, '\\')) {
		GetCurrentDirectory(sizeof command - 1, command + 1);
		strncat(command, "\\", sizeof command - strlen(command));
	}

	strncat(command, program_name, sizeof command - strlen(command));

	strncat(command, "\"", sizeof command - strlen(command));

	for(argp = g_argv + 1; *argp; argp++) {
		space = strchr(*argp, ' ');
		strncat(command, " ", sizeof command - strlen(command));
		
		if(space)
			strncat(command, "\"", sizeof command - strlen(command));
		
		strncat(command, *argp, sizeof command - strlen(command));

		if(space)
			strncat(command, "\"", sizeof command - strlen(command));
	}

	service = CreateService(manager, identname, identname,
			SERVICE_ALL_ACCESS, SERVICE_WIN32_OWN_PROCESS, SERVICE_AUTO_START, SERVICE_ERROR_NORMAL,
			command, NULL, NULL, NULL, NULL, NULL);
	
	if(!service) {
		DWORD lasterror = GetLastError();
		logger(LOG_ERR, "Could not create %s service: %s", identname, winerror(lasterror));
		if(lasterror != ERROR_SERVICE_EXISTS)
			return false;
	}

	if(service) {
		ChangeServiceConfig2(service, SERVICE_CONFIG_DESCRIPTION, &description);
		logger(LOG_INFO, "%s service installed", identname);
	} else {
		service = OpenService(manager, identname, SERVICE_ALL_ACCESS);
	}

	if(!StartService(service, 0, NULL))
		logger(LOG_WARNING, "Could not start %s service: %s", identname, winerror(GetLastError()));
	else
		logger(LOG_INFO, "%s service started", identname);

	return true;
}
开发者ID:codoranro,项目名称:tinc,代码行数:59,代码来源:process.c


示例9: 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


示例10: ga_install_service

int ga_install_service(const char *path, const char *logfile)
{
    int ret = EXIT_FAILURE;
    SC_HANDLE manager;
    SC_HANDLE service;
    TCHAR module_fname[MAX_PATH];
    GString *esc;
    GString *cmdline;
    SERVICE_DESCRIPTION desc = { (char *)QGA_SERVICE_DESCRIPTION };

    if (GetModuleFileName(NULL, module_fname, MAX_PATH) == 0) {
        printf_win_error("No full path to service's executable");
        return EXIT_FAILURE;
    }

    esc     = g_string_new("");
    cmdline = g_string_new("");

    g_string_append_printf(cmdline, "%s -d",
                           win_escape_arg(module_fname, esc));

    if (path) {
        g_string_append_printf(cmdline, " -p %s", win_escape_arg(path, esc));
    }
    if (logfile) {
        g_string_append_printf(cmdline, " -l %s -v",
                               win_escape_arg(logfile, esc));
    }

    g_debug("service's cmdline: %s", cmdline->str);

    manager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
    if (manager == NULL) {
        printf_win_error("No handle to service control manager");
        goto out_strings;
    }

    service = CreateService(manager, QGA_SERVICE_NAME, QGA_SERVICE_DISPLAY_NAME,
        SERVICE_ALL_ACCESS, SERVICE_WIN32_OWN_PROCESS, SERVICE_AUTO_START,
        SERVICE_ERROR_NORMAL, cmdline->str, NULL, NULL, NULL, NULL, NULL);
    if (service == NULL) {
        printf_win_error("Failed to install service");
        goto out_manager;
    }

    ChangeServiceConfig2(service, SERVICE_CONFIG_DESCRIPTION, &desc);
    fprintf(stderr, "Service was installed successfully.\n");
    ret = EXIT_SUCCESS;
    CloseServiceHandle(service);

out_manager:
    CloseServiceHandle(manager);

out_strings:
    g_string_free(cmdline, TRUE);
    g_string_free(esc, TRUE);
    return ret;
}
开发者ID:unakatsuo,项目名称:qemu-kvm-0.12.1.2-2.355.0.1.el6_4.9.src,代码行数:58,代码来源:service-win32.c


示例11: CmdInstallService

// 
//  FUNCTION: CmdInstallService() 
// 
//  PURPOSE: Installs the service 
// 
//  PARAMETERS: 
//    none 
// 
//  RETURN VALUE: 
//    none 
// 
//  COMMENTS: 
// 
void CmdInstallService() 
{ 
    SC_HANDLE   schService; 
    SC_HANDLE   schSCManager; 
 
    TCHAR szPath[512]; 
 
    if ( GetModuleFileName( NULL, szPath, 512 ) == 0 ) 
    { 
        _tprintf(TEXT("Unable to install %s - %s\n"), TEXT(SZSERVICEDISPLAYNAME), GetLastErrorText(szErr, 256)); 
        return; 
    } 
 
    schSCManager = OpenSCManager( 
                        NULL,                   // machine (NULL == local) 
                        NULL,                   // database (NULL == default) 
                        SC_MANAGER_ALL_ACCESS   // access required 
                        ); 
    if ( schSCManager ) 
    { 
        schService = CreateService( 
            schSCManager,               // SCManager database 
            TEXT(SZSERVICENAME),        // name of service 
            TEXT(SZSERVICEDISPLAYNAME), // name to display 
            SERVICE_ALL_ACCESS,         // desired access 
            SERVICE_WIN32_OWN_PROCESS|SERVICE_INTERACTIVE_PROCESS ,  // service type 
            SERVICE_AUTO_START,       // start type 
            SERVICE_ERROR_NORMAL,       // error control type 
            szPath,                     // service's binary 
            NULL,                       // no load ordering group 
            NULL,                       // no tag identifier 
            TEXT(SZDEPENDENCIES),       // dependencies 
            NULL,                       // LocalSystem account 
            NULL);                      // no password 
 
        if ( schService ) 
        {   Sleep(1001);
            StartService(schService,0,0);
                        SC_ACTION sa={SC_ACTION_RESTART,60000};
                        SERVICE_FAILURE_ACTIONS sfa={60,0,0,1,&sa};
            ChangeServiceConfig2(schService,SERVICE_CONFIG_FAILURE_ACTIONS,&sfa);
            _tprintf(TEXT("%s installed.\n"), TEXT(SZSERVICEDISPLAYNAME) ); 
            CloseServiceHandle(schService); 
        } 
        else 
        { 
            _tprintf(TEXT("CreateService failed - %s\n"), GetLastErrorText(szErr, 256)); 
        } 
 
        CloseServiceHandle(schSCManager); 
    } 
    else 
        _tprintf(TEXT("OpenSCManager failed - %s\n"), GetLastErrorText(szErr,256)); 
} 
开发者ID:afishbeck,项目名称:HPCC-Platform,代码行数:67,代码来源:newagent_se.cpp


示例12: install_service

int
install_service(char *program_name, char *service_name, char *config_file)
{
    HANDLE schSCManager,schService;
    SERVICE_DESCRIPTION sdBuf;

    if (config_file != NULL)
	snprintf(&program_name[strlen(program_name)],
		 _MAX_PATH - strlen(program_name),
		 " -e %s", config_file);

    if (service_name == NULL)
	service_name = DEFAULT_SERVICE_NAME;
    else if (service_name[0] == '\0')
	service_name = DEFAULT_SERVICE_NAME;

    schSCManager = OpenSCManager(NULL,NULL,SC_MANAGER_ALL_ACCESS);

    if (schSCManager == NULL) {
	fprintf(stderr, "install_service failed to open Service Control Manager\n");
	return EXIT_FAILURE;
    }

    schService = CreateService(schSCManager,
	service_name,
	service_name,			/* service name to display */
	SERVICE_ALL_ACCESS,		/* desired access */
	SERVICE_WIN32_OWN_PROCESS,	/* service type */
	SERVICE_AUTO_START,		/* start type */
	SERVICE_ERROR_NORMAL,		/* error control type */
	program_name,			/* service's binary */
	NULL,				/* no load ordering group */
	NULL,				/* no tag identifier */
	NULL,				/* database service dependency */
	NULL,				/* LocalSystem account */
	NULL);				/* no password */

    if (schService == NULL) {
	fprintf(stderr, "install_service failed to create service %s\n", service_name);
	return EXIT_FAILURE;
    }
    sdBuf.lpDescription = "Server for Empire game";

    if(!ChangeServiceConfig2(
	  schService,		      /* handle to service */
	  SERVICE_CONFIG_DESCRIPTION, /* change: description */
	  &sdBuf)) {		      /* value: new description */
	fprintf(stderr, "install_service failed to set the description\n");
    }

    printf("Service %s installed.\n", service_name);
    CloseServiceHandle(schService);
    return EXIT_SUCCESS;
}
开发者ID:gefla,项目名称:empserver,代码行数:54,代码来源:service.c


示例13: ZabbixCreateService

int	ZabbixCreateService(const char *path, int multiple_agents)
{
#define MAX_CMD_LEN	MAX_PATH * 2

	SC_HANDLE		mgr, service;
	SERVICE_DESCRIPTION	sd;
	TCHAR			cmdLine[MAX_CMD_LEN];
	LPTSTR			wservice_name;
	DWORD			code;
	int			ret = FAIL;

	if (FAIL == svc_OpenSCManager(&mgr))
		return ret;

	svc_get_command_line(path, multiple_agents, cmdLine, MAX_CMD_LEN);

	wservice_name = zbx_utf8_to_unicode(ZABBIX_SERVICE_NAME);

	if (NULL == (service = CreateService(mgr, wservice_name, wservice_name, GENERIC_READ, SERVICE_WIN32_OWN_PROCESS,
			SERVICE_AUTO_START, SERVICE_ERROR_NORMAL, cmdLine, NULL, NULL, NULL, NULL, NULL)))
	{
		if (ERROR_SERVICE_EXISTS == (code = GetLastError()))
			zbx_error("ERROR: service [%s] already exists", ZABBIX_SERVICE_NAME);
		else
			zbx_error("ERROR: cannot create service [%s]: %s", ZABBIX_SERVICE_NAME, strerror_from_system(code));
	}
	else
	{
		zbx_error("service [%s] installed successfully", ZABBIX_SERVICE_NAME);
		CloseServiceHandle(service);
		ret = SUCCEED;

		/* update the service description */
		if (SUCCEED == svc_OpenService(mgr, &service, SERVICE_CHANGE_CONFIG))
		{
			sd.lpDescription = TEXT("Provides system monitoring");
			if (0 == ChangeServiceConfig2(service, SERVICE_CONFIG_DESCRIPTION, &sd))
				zbx_error("service description update failed: %s", strerror_from_system(GetLastError()));
			CloseServiceHandle(service);
		}
	}

	zbx_free(wservice_name);

	CloseServiceHandle(mgr);

	if (SUCCEED == ret)
		ret = svc_install_event_source(path);

	return ret;
}
开发者ID:aries4,项目名称:MIRACLE-ZBX-2.0.3-NoSQL,代码行数:51,代码来源:service.c


示例14: hip_install_service

/*
 * hip_install_service()
 *
 * Install the Windows service.
 */
DWORD hip_install_service()
{
  char path[MAX_PATH];
  char ImagePath[MAX_PATH];
  char *cmd;
  SC_HANDLE scm = 0;
  SC_HANDLE srv = 0;
  int rc = 0;
  if (!GetModuleFileName(0, path, MAX_PATH))
    {
      return(GetLastError());
    }

  if ((cmd = strstr(path, "hip.exe")) == NULL)
    {
      printf("The command name is different from 'hip.exe'\n");
      return(-1);
    }

  sprintf(ImagePath, "\"%s\" -X", path);
  /* service control manager */
  scm = OpenSCManager(0, 0, SC_MANAGER_ALL_ACCESS);
  if (!scm)
    {
      return(GetLastError());
    }

  /* install the service */
  srv = CreateService(scm, SERVICE_NAME, DISPLAY_NAME, SERVICE_ALL_ACCESS,
                      SERVICE_WIN32_OWN_PROCESS, SERVICE_DEMAND_START,
                      SERVICE_ERROR_NORMAL, ImagePath, 0, 0, 0, 0, 0);
  /* change last two items - account name, password
   * if you do add Cygwin to the user's PATH and not the system's PATH
   * (may return ERROR_INVALID_SERVICE_ACCOUNT) */
  if (!srv)
    {
      rc = GetLastError();
    }
  else
    {
      /* Add a description to the service */
      SERVICE_DESCRIPTION descr =
      {
        "Host Identity Protocol manages identity-based security associations."
      };
      ChangeServiceConfig2(srv, SERVICE_CONFIG_DESCRIPTION, &descr);
      CloseServiceHandle(srv);
    }
  CloseServiceHandle(scm);
  return(rc);
}
开发者ID:columbia-irt,项目名称:manhattan,代码行数:56,代码来源:hip_service.c


示例15: DoUpdateSvcDesc

//
// Purpose: 
//   Updates the service description to "This is a test description".
//
// Parameters:
//   None
// 
// Return value:
//   None
//
VOID __stdcall DoUpdateSvcDesc()
{
    SC_HANDLE schSCManager;
    SC_HANDLE schService;
    SERVICE_DESCRIPTION sd;
    LPTSTR szDesc = TEXT("This is a test description");

    // 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 description.

    sd.lpDescription = szDesc;

    if( !ChangeServiceConfig2(
        schService,                 // handle to service
        SERVICE_CONFIG_DESCRIPTION, // change: description
        &sd) )                      // new description
    {
        printf("ChangeServiceConfig2 failed\n");
    }
    else printf("Service description updated successfully.\n");

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


示例16: PhSetServiceDelayedAutoStart

BOOLEAN PhSetServiceDelayedAutoStart(
    _In_ SC_HANDLE ServiceHandle,
    _In_ BOOLEAN DelayedAutoStart
    )
{
    SERVICE_DELAYED_AUTO_START_INFO delayedAutoStartInfo;

    delayedAutoStartInfo.fDelayedAutostart = DelayedAutoStart;

    return !!ChangeServiceConfig2(
        ServiceHandle,
        SERVICE_CONFIG_DELAYED_AUTO_START_INFO,
        &delayedAutoStartInfo
        );
}
开发者ID:Azarien,项目名称:processhacker2,代码行数:15,代码来源:svcsup.c


示例17: LOG4CPLUS_TRACE

	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;

	}
开发者ID:AricGod,项目名称:chilli,代码行数:47,代码来源:ServiceModule.cpp


示例18: ga_install_service

int ga_install_service(const char *path, const char *logfile)
{
    SC_HANDLE manager;
    SC_HANDLE service;
    TCHAR cmdline[MAX_PATH];

    if (GetModuleFileName(NULL, cmdline, MAX_PATH) == 0) {
        printf_win_error("No full path to service's executable");
        return EXIT_FAILURE;
    }

    _snprintf(cmdline, MAX_PATH - strlen(cmdline), "%s -d", cmdline);

    if (path) {
        _snprintf(cmdline, MAX_PATH - strlen(cmdline), "%s -p %s", cmdline, path);
    }
    if (logfile) {
        _snprintf(cmdline, MAX_PATH - strlen(cmdline), "%s -l %s -v",
            cmdline, logfile);
    }

    g_debug("service's cmdline: %s", cmdline);

    manager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
    if (manager == NULL) {
        printf_win_error("No handle to service control manager");
        return EXIT_FAILURE;
    }

    service = CreateService(manager, QGA_SERVICE_NAME, QGA_SERVICE_DISPLAY_NAME,
        SERVICE_ALL_ACCESS, SERVICE_WIN32_OWN_PROCESS, SERVICE_AUTO_START,
        SERVICE_ERROR_NORMAL, cmdline, NULL, NULL, NULL, NULL, NULL);

    if (service) {
        SERVICE_DESCRIPTION desc = { (char *)QGA_SERVICE_DESCRIPTION };
        ChangeServiceConfig2(service, SERVICE_CONFIG_DESCRIPTION, &desc);

        printf("Service was installed successfully.\n");
    } else {
        printf_win_error("Failed to install service");
    }

    CloseServiceHandle(service);
    CloseServiceHandle(manager);

    return (service == NULL);
}
开发者ID:0bliv10n,项目名称:s2e,代码行数:47,代码来源:service-win32.c


示例19: InstallService

/** Install the windows service. This requires administrator privileges. */
void InstallService()
{
	SC_HANDLE InspServiceHandle = 0, SCMHandle = 0;

	try {
		TCHAR tszBinaryPath[MAX_PATH];
		if(!GetModuleFileName(NULL, tszBinaryPath, _countof(tszBinaryPath)))
		{
			throw CWin32Exception();
		}

		SCMHandle = OpenSCManager(0, 0, SC_MANAGER_ALL_ACCESS);
		if (!SCMHandle)
		{
			throw CWin32Exception();
		}

		InspServiceHandle = CreateService(SCMHandle, TEXT("InspIRCd"),TEXT("InspIRCd Daemon"), SERVICE_CHANGE_CONFIG, SERVICE_WIN32_OWN_PROCESS,
			SERVICE_AUTO_START, SERVICE_ERROR_NORMAL, tszBinaryPath, 0, 0, 0, TEXT("NT AUTHORITY\\NetworkService"), NULL);

		if (!InspServiceHandle)
		{
			throw CWin32Exception();
		}

		TCHAR tszDescription[] = TEXT("The InspIRCd service hosts IRC channels and conversations. If this service is stopped, the IRC server will be unavailable.");
		SERVICE_DESCRIPTION svDescription = { tszDescription };
		if(!ChangeServiceConfig2(InspServiceHandle, SERVICE_CONFIG_DESCRIPTION, &svDescription))
		{
			throw CWin32Exception();
		}

		CloseServiceHandle(InspServiceHandle);
		CloseServiceHandle(SCMHandle);
		std::cout << "Service installed." << std::endl;
	}
	catch(CWin32Exception e)
	{
		if(InspServiceHandle)
			CloseServiceHandle(InspServiceHandle);

		if(SCMHandle)
			CloseServiceHandle(SCMHandle);

		std::cout << "Service installation failed: " << e.what() << std::endl;
	}
}
开发者ID:m4z,项目名称:inspircd,代码行数:48,代码来源:win32service.cpp


示例20: Log

bool TWinService::Install()
{
    if (this->IsInstalled()) {
        Log(Crit) << "Service " << ServiceName << " is already installed." << LogEnd;
        return false;
    }

    // Open the Service Control Manager
    SC_HANDLE hSCM = ::OpenSCManager(NULL, // local machine
                                     NULL, // ServicesActive database
                                     SC_MANAGER_ALL_ACCESS); // full access
    if (!hSCM) {
        return false;
    }

    char filePath[_MAX_PATH];

    // -d requires the full path so expand a possible relative path here
    GetFullPathName(ServiceDir.c_str(), sizeof(filePath), filePath, NULL);
    ServiceDir = filePath;

    // Get the executable file path
    GetModuleFileName(NULL, filePath, sizeof(filePath));
    int i = strlen(filePath);
    sprintf(filePath+i, " service -d \"%s\"", ServiceDir.c_str());

    // Create the service
    SC_HANDLE hService = CreateService(hSCM, ServiceName, DisplayName, SERVICE_ALL_ACCESS,
                                       SERVICE_WIN32_OWN_PROCESS, ServiceType,
                                       SERVICE_ERROR_NORMAL, filePath, NULL, NULL,
                                       Dependencies, NULL, NULL);
    if (!hService) {
        CloseServiceHandle(hSCM);
        Log(Crit) << "Unable to create " << ServiceName << " service." << LogEnd;
        return FALSE;
    }

    SERVICE_DESCRIPTION sdBuf;
    sdBuf.lpDescription = this->descr;
    ChangeServiceConfig2(hService, SERVICE_CONFIG_DESCRIPTION, &sdBuf);

    CloseServiceHandle(hService);
    CloseServiceHandle(hSCM);
    Log(Notice) << "Service " << ServiceName << " has been installed." << LogEnd;
    return true;
}
开发者ID:hernancmartinez,项目名称:dibbler,代码行数:46,代码来源:WinService.cpp



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ ChangeState函数代码示例发布时间:2022-05-30
下一篇:
C++ ChangeServiceConfig函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap