Click here to Skip to main content
15,881,803 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have made a windows service that checks on another window service to check if it is running.If the service to be monitored has stopped I need to set a given set of username and password and restart that service.would it be possible to do that.I tried the following code but it doesnt work.

string objPath = string.Format("Win32_Service.Name='{0}'", serviceName);
using (ManagementObject service = new ManagementObject(new ManagementPath(objPath)))
{
   object[] wmiParams = new object[11];
   wmiParams[6] = username;
   wmiParams[7] = password;
   service.InvokeMethod("Change", wmiParams);
}
Posted
Updated 24-Nov-14 1:12am
v2

1 solution

Yes, You can set the username who can access to that windows service.

In security tab.

But administrator of the machine will always have the access.
 
Share this answer
 
Comments
Malayali Coder 24-Nov-14 7:17am    
i want to set it programmatically.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900