How can I install a windows service onto a machine that doesn't have Visual Studio installed?

前端 未结 11 1829
悲&欢浪女
悲&欢浪女 2021-01-31 09:08

The only way to install windows-service I know is using \"Visual Studio 2008 Command Prompt\", Is there a way to install windows-service on a machine which isn\

11条回答
  •  终归单人心
    2021-01-31 09:57

    Yep, installutil.exe works nicely, but I got tired of having to remember to start the Visual Studio 2008 Command Prompt in order to use it. Invariably, I'd open an ordinary console only to realize that the installutil.exe location was not part of the path.

    Fortunately, the installutil.exe is a wrapper around a set of reflection calls. From MSDN,

    Installutil.exe uses reflection to inspect the specified assembly and find all Installer types with the RunInstallerAttribute set to true. The tool then executes either the Install Method or the Uninstall Method on each instance of the Installer type.

    What this means is that it is possible to add code to the Windows service to have it install and uninstall itself. By doing so, I no longer require installutil.exe or the Visual Studio 2008 Command Prompt to run it.

    I have provided a step-by-step guide for how to do this here. The -install option installs the Windows service and starts it. Conversely, the -uninstall option stops the service and uninstalls it.

提交回复
热议问题