本文整理汇总了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;
}
示例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;
}
示例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;
}
示例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);
}
示例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;
}
示例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));
}
示例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;
}
示例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;
}
示例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);
}
示例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;
}
示例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;
}
示例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);
}
}
示例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);
}
示例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;
}
示例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);
}