How do I install a Windows Service programatically with additional args?

此生再无相见时 提交于 2019-12-11 20:11:31

问题


I'm attempting to install a service via C# from an installer's custom action.

I've tracked most of the topics related to my problem on Stack-Overflow however I've failed to find a solution to my problem.

The problem is : I need to pass additional arguments to my service, here's how it looks like in cmd.exe :

my_service -installMY_SERVICE_NAME cmdLine="commands in here" auxCommands="aux commands in here"
net start "My Service (MY_SERVICE_NAME)"

It works if I do it from the command line however I fail to get it done in C# therefore I'm forced to ask for help

Regards


回答1:


It sounds like you want to start a service via the command line with C# and pass in additional arguments. Process.Start has parameters for command line arguments. Give this a try

Process.Start("my_service", "-install MY_SERVICE_NAME cmdLine=\"commands in here\"" auxCommands=\"aux commands in here\");
Process.Start("net", "start \"My Service (MY_SERVICE_NAME)\"");



回答2:


Would this be what you are looking for, to start a service from C#? The article here on CodeProject might do the trick?

Hope this helps, Best regards, Tom.



来源:https://stackoverflow.com/questions/1809243/how-do-i-install-a-windows-service-programatically-with-additional-args

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