StartService

startService启动过程分析 本文将开启对ActivityManagerService的分析。ActivityManagerService是Android的Java framework的服务框架最重要的服务之一。对于Andorid的Activity、Service、Broadcast、ContentProvider四剑客的管理,包含其生命周期都是通过ActivityManagerService来完成的。对于这四剑客的介绍,此处先略过,后续博主会针对这4剑客分别阐述。在整个startService过程,从进程角度看服务启动过程。 阅读详情

StartService

The StartService function starts a service.

BOOL StartService(
  SC_HANDLE hService,
  DWORD dwNumServiceArgs,
  LPCTSTR* lpServiceArgVectors
);
Parameters
hService
[in] Handle to the service. This handle is returned by the OpenService or CreateService function, and it must have the SERVICE_START access right. For more information, see Service Security and Access Rights.
dwNumServiceArgs
[in] Number of strings in the lpServiceArgVectors array. If lpServiceArgVectors is NULL, this parameter can be zero.
lpServiceArgVectors
[in] Pointer to an array of pointers to null-terminated strings to be passed to a service as arguments. Driver services do not receive these arguments. If no arguments are passed to the service, this parameter can be NULL. The service accesses these arguments through its ServiceMain function. The first argument (argv[0]) is the name of the service by default, followed by the arguments, if any, in the lpServiceArgVectors array.
Return Values

If the function succeeds, the return value is nonzero.

If the function fails, the return value is zero. To get extended error information, call GetLastError.

The following error codes can be set by the service control manager. Others can be set by the registry functions that are called by the service control manager.

Return codeDescription
ERROR_ACCESS_DENIEDThe handle does not have the SERVICE_START access right.
ERROR_INVALID_HANDLEThe handle is invalid.
ERROR_PATH_NOT_FOUNDThe service binary file could not be found.
ERROR_SERVICE_ALREADY_RUNNINGAn instance of the service is already running.
ERROR_SERVICE_DATABASE_LOCKEDThe database is locked.
ERROR_SERVICE_DEPENDENCY_DELETEDThe service depends on a service that does not exist or has been marked for deletion.
ERROR_SERVICE_DEPENDENCY_FAILThe service depends on another service that has failed to start.
ERROR_SERVICE_DISABLEDThe service has been disabled.
ERROR_SERVICE_LOGON_FAILEDThe service did not start due to a logon failure. This error occurs if the service is configured to run under an account that does not have the "Log on as a service" right.
ERROR_SERVICE_MARKED_FOR_DELETEThe service has been marked for deletion.
ERROR_SERVICE_NO_THREADA thread could not be created for the service.
ERROR_SERVICE_REQUEST_TIMEOUTThe process for the service was started, but it did not call StartServiceCtrlDispatcher, or the thread that called StartServiceCtrlDispatcher may be blocked in a control handler function.
Remarks

When a driver service is started, the StartService function does not return until the device driver has finished initializing.

When a service is started, the Service Control Manager (SCM) spawns the service process, if necessary. If the specified service shares a process with other services, the required process may already exist. The StartService function does not wait for the first status update from the new service, because it can take a while. Instead, it returns when the SCM receives notification from the service control dispatcher that the ServiceMain thread for this service was created successfully.

The SCM sets the following default status values before returning from StartService:

  • Current state of the service is set to SERVICE_START_PENDING.
  • Controls accepted is set to none (zero).
  • The CheckPoint value is set to zero.
  • The WaitHint time is set to 2 seconds.

The calling process can determine if the new service has finished its initialization by calling the QueryServiceStatus function periodically to query the service's status.

A service cannot call StartService during initialization. The reason is that the SCM locks the service control database during initialization, so a call to StartService will block. Once the service reports to the SCM that it has successfully started, it can call StartService.

As with ControlService, StartService will block for 30 seconds if any service is busy handling a control code. If the busy service still has not returned from its handler function when the timeout expires, StartService fails with ERROR_SERVICE_REQUEST_TIMEOUT. This is because the SCM processes only one service control notification at a time.

