问题
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