开发者

Disable Windows service at application launch

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?


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");


ServiceController _ServiceController = new ServiceController([NameService]);
if (!_ServiceController.ServiceHandle.IsInvalid) 
{
     _ServiceController.Stop();
     _ServiceController.WaitForStatus(ServiceControllerStatus.Stopped, TimeSpan.FromMilliseconds(uConstante.CtTempoEsperaRespostaServico));
}


You can use WMI for that.

Look here, for example: http://www.csharpfriends.com/Articles/getArticle.aspx?articleID=114


You can use the ServiceController class for this. There are code samples in the linked documentation page.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