我期待在Windows上安装服务(Windows 7 / Windows 8)。
虽然该服务最初将由“管理员”安装,但应以这样的方式安装,即该本地计算机上的任何用户帐户都可以启动/停止/重新启动它。
尝试将“登录身份”更改为网络服务,但没有帮助。
尝试使用Subinacl.exe,但由于安装程序的架构设计(不允许安装任何外部应用程序),这是不可行的。
问题很简单 - >服务A由管理员安装,但应具有该计算机上所有用户帐户的完全权限。
同样在安装时,事先并不知道该机器上有多少用户帐户可用。
答案 0 :(得分:0)
Kevin van Zonneveld在他的blog中描述了如何做到这一点。他提供的示例是允许所有经过身份验证的用户重新启动Apache Tomcat服务:
sc GetKeyName "Apache Tomcat"
# returns Tomcat5
sc sdset Tomcat5 "D:AR(A;;CCDCLCSWRPWPDTLOCRSDRCWDWO;;;BA)(A;;LCRPWP;;;AU)(A;;CCLCSWLOCRRC;;;IU)(A;;CCDCLCSWRPWPDTLOCRSDRCWDWO;;;SY)S:(AU;FA;CCDCLCSWRPWPDTLOCRSDRCWDWO;;;WD)"
答案 1 :(得分:0)
您可以使用SetSecurityInfo
或SetServiceObjectSecurity
来更改服务ACL。此代码创建服务,然后设置ACL以允许任何交互式登录用户启动服务:
wchar_t sddl[] = L"D:"
L"(A;;CCLCSWRPWPDTLOCRRC;;;SY)"
// default permissions for local system
L"(A;;CCDCLCSWRPWPDTLOCRSDRCWDWO;;;BA)"
// default permissions for administrators
L"(A;;CCLCSWLOCRRC;;;AU)"
// default permissions for authenticated users
L"(A;;CCLCSWRPWPDTLOCRRC;;;PU)"
// default permissions for power users
L"(A;;RP;;;IU)"
// added permission: start service for interactive users
;
DWORD InstallService()
{
SC_HANDLE manager, service;
PSECURITY_DESCRIPTOR sd;
DWORD err;
wchar_t apppath[MAX_PATH + 2];
// Note: because this is only called from main() which exits
// immediately afterwards, no attempt is made to close the
// handles generated.
if (!ConvertStringSecurityDescriptorToSecurityDescriptor(sddl,
SDDL_REVISION_1, &sd, NULL))
{
err = GetLastError();
printf("Error %u creating security descriptor.\n", err);
return err;
}
if (!GetModuleFileName(0, apppath, MAX_PATH + 1))
{
err = GetLastError();
printf("Error %u fetching module name.\n", err);
return err;
}
if (_wcsicmp(apppath + wcslen(apppath) - wcslen(exename), exename) != 0)
{
printf("Application name mismatch: %ls\n",
apppath + wcslen(apppath) - wcslen(exename));
return ERROR_INVALID_FUNCTION;
}
manager = OpenSCManager(0, 0, SC_MANAGER_CREATE_SERVICE);
if (!manager)
{
err = GetLastError();
printf("Error %u connecting to service manager.\n", err);
return err;
}
service = CreateService(manager,
servicename,
displayname,
WRITE_DAC,
SERVICE_WIN32_OWN_PROCESS,
SERVICE_DEMAND_START,
SERVICE_ERROR_NORMAL,
apppath,
0,
0,
NULL,
NULL,
NULL);
if (!service)
{
err = GetLastError();
printf("Error %u installing service.\n", err);
return err;
}
if (!SetServiceObjectSecurity(service, DACL_SECURITY_INFORMATION, sd))
{
err = GetLastError();
printf("Error %u setting service security.\n", err);
return err;
}
printf("Service successfully installed.\n");
return 0;
}