Create a Service using C#

試著忘記壹切 提交于 2019-12-10 15:18:04

问题


I need to create a service using C# and sc.exe utility when i try to execute

C:\Windows\system32\sc.exe create ServiceName binPath= D:\work\ServiceExe.exe,

it works fine. But when i try to execute

Process.Start(@"C:\Windows\system32\sc.exe create ServiceName binPath= D:\work\ServiceExe.exe");

I have an exception, that the system cannot find the file specified.

What can it be? File exists, Service removing before re-install.


回答1:


You should use another overload of Process.Start which takes arguments as a separate parameter.

Process.Start(@"C:\Windows\system32\sc.exe", "create ServiceName binPath= D:\work\ServiceExe.exe")



回答2:


As per my understanding , you should create a deployment project for service which can be made auto run and you donot need to bother after system restart/shutdown.



来源:https://stackoverflow.com/questions/5881901/create-a-service-using-c-sharp

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