如何为指定用户创建Windows服务?
我构建了一个测试服务,它将消息写入本地文件。 我注意到文件的“所有者”属性始终是“管理员”,这在使用“本地系统”帐户时是相同的。 但我已将服务管理器中的“登录身份”设置更改为我的个人帐户。
我应该怎样做才能使该服务在指定帐户上运行?
I built a testing service which writes a message to a local file. I noticed the "Owner" property of the file is always "Administrator" which is same when using "Local System" account. But I have changed the "Log on as" setting to my personal account in service manager.
What should I do to make the service work on a specified account?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我不知道该怎么做,但您还应该将用户设置为“作为服务运行”选项。 检查 MSDN API 了解详细信息
I am not sure how to do it, but you should also set the user to "Run as a service" option. check the MSDN API for details
“登录身份”设置应该可以满足您的要求。
难道是你更改登录帐户后没有创建该文件? 如果您覆盖该文件,所有者可能不会改变。
我不确定是否建议以普通用户身份登录该服务。 用户将需要“作为服务登录”权限。 如果您是管理员,则可能有此权限,但普通用户可能没有。
The "Log on as" setting should do what you want.
Could it be that you haven't created the file after you changed the logon account? If you overwrite the file, the owner will probably not change.
I'm not sure if it is advisable to log the service on as a regular user. The user will need the "log on as a service" right. You might have that if you're an administrator, but a regular user might not.
您执行完全相同的操作,但在服务控制管理器中指定该特定帐户。
或者您的意思是该服务只会为特定用户运行?
You do exactly the same, but specify that specific account in service control manager.
Or do you mean that the service will only be running for a specific user?
您可以通过创建 WMI 脚本来设置服务设置来完成此操作。
据我所知,您无法对服务将自动使用的用户进行硬编码。
You could do this by creating a WMI script to set up the Service settings.
You cannot, as far as I know, hardcode the user the service will use automatically.