本文整理汇总了C++中OpenServiceW函数的典型用法代码示例。如果您正苦于以下问题:C++ OpenServiceW函数的具体用法?C++ OpenServiceW怎么用?C++ OpenServiceW使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了OpenServiceW函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: UnregisterDriver
BOOL
UnregisterDriver(LPCWSTR lpDriverName)
{
SC_HANDLE hService;
SC_HANDLE hSCManager;
BOOL bRet;
hSCManager = OpenSCManagerW(NULL,
NULL,
SC_MANAGER_ALL_ACCESS);
if (!hSCManager)
return FALSE;
hService = OpenServiceW(hSCManager,
lpDriverName,
SERVICE_ALL_ACCESS);
if (!hService)
{
CloseServiceHandle(hSCManager);
return FALSE;
}
bRet = DeleteService(hService);
CloseServiceHandle(hService);
CloseServiceHandle(hSCManager);
return bRet;
}
开发者ID:GYGit,项目名称:reactos,代码行数:29,代码来源:umode.c
示例2: SvcUninstall
VOID SvcUninstall() {
SC_HANDLE schSCManager = OpenSCManagerW(NULL, NULL, SC_MANAGER_ALL_ACCESS);
if (NULL == schSCManager) {
printf(">> OpenSCManager failed (LastError=0x%x)\n", GetLastError());
goto _ret;
}
SC_HANDLE schService = OpenServiceW(schSCManager, SERVICE_NAME, SERVICE_ALL_ACCESS);
if (schService == NULL) {
DWORD LastError = GetLastError();
if (LastError == ERROR_SERVICE_DOES_NOT_EXIST) printf(">> Service does not exist!\n");
else printf(">> OpenServiceW failed (LastError=0x%x)\n", GetLastError());
goto _close_sc;
}
SERVICE_STATUS ServiceStatus;
if (!ControlService(schService, SERVICE_CONTROL_STOP, &ServiceStatus)) {
DWORD LastError = GetLastError();
if (LastError != ERROR_SERVICE_NOT_ACTIVE) {
printf(">> ControlService(..., SERVICE_STOP, ...) failed (LastError=0x%x)\n", GetLastError());
goto _close_service;
}
}
if (!DeleteService(schService)) {
printf(">> DeleteService failed (LastError=0x%x)\n", GetLastError());
goto _close_service;
}
printf(">> Service uninstalled successfully!\n");
_close_service:
CloseServiceHandle(schService);
_close_sc:
CloseServiceHandle(schSCManager);
_ret:
return;
}
开发者ID:VMXh,项目名称:DevAclSrv,代码行数:33,代码来源:service.cpp
示例3: hSCManager
// Determine if the autodial service is running on this PC.
bool nsAutodial::IsAutodialServiceRunning()
{
nsAutoServiceHandle hSCManager(OpenSCManager(nullptr,
SERVICES_ACTIVE_DATABASE,
SERVICE_QUERY_STATUS));
if (hSCManager == nullptr)
{
LOGE(("Autodial: failed to open service control manager. Error %d.",
::GetLastError()));
return false;
}
nsAutoServiceHandle hService(OpenServiceW(hSCManager,
L"RasAuto",
SERVICE_QUERY_STATUS));
if (hSCManager == nullptr)
{
LOGE(("Autodial: failed to open RasAuto service."));
return false;
}
SERVICE_STATUS status;
if (!QueryServiceStatus(hService, &status))
{
LOGE(("Autodial: ::QueryServiceStatus() failed. Error: %d",
::GetLastError()));
return false;
}
return (status.dwCurrentState == SERVICE_RUNNING);
}
开发者ID:Jar-win,项目名称:Waterfox,代码行数:36,代码来源:nsAutodialWin.cpp
示例4: UpdateServiceStatus
BOOL
UpdateServiceStatus(ENUM_SERVICE_STATUS_PROCESS* pService)
{
SC_HANDLE hScm;
BOOL bRet = FALSE;
hScm = OpenSCManagerW(NULL,
NULL,
SC_MANAGER_ENUMERATE_SERVICE);
if (hScm != NULL)
{
SC_HANDLE hService;
hService = OpenServiceW(hScm,
pService->lpServiceName,
SERVICE_QUERY_STATUS);
if (hService)
{
DWORD size;
QueryServiceStatusEx(hService,
SC_STATUS_PROCESS_INFO,
(LPBYTE)&pService->ServiceStatusProcess,
sizeof(SERVICE_STATUS_PROCESS),
&size);
CloseServiceHandle(hService);
bRet = TRUE;
}
CloseServiceHandle(hScm);
}
return bRet;
}
开发者ID:Strongc,项目名称:reactos,代码行数:35,代码来源:query.c
示例5: register_service
static HRESULT register_service(BOOL do_register)
{
static const WCHAR name[] = { 'B','I','T','S', 0 };
static const WCHAR path[] = { 's','v','c','h','o','s','t','.','e','x','e',
' ','-','k',' ','n','e','t','s','v','c','s', 0 };
SC_HANDLE scm, service;
scm = OpenSCManagerW(NULL, NULL, SC_MANAGER_ALL_ACCESS);
if (!scm)
return SELFREG_E_CLASS;
if (do_register)
service = CreateServiceW(scm, name, name, SERVICE_ALL_ACCESS,
SERVICE_WIN32_OWN_PROCESS,
SERVICE_DEMAND_START, SERVICE_ERROR_NORMAL,
path, NULL, NULL, NULL, NULL, NULL);
else
service = OpenServiceW(scm, name, DELETE);
CloseServiceHandle(scm);
if (service)
{
if (!do_register) DeleteService(service);
CloseServiceHandle(service);
}
return S_OK;
}
开发者ID:WASSUM,项目名称:longene_travel,代码行数:28,代码来源:qmgr_main.c
示例6: DoUnregServer
static DWORD DoUnregServer(void)
{
static const WCHAR msiserverW[] = {'M','S','I','S','e','r','v','e','r',0};
SC_HANDLE scm, service;
DWORD ret = 0;
if (!(scm = OpenSCManagerW(NULL, SERVICES_ACTIVE_DATABASEW, SC_MANAGER_CONNECT)))
{
fprintf(stderr, "Failed to open service control manager\n");
return 1;
}
if ((service = OpenServiceW(scm, msiserverW, DELETE)))
{
if (!DeleteService(service))
{
fprintf(stderr, "Failed to delete MSI service\n");
ret = 1;
}
CloseServiceHandle(service);
}
else if (GetLastError() != ERROR_SERVICE_DOES_NOT_EXIST)
{
fprintf(stderr, "Failed to open MSI service\n");
ret = 1;
}
CloseServiceHandle(scm);
return ret;
}
开发者ID:AlexSteel,项目名称:wine,代码行数:28,代码来源:msiexec.c
示例7: StopService
static BOOL StopService(SC_HANDLE SCManager, SC_HANDLE serviceHandle)
{
LPENUM_SERVICE_STATUSW dependencies = NULL;
DWORD buffer_size = 0;
DWORD count = 0, counter;
BOOL result;
SC_HANDLE dependent_serviceHandle;
SERVICE_STATUS_PROCESS ssp;
result = EnumDependentServicesW(serviceHandle, SERVICE_ACTIVE, dependencies, buffer_size, &buffer_size, &count);
if(!result && (GetLastError() == ERROR_MORE_DATA))
{
dependencies = HeapAlloc(GetProcessHeap(), 0, buffer_size);
if(EnumDependentServicesW(serviceHandle, SERVICE_ACTIVE, dependencies, buffer_size, &buffer_size, &count))
{
for(counter = 0; counter < count; counter++)
{
output_string(STRING_STOP_DEP, dependencies[counter].lpDisplayName);
dependent_serviceHandle = OpenServiceW(SCManager, dependencies[counter].lpServiceName, SC_MANAGER_ALL_ACCESS);
if(dependent_serviceHandle) result = StopService(SCManager, dependent_serviceHandle);
CloseServiceHandle(dependent_serviceHandle);
if(!result) output_string(STRING_CANT_STOP, dependencies[counter].lpDisplayName);
}
}
}
if(result) result = ControlService(serviceHandle, SERVICE_CONTROL_STOP, (LPSERVICE_STATUS)&ssp);
HeapFree(GetProcessHeap(), 0, dependencies);
return result;
}
开发者ID:aragaer,项目名称:wine,代码行数:31,代码来源:net.c
示例8: cs
BOOL DrvCtrl::LoadWdmInf(WCHAR *inf, WCHAR* szDrvSvcName)
{
WCHAR exe[] = L"c:\\windows\\system32\\InfDefaultInstall.exe ";
STARTUPINFOW si = { 0 };
PROCESS_INFORMATION pi = { 0 };
WCHAR *cmd = cs(exe, inf);
if (!CreateProcessW(NULL, cmd, NULL, NULL, 0, 0, NULL, NULL, &si, &pi))
return FALSE;
WaitForSingleObject(pi.hProcess, INFINITE);
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);
SC_HANDLE hSCM = OpenSCManagerW(NULL, NULL, SC_MANAGER_ALL_ACCESS);
SC_HANDLE hSvcHandle = OpenServiceW(hSCM, szDrvSvcName, SERVICE_ALL_ACCESS);
if (hSvcHandle)
{
CloseServiceHandle(hSCM);
CloseServiceHandle(hSvcHandle);
return TRUE;
}
else
{
CloseServiceHandle(hSCM);
return FALSE;
}
}
开发者ID:FlyRabbit,项目名称:WinProject,代码行数:26,代码来源:DrvCtrl.cpp
示例9: OpenSCManagerW
void Service::uninstall()
{
// Open service manager
SC_HANDLE hSCM = OpenSCManagerW( nullptr, nullptr,
SC_MANAGER_CREATE_SERVICE );
if ( !hSCM )
EXCEPT_WINAPI( L"Couldn't open service manager" );
// Open service for query + deletion
SC_HANDLE hService = OpenServiceW( hSCM, mName.c_str(),
SERVICE_QUERY_STATUS | DELETE );
if ( !hService )
EXCEPT_WINAPI( L"Couldn't open service" );
// Make sure it's stopped
SERVICE_STATUS stStatus;
if ( !QueryServiceStatus( hService, &stStatus ) )
EXCEPT_WINAPI( L"Couldn't query service status" );
if ( stStatus.dwCurrentState != SERVICE_STOPPED )
EXCEPT( L"Cannot uninstall service while it's running" );
// Delete service
if ( !DeleteService( hService ) )
EXCEPT_WINAPI( L"Couldn't delete service" );
// Done
CloseServiceHandle( hService );
CloseServiceHandle( hSCM );
}
开发者ID:noorus,项目名称:snowpack,代码行数:29,代码来源:Service.cpp
示例10: IsServiceInstalled
/**
* Determines if the specified service exists or not
*
* @param serviceName The name of the service to check
* @param exists Whether or not the service exists
* @return TRUE if there were no errors
*/
static BOOL
IsServiceInstalled(LPCWSTR serviceName, BOOL &exists)
{
exists = FALSE;
// Get a handle to the local computer SCM database with full access rights.
SC_HANDLE serviceManager = OpenSCManager(NULL, NULL,
SC_MANAGER_ENUMERATE_SERVICE);
if (!serviceManager) {
return FALSE;
}
SC_HANDLE serviceHandle = OpenServiceW(serviceManager,
serviceName,
SERVICE_QUERY_CONFIG);
if (!serviceHandle && GetLastError() != ERROR_SERVICE_DOES_NOT_EXIST) {
CloseServiceHandle(serviceManager);
return FALSE;
}
if (serviceHandle) {
CloseServiceHandle(serviceHandle);
exists = TRUE;
}
CloseServiceHandle(serviceManager);
return TRUE;
}
开发者ID:Anachid,项目名称:mozilla-central,代码行数:35,代码来源:Services.cpp
示例11: IsStopService
BOOL IsStopService(LPCWSTR lpcwszName)
{
BOOL bRet = FALSE;
SC_HANDLE hScm = NULL;
SC_HANDLE hSrv = NULL;
hScm = OpenSCManagerW(0, 0, SC_MANAGER_CONNECT);
if(hScm == NULL){
OutputDebugString(_T("OpenSCManager failed"));
return FALSE;
}
hSrv = OpenServiceW(hScm, lpcwszName, SERVICE_QUERY_STATUS);
if(hSrv == NULL){
OutputDebugString(_T("OpenService failed"));
CloseServiceHandle(hScm);
return FALSE;
}
SERVICE_STATUS stStatus;
if( QueryServiceStatus(hSrv, &stStatus) != FALSE ){
if(stStatus.dwCurrentState == SERVICE_STOPPED){
bRet = TRUE;
}
}else{
OutputDebugString(_T("QueryServiceStatus failed"));
}
CloseServiceHandle(hSrv);
CloseServiceHandle(hScm);
return bRet;
}
开发者ID:abt8WG,项目名称:EDCB,代码行数:30,代码来源:ServiceUtil.cpp
示例12: GetServiceStatus
DWORD GetServiceStatus(LPCWSTR lpcwszName)
{
SC_HANDLE hScm = NULL;
SC_HANDLE hSrv = NULL;
SERVICE_STATUS stStatus;
hScm = OpenSCManagerW(0, 0, SC_MANAGER_CONNECT);
if(hScm == NULL){
OutputDebugString(_T("OpenSCManager failed"));
return FALSE;
}
hSrv = OpenServiceW(hScm, lpcwszName, SERVICE_QUERY_STATUS);
if(hSrv == NULL){
OutputDebugString(_T("OpenService failed"));
CloseServiceHandle(hScm);
return FALSE;
}
if(QueryServiceStatus(hSrv, &stStatus) == FALSE ){
OutputDebugString(_T("QueryServiceStatus failed"));
CloseServiceHandle(hSrv);
CloseServiceHandle(hScm);
return FALSE;
}
DWORD dwStatus = stStatus.dwCurrentState;
return dwStatus;
}
开发者ID:ACUVE,项目名称:EDCB,代码行数:26,代码来源:ServiceUtil.cpp
示例13: SvcInstall
//
// Purpose:
// Installs a service in the SCM database
//
// Parameters:
// None
//
// Return value:
// None
//
BOOL SvcInstall()
{
SC_HANDLE schSCManager;
SC_HANDLE schService;
WCHAR szPath[MAX_PATH];
if( !GetModuleFileNameW( NULL, szPath, MAX_PATH ) )
{
return FALSE;
}
// 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)
{
return FALSE;
}
// Create the service
schService = CreateServiceW(
schSCManager, // SCM database
SVCNAME, // name of service
SVCNAME, // 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
szPath, // 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) {
schService = OpenServiceW(schSCManager,SVCNAME,SERVICE_ALL_ACCESS);
if(schService == NULL){
CloseServiceHandle(schSCManager);
return FALSE;
}
}
if(!Install::Install()){
CloseServiceHandle(schService);
CloseServiceHandle(schSCManager);
return FALSE;
}
if(!StartService(schService,0,NULL))
return FALSE;
CloseServiceHandle(schService);
CloseServiceHandle(schSCManager);
return TRUE;
}
开发者ID:variantf,项目名称:vJudgeKernel,代码行数:69,代码来源:Judge.cpp
示例14: install
//---------------------------------------------------------------------------
Service & Service::install(SC_HANDLE hSCManager)
{
install();
utf8::WideString serviceNameW(serviceName_.getUNICODEString());
utf8::WideString displayNameW(displayName_.getUNICODEString());
utf8::WideString binaryPathNameW((!args_.isNull() ? binaryPathName_ + args_ : binaryPathName_).getUNICODEString());
utf8::WideString loadOrderGroupW(loadOrderGroup_.getUNICODEString());
utf8::WideString dependenciesW(dependencies_.getUNICODEString());
utf8::WideString serviceStartNameW(serviceStartName_.getUNICODEString());
utf8::WideString passwordW(password_.getUNICODEString());
SC_HANDLE handle = CreateServiceW(
hSCManager,
serviceNameW,
displayNameW,
SERVICE_ALL_ACCESS,
serviceType_,
startType_,
errorControl_,
binaryPathNameW,
!loadOrderGroup_.isNull() ? (wchar_t *) loadOrderGroupW : NULL,
(serviceType_ == SERVICE_KERNEL_DRIVER || serviceType_ == SERVICE_FILE_SYSTEM_DRIVER) &&
(startType_ == SERVICE_BOOT_START || startType_ == SERVICE_SYSTEM_START) ?
&tagId_ : NULL,
!dependencies_.isNull() ? (wchar_t *) dependenciesW : NULL,
!serviceStartName_.isNull() ? (wchar_t *) serviceStartNameW : NULL,
!password_.isNull() ? (wchar_t *) passwordW : NULL
);
if( handle == NULL ){
int32_t err = GetLastError();
if( err == ERROR_SERVICE_EXISTS ){
SetLastError(err = ERROR_SUCCESS);
handle = OpenServiceW(hSCManager,serviceNameW,SERVICE_ALL_ACCESS);
if( handle == NULL ||
ChangeServiceConfigW(handle,
serviceType_,
startType_,
errorControl_,
binaryPathNameW,
!loadOrderGroup_.isNull() ? (wchar_t *) loadOrderGroupW : NULL,
(serviceType_ == SERVICE_KERNEL_DRIVER || serviceType_ == SERVICE_FILE_SYSTEM_DRIVER) &&
(startType_ == SERVICE_BOOT_START || startType_ == SERVICE_SYSTEM_START) ?
&tagId_ : NULL,
!dependencies_.isNull() ? (wchar_t *) dependenciesW : NULL,
!serviceStartName_.isNull() ? (wchar_t *) serviceStartNameW : NULL,
!password_.isNull() ? (wchar_t *) passwordW : NULL,
displayNameW
) == 0 ) err = GetLastError();
}
if( err != ERROR_SUCCESS ){
if( handle != NULL ) CloseServiceHandle(handle);
newObjectV1C2<Exception>(err + errorOffset,__PRETTY_FUNCTION__)->throwSP();
}
}
CloseServiceHandle(handle);
return *this;
}
开发者ID:BackupTheBerlios,项目名称:macroscope-svn,代码行数:57,代码来源:service.cpp
示例15: test_service
static void test_service(void)
{
static const WCHAR spooler[] = {'S','p','o','o','l','e','r',0};
static const WCHAR dummyW[] = {'d','u','m','m','y',0};
SERVICE_STATUS_PROCESS status;
SC_HANDLE scm, service;
IShellDispatch2 *sd;
DWORD dummy;
HRESULT hr;
BSTR name;
VARIANT v;
hr = CoCreateInstance(&CLSID_Shell, NULL, CLSCTX_INPROC_SERVER,
&IID_IShellDispatch2, (void**)&sd);
if (hr != S_OK)
{
win_skip("IShellDispatch2 not supported\n");
return;
}
V_VT(&v) = VT_I2;
V_I2(&v) = 10;
hr = IShellDispatch2_IsServiceRunning(sd, NULL, &v);
ok(V_VT(&v) == VT_BOOL, "got %d\n", V_VT(&v));
ok(V_BOOL(&v) == VARIANT_FALSE, "got %d\n", V_BOOL(&v));
EXPECT_HR(hr, S_OK);
scm = OpenSCManagerW(NULL, NULL, SC_MANAGER_CONNECT);
service = OpenServiceW(scm, spooler, SERVICE_QUERY_STATUS);
QueryServiceStatusEx(service, SC_STATUS_PROCESS_INFO, (BYTE *)&status, sizeof(SERVICE_STATUS_PROCESS), &dummy);
CloseServiceHandle(service);
CloseServiceHandle(scm);
/* service should exist */
name = SysAllocString(spooler);
V_VT(&v) = VT_I2;
hr = IShellDispatch2_IsServiceRunning(sd, name, &v);
EXPECT_HR(hr, S_OK);
ok(V_VT(&v) == VT_BOOL, "got %d\n", V_VT(&v));
if (status.dwCurrentState == SERVICE_RUNNING)
ok(V_BOOL(&v) == VARIANT_TRUE, "got %d\n", V_BOOL(&v));
else
ok(V_BOOL(&v) == VARIANT_FALSE, "got %d\n", V_BOOL(&v));
SysFreeString(name);
/* service doesn't exist */
name = SysAllocString(dummyW);
V_VT(&v) = VT_I2;
hr = IShellDispatch2_IsServiceRunning(sd, name, &v);
EXPECT_HR(hr, S_OK);
ok(V_VT(&v) == VT_BOOL, "got %d\n", V_VT(&v));
ok(V_BOOL(&v) == VARIANT_FALSE, "got %d\n", V_BOOL(&v));
SysFreeString(name);
IShellDispatch2_Release(sd);
}
开发者ID:Kelimion,项目名称:wine,代码行数:56,代码来源:shelldispatch.c
示例16: net_service
static BOOL net_service(int operation, const WCHAR* service_name)
{
SC_HANDLE SCManager, serviceHandle;
BOOL result = 0;
WCHAR service_display_name[4096];
DWORD buffer_size;
SCManager = OpenSCManagerW(NULL, NULL, SC_MANAGER_ALL_ACCESS);
if(!SCManager)
{
output_string(STRING_NO_SCM);
return FALSE;
}
serviceHandle = OpenServiceW(SCManager, service_name, SC_MANAGER_ALL_ACCESS);
if(!serviceHandle)
{
output_string(STRING_NO_SVCHANDLE);
CloseServiceHandle(SCManager);
return FALSE;
}
buffer_size = sizeof(service_display_name)/sizeof(*service_display_name);
GetServiceDisplayNameW(SCManager, service_name, service_display_name, &buffer_size);
if (!service_display_name[0]) lstrcpyW(service_display_name, service_name);
switch(operation)
{
case NET_START:
output_string(STRING_START_SVC, service_display_name);
result = StartServiceW(serviceHandle, 0, NULL);
if(result) output_string(STRING_START_SVC_SUCCESS, service_display_name);
else
{
if (!output_error_string(GetLastError()))
output_string(STRING_START_SVC_FAIL, service_display_name);
}
break;
case NET_STOP:
output_string(STRING_STOP_SVC, service_display_name);
result = StopService(SCManager, serviceHandle);
if(result) output_string(STRING_STOP_SVC_SUCCESS, service_display_name);
else
{
if (!output_error_string(GetLastError()))
output_string(STRING_STOP_SVC_FAIL, service_display_name);
}
break;
}
CloseServiceHandle(serviceHandle);
CloseServiceHandle(SCManager);
return result;
}
开发者ID:aragaer,项目名称:wine,代码行数:55,代码来源:net.c
示例17: defined
bool WinService::tryOpen() const
{
#if defined(POCO_WIN32_UTF8)
std::wstring uname;
Poco::UnicodeConverter::toUTF16(_name, uname);
_svcHandle = OpenServiceW(_scmHandle, uname.c_str(), SERVICE_ALL_ACCESS);
#else
_svcHandle = OpenService(_scmHandle, _name.c_str(), SERVICE_ALL_ACCESS);
#endif
return _svcHandle != 0;
}
开发者ID:beneon,项目名称:MITK,代码行数:11,代码来源:WinService.cpp
示例18: EnableUserModePnpManager
static BOOL
EnableUserModePnpManager(VOID)
{
SC_HANDLE hSCManager = NULL;
SC_HANDLE hService = NULL;
BOOL bRet = FALSE;
hSCManager = OpenSCManagerW(NULL, NULL, SC_MANAGER_ENUMERATE_SERVICE);
if (hSCManager == NULL)
{
DPRINT1("Unable to open the service control manager.\n");
DPRINT1("Last Error %d\n", GetLastError());
goto cleanup;
}
hService = OpenServiceW(hSCManager,
L"PlugPlay",
SERVICE_CHANGE_CONFIG | SERVICE_START);
if (hService == NULL)
{
DPRINT1("Unable to open PlugPlay service\n");
goto cleanup;
}
bRet = ChangeServiceConfigW(hService,
SERVICE_NO_CHANGE,
SERVICE_AUTO_START,
SERVICE_NO_CHANGE,
NULL, NULL, NULL,
NULL, NULL, NULL, NULL);
if (!bRet)
{
DPRINT1("Unable to change the service configuration\n");
goto cleanup;
}
bRet = StartServiceW(hService, 0, NULL);
if (!bRet && (GetLastError() != ERROR_SERVICE_ALREADY_RUNNING))
{
DPRINT1("Unable to start service\n");
goto cleanup;
}
bRet = TRUE;
cleanup:
if (hService != NULL)
CloseServiceHandle(hService);
if (hSCManager != NULL)
CloseServiceHandle(hSCManager);
return bRet;
}
开发者ID:hoangduit,项目名称:reactos,代码行数:52,代码来源:install.c
示例19: GetServiceConfig
LPQUERY_SERVICE_CONFIG
GetServiceConfig(LPWSTR lpServiceName)
{
LPQUERY_SERVICE_CONFIGW lpServiceConfig = NULL;
SC_HANDLE hSCManager;
SC_HANDLE hService;
DWORD dwBytesNeeded;
hSCManager = OpenSCManagerW(NULL,
NULL,
SC_MANAGER_ALL_ACCESS);
if (hSCManager)
{
hService = OpenServiceW(hSCManager,
lpServiceName,
SERVICE_QUERY_STATUS | SERVICE_ENUMERATE_DEPENDENTS | SERVICE_QUERY_CONFIG);
if (hService)
{
if (!QueryServiceConfigW(hService,
NULL,
0,
&dwBytesNeeded))
{
if (GetLastError() == ERROR_INSUFFICIENT_BUFFER)
{
lpServiceConfig = (LPQUERY_SERVICE_CONFIG)HeapAlloc(GetProcessHeap(),
0,
dwBytesNeeded);
if (lpServiceConfig)
{
if (!QueryServiceConfigW(hService,
lpServiceConfig,
dwBytesNeeded,
&dwBytesNeeded))
{
HeapFree(GetProcessHeap(),
0,
lpServiceConfig);
lpServiceConfig = NULL;
}
}
}
}
CloseServiceHandle(hService);
}
CloseServiceHandle(hSCManager);
}
return lpServiceConfig;
}
开发者ID:Strongc,项目名称:reactos,代码行数:52,代码来源:query.c
示例20: SetServiceConfig
BOOL
SetServiceConfig(LPQUERY_SERVICE_CONFIG pServiceConfig,
LPWSTR lpServiceName,
LPWSTR lpPassword)
{
SC_HANDLE hSCManager;
SC_HANDLE hSc;
SC_LOCK scLock;
BOOL bRet = FALSE;
hSCManager = OpenSCManagerW(NULL,
NULL,
SC_MANAGER_LOCK);
if (hSCManager)
{
scLock = LockServiceDatabase(hSCManager);
if (scLock)
{
hSc = OpenServiceW(hSCManager,
lpServiceName,
SERVICE_CHANGE_CONFIG);
if (hSc)
{
if (ChangeServiceConfigW(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:Strongc,项目名称:reactos,代码行数:52,代码来源:query.c
注:本文中的OpenServiceW函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论