Avatar of John Porter
John Porter
Flag for United States of America

asked on 

Start/Stop/Restart a windows Service from C# with ServiceController

Hello Experts,

I want to restart the "SAVService" (Sophos Antivirus) windows service using the ServiceController class in C#.

-- I added a reference to the ServiceProcess.dll in my C# project

-- I defined the service like this:
myService.ServiceName = "SAVService";

--I can get the status of the service like this
string svcStatus = myService.Status.ToString(); //This works - Shows SAVService is "Runing"

Problem:

When I try to stop the SAVService like this: myService.Stop();

I get an Exception "Cannot open SAVService on the computer" I suspect this may be a security issue. The SAVService on my computer will only start/stop using the Login "Local System" or Login/pswd "Local Service\Sophos default password"  

Does anyone know how to define the User/Password for a windows service in   ServiceController ?

Thanks!
C#.NET Programming

Avatar of undefined
Last Comment
John Porter

8/22/2022 - Mon