0

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

Maciek
  • 19,435
  • 18
  • 63
  • 87
  • What works from the command line? If it runs in the command line, but doesn't run in Visual Studio, then take a look at the Debug page for the project properties page -- there should be an option to enter the command line arguments there when the debugger is kicked off. – Jeremy McGee Nov 27 '09 at 15:17
  • it's not a matter of "not working" in VS. I have no idea how to get it done in the first place. I've imported the advapi32.dll's interface into C# however I have NO IDEA how to pass start parameters. – Maciek Nov 27 '09 at 15:24
  • Are you trying to pass parameters when the service is being started? If so I don't think that is possible. Passing parameters while installing certainly is – Bob Nov 27 '09 at 15:33
  • and how do I do that exactly? – Maciek Nov 27 '09 at 15:48
  • The answer that I provided shows you how to pass paramteres while installing with C# – Bob Nov 27 '09 at 16:57

2 Answers2

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)\"");
Bob
  • 97,670
  • 29
  • 122
  • 130
0

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.

t0mm13b
  • 34,087
  • 8
  • 78
  • 110
  • I'm afraid there's no mention about passing additional arguments/start parameters to the service in there – Maciek Nov 27 '09 at 15:23