问题
Because of VLC conflict I have to turn off Windows Advanced Text Services at my application launch. Is there any special API for that? Will it work for user with default rights?
回答1:
ServiceController _ServiceController = new ServiceController([NameService]);
if (!_ServiceController.ServiceHandle.IsInvalid)
{
_ServiceController.Stop();
_ServiceController.WaitForStatus(ServiceControllerStatus.Stopped, TimeSpan.FromMilliseconds(uConstante.CtTempoEsperaRespostaServico));
}
回答2:
The question is titled "Disable Windows service..." but the answers all tell how to stop a service.
Most of what you will find on Google is that you can update the registry to disable a service using something like this:
RegistryKey key = Registry.LocalMachine.OpenSubKey(@"SYSTEM\CurrentControlSet\Services\[YourServiceName]", true);
key.SetValue("Start", 4);
I haven't tried that method but it appears as though it will work. I also came up with a different method that uses sc.exe to disable the service:
Process sc = Process.Start("sc.exe", "config [YourServiceName] start= disabled");
回答3:
You can use the ServiceController class for this. There are code samples in the linked documentation page.
回答4:
You can use WMI for that.
Look here, for example: http://www.csharpfriends.com/Articles/getArticle.aspx?articleID=114
回答5:
just execute "net stop service-name" to stop a service or "net start service-name" to start a service. type "net start" in the console (cmd.exe) in order to list all services.
You need admin privileges in order to enable/disable services.
来源:https://stackoverflow.com/questions/3052649/disable-windows-service-at-application-launch