Installing Windows Services during runtime

Aloha,

I've been trying to install a Windows service during runtime in Visual C# without using any seperate programs like installutil.exe. The MSDN library barely gives any information on this, always referring to installutil.exe or a full MSI installer package, neither of which can be done in runtime.

I'm wondering if it's even possible to do this during runtime. Perhaps it would be better (but messier) to directly alter the registry perhaps Even so, I'd much rather prefer the cleaner was of using the proper classes and methods provided. (Even though the former might be quicker) An idea I had was to create a class with inherits from the System.Configuration.Install class, adding the ServiceProjectInstaller and ServiceInstaller to my class' Installers collection and then manually calling my class' Install function (which writelines some info and then calls base.Install ) but sadly this doesn't work.

The ServiceProcessInstaller and ServiceInstaller are both properly defined and the service successfully installs when I use installutil.exe on the resulting executable.

Thanks in advance,
DLSeth


Answer this question

Installing Windows Services during runtime

  • Azra

    You can use the WIN32 API calls from C# to do this.
    Take a look at the CreateService Win32 API function.

    Regards,
    Vikram


  • Kemp Brown MSFT

     Vikram wrote:
    You can use the WIN32 API calls from C# to do this.
    Take a look at the CreateService Win32 API function.

    Regards,
    Vikram


    Not exactly what I was looking for, but it works good for me, thank you!

  • ooodi

     Mykre wrote:
    Why carn't you use the installutil at runtime. I have done this before for another app where I would execute the process and redirect the console output so that the user does not see the console running.


    Yes, I'm aware that's a possibility but I would really prefer to do this without relying on any other software. It's just a hobby project of my own that I'm working with, so neither time nor money are an issue for me so I'll happily take the hard route.

    There's also the matter of distribution; If I finish and release the software under a BSD license then would I be allowed to distribute installutil.exe along with it Or am I even allowed to release a program under the BSD license which relies for a large part on installutil.exe I'm not a legal wizard, I'm a programmer.

    Lastly, calling installutil.exe and hiding the output just doesn't feel like solid and clean programming to me. But that's just my humble opinion.

  • johnny wisconsin

    Why carn't you use the installutil at runtime. I have done this before for another app where I would execute the process and redirect the console output so that the user does not see the console running.

  • MattiasO

    remember that a user must have the install util (installutil.exe) as it is part of the framework, so this being the case you would not have to distribute.

    Mykre
    www.ircomm.net
    Managed DirectX and Game Programming Resources

  • Installing Windows Services during runtime