Install a .NET windows service without InstallUtil

2019-01-03 07:11发布

I have a standard .NET windows service written in C#.

Can it install itself without using InstallUtil? Should I use the service installer class? How should I use it?

I want to be able to call the following:

MyService.exe -install

And it will have the same effect as calling:

InstallUtil MyService.exe

7条回答
Fickle 薄情
2楼-- · 2019-01-03 08:18

Take a look at the InstallHelper method of the ManagedInstaller class. You can install a service using:

string[] args;
ManagedInstallerClass.InstallHelper(args);

This is exactly what InstallUtil does. The arguments are the same as for InstallUtil.

The benefits of this method are that it involves no messing in the registry, and it uses the same mechanism as InstallUtil.

查看更多
登录 后发表回答