Example Code

For an example, see Starting a Service.

Requirements
ClientRequires Windows XP, Windows 2000 Professional, or Windows NT Workstation.
ServerRequires Windows Server 2003, Windows 2000 Server, or Windows NT Server.
Header

Declared in Winsvc.h; include Windows.h.

Library

Link to Advapi32.lib.

DLLRequires Advapi32.dll.
Unicode

Implemented as StartServiceW (Unicode) and StartServiceA (ANSI).

C++调用StartService启动服务失败1053分析与解决 网上通用的OpenSCManager->OpenService->StartService这种启动方式是正确的,但是很多人遇到开启服务时出现1053错误,下面来分析与解决 官网对于StartServiceW的描述(我程序里用的宽字符版本) https://docs.microsoft.com/zh-cn/windows/win32/api/winsvc/nf-winsvc-star... 阅读详情

相关推荐

通信工程学习:什么是OLT光线路终端

OLT(光线路终端)是无源光网络(PON)的核心局端设备,负责光/电信号转换、数据处理、带宽分配及用户管理。具有高带宽、低损耗、高安全性和易维护等技术特点,广泛应用于家庭、企业及公共机构宽带接入。未来将向更高性能、智能化方向发展,结合SDN/NFV等新技术,提升网络服务质量。

limengshi138392的博客 4365

redis启动报错 HandleServiceCommands: system error caught. error code=1056, message = StartService failed

输入redis-server --service-start然后就会有如下报错。所以解决办法就是先将服务停止,然后再进行重新启动。

changyana的博客 7355

2.ROS实用工具:坐标变换

本文围绕ROS坐标变换展开,介绍其在机器人系统中的关键作用,即统一不同传感器和执行器坐标系,服务数据融合等操作。基于ROS的tf库,从广播和监听TF变换两方面阐述实现过程,涵盖新建工作包、编写广播和监听代码、配置构建文件及编译等步骤。此外,介绍启动节点管理器后运行广播和监听节点的方法,并通过rqt_graph、rqt_tf_tree、tf_echo等工具可视化和获取坐标系变换信息。借助这些内容,读者不仅能掌握ROS坐标变换的实现,还能对机器人坐标变换系统的调试和理解有更深入认识 。

qq_74168740的博客 1174

git 突然运行不了,phpstorm 提示git未安装,直接git bash here运行超时,解决方案之一

git 突然运行不了,phpstorm 提示git未安装,直接git bash here运行超时,解决方案之一

weixin_42968668的博客 1283

拼多多爬虫实战:逆向sign与anti_content动态参数解析

现代电商爬虫已远超基础HTTP请求范畴,其核心在于理解服务端如何通过动态签名(sign)、设备指纹、行为验证等多维机制定义‘合法请求’。拼多多作为典型代表,将价格、销量、评价等关键数据完全剥离HTML,转由强校验API返回,依赖HMAC-SHA256嵌套签名、anti_content前端加密载荷及滑动验证token闭环。这类机制本质上是客户端环境可信度与请求上下文一致性的实时博弈,技术价值在于保障数据安全与业务风控。典型应用场景包括竞品价格监控、销量趋势分析、评价情感挖掘等需高保真数据的商业分析任务。本文聚

weixin_29741447的博客 835

Cadence 17.4 PSpice仿真555定时器输出方波

这里利用555定时器组成多谐振荡器产生1Hz的方波并用PSpice仿真其输出的方波波形。555定时器是一种广泛应用的中规模集成电路。根据其内部组成的不同,可分为双极型(555B)和CMOS型(555C)两类。两种类型的定时器各有所长。双极型定时器具有较大的驱动能力,其输出电流可达200mA,可直接驱动发光二级管、扬声器、继电器等负载。而CMOS型定时器的输入阻抗高、功耗低。

tj_nonstoper的博客 1万+

