Using the ServiceInstall Table to install a Windows Service with custom properties
You know how when you build a Windows Service and then include a setup and deployment project with your application and then during the installation a Log in screen appears? There may come a time when you want to install a Windows Service silently and not see that log in screen.
First, I need to point out that the Windows Installer and the installer for the Windows service are two separate entities and Windows Installer has no influence on the service except to run the EXE. I've also tried passing properties to a service installer EXE manually but was not successful.
You have to remember that Visual Studio .NET in intended to build quick and simple MSI packages, nothing real involved, so it won't be of much help to us here. What I've found that does work is using ORCA to modify the MSI package and populate the ServiceInstall table with information needed to make your request work. To do that, please follow these steps:
1. Open your service/setup project in VS.NET. Remove the ServiceProcessInstaller and the ServiceInstaller from your project.
2. Build your MSI package.
3. I have attached a ZIP file containing a program called ORCA. In the ZIP file is a file, Orca.MSI that you will need to install.
4. Once you have installed Orca, go to the folder that contains your MSI file. Right click the MSI package and then left click on Open with Orca.
5. With the Orca program open, scroll down to the Property table on the left side and click it once to highlight it. Double click the first empty row in the right side of this table. We're going to create two new property values. For the first one, in the Property field enter any name, like USERNAME_FIELD and in the Value column enter NONE. Then click OK. Double left click the next empty row and follow the same instructions for creating a value for our password field. Call it something like PASSWORD_FIELD or whatever you prefer. These values will take the place of the UserName and Password prompts that you are used to seeing in the pop up dialog when you install a Windows service.
6. With the Orca program open, scroll down on the left side to the ServiceInstall table and click it once to highlight it. Double click the first empty row on the right side and populate the fields with the following info:
(info on the ServiceInstall table can be found at https://msdn.microsoft.com/library/default.asp?url=/library/en-us/msi/setup/serviceinstall_table.asp)
ServiceInstall - This is a primary key and can be set to any unique value such as 123123123ABC or ServiceTest1234567890
Name - This column is the string that gives the service name to install. The string has a maximum length of 256 characters. The service control manager database preserves the case of the characters in the service name, but comparisons of service names are case insensitive. Forward-slash (/) and back-slash (\) are invalid service name characters.
Display Name - This column is the localizable string that user interface programs use to identify the service. The string has a maximum length of 256 characters. The service control manager preserves the case of the display name, but display name comparisons are case insensitive.
ServiceType - 16 (see the ServiceType documentation in the link provided for tables that describe what these values are for)
StartType - 2 (see the StartType documentation in the link provided for tables that describe what these values are for)
ErrorControl - 1 (see the ErrorControl documentation in the link provided for tables that describe what these values are for)
LoadOrderGroup - (this can be left blank)
Dependencies - (this can also be left blank)
StartName - This will be one of the properties you created in the previous step that corresponds to the Machinename\Username that you would normally enter in the service install window that pops up. The property name needs to be included in square brackets, so for example, if you had a property name of USERNAME_FIELD it should be entered as [USERNAME_FIELD]
Password - This will be the other property that you created corresponding to the password for the previously mentioned machinename\username. Since it references a property, it should also be included in square brackets. For example, if the property name you created was PASSWORD_FIELD the value you entered would be [PASSWORD_FIELD]
Arguments - (This field can be left blank)
Component - This needs to be set to the same value that's in the first column of the Component Table for the service that you are installing. If you aren't sure which component value is for your service, look at the File table, you should see the executable for your service in the FileName column. The corresponding value in the Component column of this table will be the same as the Component column of the Component table.
7. Click File, Save at the top to save your changes. Note: Don't use the Save As option in ORCA as it incorrectly strips out information that we will need.
8. Now all that's left to do is install your MSI package. Try running it silently and passing the two property values that we created from a command prompt. The syntax will be something like:
C:\ServiceInstallTest.MSI /Q USERNAME_FIELD=MACHINENAME\USERNAME PASSWORD_FIELD=PASSWORD
where USERNAME_FIELD and PASSWORD_FIELD are the property values we created in Orca.
9. You can monitor the MSI Progress by looking as Task Manager (START, RUN, type TASKMGR) and looking at the Processes tab for MSIEXEC.EXE - you might see several of them running and that's normal.
10. After they disappear, you know the installation is complete. Go to START, RUN and type SERVICES.MSC and click OK to view the services and you should see your service in the list.