JimDel
JimDel

Reputation: 4359

Cant stop a service with c#

I'm trying to temporarily stop the "Program Compatibility Assistant Service". But the code below gives the error "Cannot open PcaSvc service on computer '.'." I've used "PcaSvc" and "Program Compatibility Assistant Service" as the name but they both give the same error. And the service is running. Can someone explain please?

ServiceController service = new ServiceController("PcaSvc");
try
{
    service.Stop();
    service.WaitForStatus(ServiceControllerStatus.Stopped);
}
catch (Exception e)
{
    MessageBox.Show(e.Message);
}

Upvotes: 0

Views: 1967

Answers (1)

Derek
Derek

Reputation: 8753

This is probably a security issue.

See: ServiceController permissions in Windows 7

Also see: Stop/Start service in code in Windows 7

Upvotes: 1

Related Questions