I am struggling to this project for a long time.
I am working with the windows service application. I have already created a working windows service application. Now I got a request that only authorized users can only start the service.
Here’s what I have tried.
i. read the connection string from the app.config file
<add name ="ConnectionString" connectionString="Data Source = Server_name; Initial Catalog = DB_DEV; Integrated Security = True" providerName="System.Data.SqlClient"/>
ii. pass the connection string to SqlConnection
SqlConnection myConnection = new SqlConnection(myConnectionString) //gives me error here
iii. And tried to start service as Log on – This user.
Is this the way to do it or any other way to do it? please guide me. Thanks.
note-it is in VS2010.
A Windows service runs as a single user, configured via the Services control panel as you appear to be doing. It’s unclear how the database connection is related, but you can specify which users can start and stop the service via a number of methods.
The
sccommand-line toolUsing the
sc sdset <Service name> <SDDL string>you can configure permissions on the service, allowing you to control who can start/stop the service, however this requires use of the rather terse and not particularly well documented SDDL string format.Using
subinaclMicrosoft provides a tool called
SubInACLwhich can be used to configure a number of permissions-related settings.You can use this tool to set service start/stop permissions as follows:
(The "
TO" indicates that the user is to be granted both Start service (T) and Stop service (O) permissions, the other permission values can be determined viasubinacl /help /full).