martedì, novembre 27, 2007

Service install error

Using VS2005 you can create NTServices. Every service runs under the permission of an account, tipically Network Service or Local Service. But there are situations where you need to run the service with another account.
When you create an instance of a ServiceProcessInstaller you can specifiy the Account property: LocalService, NetworkService, LocalSystem or User. User is not a real account. It's a "placeholder" and you will set the real account during installation.

To install a service, you must use InstallUtil.exe from the NET Framework:

c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\ InstallUtil.exe foo.exe

After pressing enter, install starts and after some seconds you are prompted with a windows asking username and password for the account:

Important: you must add ".\" before the username. If you do not that, you get an error and your service will not be installed:

An exception occurred during the Install phase.
System.ComponentModel.Win32Exception: The account name is invalid or does not exist, or the password is invalid for the account name specified

1 commento:

Guerrino ha detto...

se si vuole installare il servizio come utente di un dominio, invece di ".\foo" utilizzare "domainname\foo".
Magari era scontato ma per i neofiti non è molto chiaro.