Disable Windows service at application launch

孤街醉人 提交于 2020-08-02 07:54:19

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!