Install Windows service to run under user's credentials with ServiceAccount.User but don't prompt

China☆狼群 提交于 2020-01-13 11:20:51

问题


I have created a C# Windows Service and its accompanying Visual Studio Setup project that creates an installer. It successfully installs the service.

When I choose any value from enum ServiceAccount apart from ServiceAccount.User, the service installs without prompting using the appropriate built-in user. What I am after is actually installing the service under current user's credentials. When I specify ServiceAccount.User, I get a prompt for a user name and password during installation. What I need to do is find a way to install the service with the credentials of the user who is running the setup without prompting for password.

Is this at all possible? I am willing to resort to any measures needed (like loads of P/Invoke) to get the job done.


回答1:


You can't, there's no way to extract the clear-text password unless something is misconfigured and you'll need that to set up the service. See this similar question.

Also, in general, services should be installed with a separate and unique account per service with least privilege.




回答2:


This won't be possible as suggested by others. Even when from service manager you want to run the service under some other account (even if it current user account) it asks you to type the password again.



来源:https://stackoverflow.com/questions/6199615/install-windows-service-to-run-under-users-credentials-with-serviceaccount-user

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!