4

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.

wpfwannabe
  • 14,587
  • 16
  • 78
  • 129
  • What does the service do? If it is a per-user service, then using the task scheduling mechanisms or program autostart might be a better choice. – Anders Abel Jun 01 '11 at 10:29
  • Yes, you are right. There is just once scenario not covered by auto-start - what if the program needs to run even without logged users or if a different user is logged on? Also, I am not sure about task scheduling and logged on users, but task scheduling does not seem appropriate because the app needs to run continuously instead of getting started at specified times. – wpfwannabe Jun 01 '11 at 12:11

2 Answers2

6

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.

Community
  • 1
  • 1
Oskar Duveborn
  • 2,189
  • 16
  • 20
1

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.

Ankur
  • 33,367
  • 2
  • 46
  • 72