Windows服务编写原理及探讨(2)

Windows服务编写原理及探讨(2)(二)对服务的深入讨论之上  上一章其实只是概括性的介绍,下面开始才是真正的细节所在。在进入点函数里面要完成ServiceMain的初始化,准确点说是初始化一个SERVICE_TABLE_ENTRY结构数组,这个结构记录了这个服务程序里面所包含的所有服务的名称和服务的进入点函数,下面是一个SERVICE_TABLE_ENTRY的例子:SERVICE_TABLE

神经网络爱好者 2075

AIGC算法工程师 面试八股文

1、简述DDPM的算法原理 2、什么是重参数化技巧?Diffusion Models和VAE中的重参数化技巧是如何使用的? VAE中的重参数化技巧 Diffusion Models中的重参数化技巧 3、什么是马尔可夫过程?DDPM中的马尔可夫链是如何定义的? 马尔可夫过程 DDPM马尔可夫链 4、为什么DDPM前向过程中前期加噪少,后期加噪多? 5、VAE和Diffusion Models中的变分推断是什么? 6、Negative Prompt实现的原理是什么?

沉迷单车的追风少年 1万+

Windows无法启动启动服务,错误1053的解决方法

项目需求,要将一个exe二进制文件以windows服务的形式发布,开发编译运行后一切正常。sc命令安装为windows服务启动,出现下图错误Windows无法启动启动服务,错误1053。原因是加载配置文件的接口是用Getwd()获取的当前的工作目录,当将exe注册为windows服务运行时,Getwd获取的则是系统服务调用的工作目录。项目用的是golang开发,这里用到了os.Executable()来返回当前实际运行exe的路径,而不是调用者的工作路径。关键代码处打上crash日志。...

HonWee90的博客 2万+

DeepSeek+Dify之一安装部署

DeepSeek添加知识库

yilvyangguang520的博客 1545

使用 MATLAB/Simulink 对风光互补发电系统进行建模

随着全球对清洁能源的需求日益增长,风力发电和光伏发电作为两种主要的可再生能源形式,在电力供应中的占比越来越高。然而,由于风电和光伏的间歇性和不确定性,单独依赖其中任何一种能源都会给电网带来挑战。因此,风光互补发电系统(Wind-PV Hybrid System)应运而生,通过合理配置风力发电机和光伏电池板的数量,可以有效提高系统的稳定性和可靠性。此外,为了确保整个电力系统的安全稳定运行,还需要研究风光互补发电系统与主网之间的协调调度策略。本教程将详细介绍如何使用。

amy_mhd的博客 119

Android startService和bindService的区别和用法

1、生命周期上的区别 执行startService时,Service会经历onCreate->onStartCommand。当执行stopService时,直接调用onDestroy方法。调用者如果没有stopService,Service会一直在后台运行,下次调用者再起来仍然可以stopService。 执行bindService时,Service会经历onCreate->onBind。这个时候调用者和Service绑定在一起。调用者调用unbindService方法或者调用者Context不

沧海龙腾LV的博客 2228

Autosar MCAL-S32k324 Crypto配置-基于EB

NXP官网提供了免费的HSE固件,同时也提供了对应的协议栈。本文以算法为例,介绍MCAL相关的配置及在代码中的集成与使用。使用HSE计算,比软件算法确实方便许多。后面会完善更多的算法测试。

赞的博客 2436

快速使用StartService

快速使用StartService 1.Service定义 Android四大组件之一 Service是一个可以在后台执行长时间运行操作而不提供用户界面的应用组件。 服务可由其他应用组件启动,而且即使用户切换到其他应用,服务仍将在后台继续运行。 组件可以绑定到服务,以与之进行交互,甚至是执行进程间通信 (IPC) 2. 创建两个按钮: 启动按钮以及停止按钮 2.1 创建一个Service文件 2.2 编写server部分: package com.example.servicebasic; impor

qq_46258465的博客 2677

