How register service with command line arguments

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • tvrdak
    New Member
    • Dec 2009
    • 2

    How register service with command line arguments

    Hello,

    I would like to register service to start with some arguments - meaning command line arguments of service itself. The best approach was some articles about selfregistratin g service, like f.e. http://alt.pluralsight .com/wiki/default.aspx/Craig/SelfInstallingS ervice.html

    In this case I had assembly executable and could add my parameter at the end, but unfortunately registration itself closed it into dobulequotes :(, so result was "c:\directory\m yservice.exe /param" and service didn't not start of couse.

    I spent almost all day looking for some solution but till now nothing. Do somebody know some solution or only way is to use an API function ?

    tvr
  • Plater
    Recognized Expert Expert
    • Apr 2007
    • 7872

    #2
    Well you can start your service with arguments from the command line
    It's like:
    Code:
    NET START MYSERVICE /param1 /param2 /param3
    There might be something you can take away from that?

    Also there might be something you can do in the registry at:
    Code:
    HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services\MYSERVICE

    Comment

    • tvrdak
      New Member
      • Dec 2009
      • 2

      #3
      Thank for response, just now I am not in hurry to solve it, but in case I will need, I will try it by edit registry. I am just disapointed to have an installation support inside .net, but no support for add command line parameters when service is beeing registered

      Comment

      • Frinavale
        Recognized Expert Expert
        • Oct 2006
        • 9749

        #4
        I'm a little confused.

        What do you mean exactly when you say "register service"?

        Do you want to register a .NET DLL (that can be exposed to COM) into the Windows Registry?

        Do you want to "register" the software against some sort of database or web service/website?

        What tool are you attempting to "register" your service with?
        Is it your own tool that you've developed?

        -Frinny

        Comment

        • Plater
          Recognized Expert Expert
          • Apr 2007
          • 7872

          #5
          You have to register your service with the service control manager SCM(services.ex e) in windows.
          For .NET services, this is done with:
          Code:
          //INSTALL COMMAND
          // C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\InstallUtil /i <path and filename of service>
          //UN-INSTALL COMMAND
          // C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\InstallUtil /u <path and filename of service>
          (or similar depending on your .NET package I suppose)

          I however have not seen anything in InstallUtil, nor the System.ServiceP rocess.ServiceP rocessInstaller or System.ServiceP rocess.ServiceI nstaller classes that allow for parameters.

          When implemented in a derived class, executes when a Start command is sent to the service by the Service Control Manager (SCM) or when the operating system starts (for a service that starts automatically). Specifies actions to take when the service starts.

          Process initialization arguments for the service in the OnStart method, not in the Main method. The arguments in the args parameter array can be set manually in the properties window for the service in the Services console. The arguments entered in the console are not saved; they are passed to the service on a one-time basis when the service is started from the control panel. Arguments that must be present when the service is automatically started can be placed in the ImagePath string value for the service's registry key (HKEY_LOCAL_MAC HINE\SYSTEM\Cur rentControlSet\ Services\<servi ce name>). You can obtain the arguments from the registry using the GetCommandLineA rgs method, for example: string[] imagePathArgs = Environment.Get CommandLineArgs ();.

          From what I have read, the default servicetype does not allow parameters(my service has the parameters box grayed out in the services.msc settings)
          This talks about a FileHandlingWin Service type:
          Microsoft Support is here to help you with Microsoft products. Find how-to articles, videos, and training for Microsoft Copilot, Microsoft 365, Windows 11, Surface, and more.

          Comment

          Working...