Deleting a Service
In the following example, a service configuration program uses the OpenService function to get a handle with DELETE access to an installed service object. The program then uses the service object handle in the DeleteService function to remove the service from the SCM database.
BOOL DeleteSampleService()
{
schService = OpenService(
schSCManager, // SCManager database
TEXT("Sample_Srv"), // name of service
DELETE); // only need DELETE access
if (schService == NULL)
{
printf("OpenService failed (%d)/n", GetLastError());
return FALSE;
}
if (! DeleteService(schService) )
{
printf("DeleteService failed (%d)/n", GetLastError());
return FALSE;
}
else
printf("DeleteService succeeded/n");
CloseServiceHandle(schService);
return TRUE;
}
博客介绍了服务配置程序删除服务的操作。通过OpenService函数获取对已安装服务对象具有DELETE访问权限的句柄,再利用DeleteService函数结合该句柄,将服务从SCM数据库中移除。
24

被折叠的 条评论
为什么被折叠?



