DeleteService

博客介绍了DeleteService函数,该函数用于标记从服务控制管理器数据库中删除指定服务。说明了函数的参数、返回值,成功返回非零值,失败返回零。还提及函数标记删除后,需关闭服务句柄且服务停止才移除数据库条目,若服务无法停止,系统重启时移除。

DeleteService

The DeleteService function marks the specified service for deletion from the service control manager database.

BOOL DeleteService(
  SC_HANDLE hService
);
Parameters
hService
[in] Handle to the service. This handle is returned by the OpenService or CreateService function, and it must have the DELETE access right. For more information, see Service Security and Access Rights.
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 may be set by the service control manager. Others may be set by the registry functions that are called by the service control manager.

Return codeDescription
ERROR_ACCESS_DENIEDThe handle does not have the DELETE access right.
ERROR_INVALID_HANDLEThe specified handle is invalid.
ERROR_SERVICE_MARKED_FOR_DELETEThe specified service has already been marked for deletion.
Remarks

The DeleteService function marks a service for deletion from the service control manager database. The database entry is not removed until all open handles to the service have been closed by calls to the CloseServiceHandle function, and the service is not running. A running service is stopped by a call to the ControlService function with the SERVICE_CONTROL_STOP control code. If the service cannot be stopped, the database entry is removed when the system is restarted.

The service control manager deletes the service by deleting the service key and its subkeys from the registry.

Example Code

For an example, see Deleting 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.
@startuml actor User as 用户 participant Controller as "设备删除接口" participant DeleteService as "DeleteDeviceService" participant ResetService as "ResetDeviceService" participant PassThrough as "PassThroughService" participant SolarPass as "SolarPassthroughService" participant PhysicalDevice as "物理设备" == 删除设备流程(简化)== 用户 -> Controller: 提交删除请求\n(resetDevice=true) Controller -> DeleteService: deleteDeviceLock() activate DeleteService DeleteService -> DeleteService: 加锁、设置删除标志 DeleteService -> DeleteService: 执行设备删除逻辑 == 设备重置流程== DeleteService -> ResetService: resetDevice(resetDeviceDTO) activate ResetService alt 设备类型 == solar太阳能 ResetService -> SolarPass: resetDevice(devId) activate SolarPass SolarPass -> PhysicalDevice: 发送太阳能专用reset指令 activate PhysicalDevice PhysicalDevice --> SolarPass: 执行硬件复位 deactivate PhysicalDevice SolarPass --> ResetService: 返回操作结果 deactivate SolarPass else 其他设备类型 (IPC、NVR) ResetService -> PassThrough: resetDevice(devId) activate PassThrough PassThrough -> PhysicalDevice: 发送reset指令 activate PhysicalDevice PhysicalDevice --> PassThrough: 执行硬件复位 deactivate PhysicalDevice PassThrough --> ResetService: 返回操作结果 deactivate PassThrough end alt 重置成功 ResetService -> DeleteService: OK DeleteService -> DeleteService: 记录成功日志\n(DELETE_AND_RESET_DEVICE_SUCCEED) else 重置失败 ResetService -> DeleteService: RESET_DEVICES_FAILED DeleteService -> DeleteService: 记录失败日志\n(DELETE_DEVICE_SUCCEED_AND_RESET_DEVICE_FAILED) end deactivate ResetService == 后续处理 == DeleteService -> DeleteService: 释放锁/清除标志 DeleteService --> Controller: 返回操作结果 deactivate DeleteService alt 完全成功 Controller --> 用户: 删除成功+复位成功 else 删除成功但复位失败 Controller --> 用户: 删除成功+复位失败\n(错误码:-5361) end @enduml 以这个plantUMl为例,现在主体就只有User,设备删除接口,DeleteDeviceService,详细展示DeleteDeviceService的后处理操作(有local和cloud两套,代码分别是: @Override public void afterDelete(String vmsId, DeviceDO deviceDO, Boolean resetDevice) { deviceConnectorLocalApiService.addUnRecognizedDevice(deviceDO.getDevId()); if (deviceDO.isChannelDevice() || OnlineStatus.OFFLINE == deviceDO.getOnlineStatus()) { return; } // 透传关闭设备VMS local配置 closeVmsLocal(deviceDO.getDevId(), deviceDO.getDeviceType()); } @Override public void afterDelete(String vmsId, DeviceDO deviceDO, Boolean resetDevice) { if (Boolean.FALSE.equals(resetDevice)) { if (deviceGatewaySwitchService.isSwitchedToGateway(deviceDO.getDevId())) { // 主动下发解绑 deviceBindService.unbindDevice(vmsId, deviceDO.getDevId()); deviceGatewaySwitchRetryService.switchDeviceToCloud(deviceDO); } } }),用plantUML画出这部分的逻辑
最新发布
11-25
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值