Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create a Service using C#

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.

like image 311
E-Max Avatar asked Feb 25 '23 08:02

E-Max


1 Answers

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")
like image 152
František Žiačik Avatar answered Mar 08 '23 10:03

František Žiačik