I am trying to run an exe file as window service. I have done it before manually by doing like this:
sc create TestService binPath= "C:\MyExePathWhichIsToBeRunAsWindowService"
and it could worked properly, when i see the services i am able to find it, Now have to do the same using c# code.
The code should ask the user for the path of exe file and this file has to be run as window service and also the name which he has to provide to this window service.So these two things user will enter at runtime, which is an easy task for me but once if i got that, then how i will run the command below from c# code ?
sc create TestServiceNameUsrEntered binPath= "path user entered for exe at run time"
Could some one please help me ?
EDIT: Please note that user will always enter serviceApplication exe file Not arbitrary files
You should look into Process.Start
. You might want to try something like this:
Process.Start("sc", String.Format("create \"{0}\" binPath=\"{1}\"", serviceName, binPath));