本文整理汇总了C++中ChangeServiceConfig2函数的典型用法代码示例。如果您正苦于以下问题:C++ ChangeServiceConfig2函数的具体用法?C++ ChangeServiceConfig2怎么用?C++ ChangeServiceConfig2使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ChangeServiceConfig2函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
}
}
示例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;
}
示例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);
}
}
示例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;
}
示例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);
}
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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));
}
示例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;
}
示例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;
}
示例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);
}
示例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);
}