华为的C语言编程规范.pdf

华为技术有限公司内部技术规范。本规范制定了编写C语言程序的基本原则、规则和建议。从代码的清晰、简洁、可测试、安全、程序效率、可移植各个方面对C语言编程作出了具体指导。

LinePhone3.2.7(android端最新版本) sip客户端

SIP客户端For android:LinePhone3.2.7(最新版本),官网地址:http://www.linphone.org/

Android service 启动篇之 startService

Android 中service 详解中说明了大概背景,这里不再过叙述了。 代码基于Android O Android基础总结之六:Sevice中是应用端对于service 使用的总结,其中看到启动service 需要的接口有startService 和bindService。在Android O 中又添加了一个接口api——startForegroundService。本篇主要围...

私房菜 2万+

VC中sqlite的使用

在VC中对sqlite的使用,实现数据库大批数据的快速插入,读取数据库中的数据在ListCtrl中显示

【Framework】startService启动流程

带你看Android 13下startService的实现原理

to_perfect的博客 1776

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

startService流程

开启Service进程的主要类 android.content包的ContextWrapper类 android.content包的Context类 android.app包的ContextImpl类 android.app包的ActivityManager类 android.os包的ServiceManager类 android.os包的ServiceManagerNative类 android...

fengluoye2012的博客 556

bindService和startService

服务 服务(service)是Android中实现程序后台运行的解决方案,它非常适合去执行那些不需要和用户交互而且还要求长期运行的任务。服务的运行不依赖于任何用户界面,即使程序被切换到后台,后者用户打开了另一个应用程序,服务仍然能够保持正常运行。 bindService bindService是绑定Service服务,执行service服务中逻辑流程。service通过Context.startS...

API搬运工 1337

bindService与startService

1. bindService既可以启动一个跨进程的service,也可以启动一个本进程内的service。     如果没有用aidl接口,则bindService不能bind另一个进程的service     如果使用了aidl接口,则在bindService()时,若service还没有启动,则系统会先启动service运行在的新进程。     当然,如果没用aidl,bindservi

hhitom的博客 3890

startService流程详解

1.Service整体交互结构 Service作为Android四大组件之一,其生命周期是通过system_server进程中的ActivityManagerService(AMS)管理的,大致了解Service通信过程中涉及到的几个主要角色。 App端进程: ContextImpl Context抽象类所有api的实现,是Service、Activity和其他组件base Context。 ActivityThread 代表着App的主线程,是App的入口,Application、Activ

尤教授的博客 3258

startService和bindService的区别

首先看下其生命周期的区别: 生命周期: onCreate → startCommand → onDestroy onCreate → onBind→onUnBind→ onDestroy 静态绑定对应着startService;动态绑定对应着bindService,静态有自己独立的生命周期,动态会依附activity等组件的生命周期。 1、生命周期上的区别 执行startService时,Service会经历onCreate->onStartCommand。当执行stopService时,直接调

梦否 5704

android service startService与bindService的区别

Android执行Service有两种方法,一种是startService,一种是bindService。下面让我们一起来聊一聊这两种执行Service方法的区别。 1、生命周期上的区别     执行startService时,Service会经历onCreate->onStartCommand。当执行stopService时,直接调用onDestroy方法。调用者如果没有st

zhuangyalei的专栏 8049

Android中bindService和startService启动服务有何区别

和是 Android 中两种用于与Service交互的方式,它们的区别主要在于和。

白泽的博客 1217

Android Service原理分析之startService(一)

1. Service概述 Service作为Android四大组件之一,在开发过程中非常常用,它虽然没有ui,但是同样可以在后台做很多重要的事情,我们平时使用启动service主要通过startService以及bindService来启动service以便已经相关操作。本文将介绍start...

测试0901-1 457
上一篇: StartServiceCtrlDispatcher
下一篇: UnlockServiceDatabase
普通网友
博客等级 码龄22年 1万+粉丝 3156原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值