Windows services Windows XPE服务安装-如何在CreateService时设置安全性?

Windows services Windows XPE服务安装-如何在CreateService时设置安全性?,windows-services,windows-xp,windows-xp-embedded,Windows Services,Windows Xp,Windows Xp Embedded,我正在使用CreateService在windows XPE上安装windows服务。我想进行设置,以便只有管理员才能启动/停止/暂停/恢复服务 现在,我正在使用以下方法安装该服务: schService = CreateService(schSCManager, ServiceName, ServiceDisplayName, // service name to display SERVICE_ALL_ACCESS, // desired access

我正在使用CreateService在windows XPE上安装windows服务。我想进行设置,以便只有管理员才能启动/停止/暂停/恢复服务

现在,我正在使用以下方法安装该服务:

  schService = CreateService(schSCManager,
     ServiceName, 
     ServiceDisplayName, // service name to display
     SERVICE_ALL_ACCESS, // desired access 
     SERVICE_WIN32_OWN_PROCESS, // service type 
     SERVICE_AUTO_START, // start type 
     SERVICE_ERROR_NORMAL, // error control type 
     binaryPathName, // service's binary (this program)
     NULL, // no load ordering group 
     NULL, // no tag identifier 
     NULL, // no dependencies
     NULL, // LocalSystem account
     NULL); // no password
该服务以安全性结束,这样PowerUsers组的成员就可以启动和停止该服务。我发现我可以使用sc-sdshow来检查安全描述符,并且我已经设计出一个SDDL行,它将为我们做正确的事情

我还了解到,我们的Win XPE安装没有sc.exe二进制文件,因此我们无法真正使用它来安装这个特定的系统

因此,我需要知道的是:我需要使用哪些API,以便在我执行CreateService调用时在该服务上设置安全描述符。我完全不熟悉Windows安全API,所以我不知道从哪里开始


更新:答案是SetServiceObjectSecurity(如下)。下一个问题:设置SecurityDescriptor的最佳方法是什么?最好先获取默认描述符,然后修改它吗?或者我应该创建一个全新的描述符吗?

我对Windows XP Embedded不是很熟悉,但通常情况下,使用该函数后,您将实现您的目标。使用从CreateService获得的句柄,并构建与所需内容匹配的安全描述符