Example of Installation
This is a short tutorial which explain you how to install a universal windows service inside your own C# software package.
We want to install a service which must be manually started and runs different applications like the notepad every 20 minutes for example.
Firstly you have to download the latest version. Therefore you would only need the binaries of UWS package.
After downloading the packed file you must extract the binaries into a directory you want. Should be someone inside your installation directories.
Before you could use the installation class you have to copy the files to their working directory or installation destination because the installation class uses the current path of assembly for service installation. Also you have to leave the whole UWS files together in one directory.
Now you have to add the following code to your C# installation program. The following includes are neeeded.
This code example is a part of the installation routine which installs the service with given name, description and so on. Errors would be recorded in the multi line text box 'txtStatus'.
And now a simple code example for uninstalling the universal windows service.
For all possible properties of the installer class see the SDK Reference.
Configure the service
After you have installed your software package and the UWS you have to generate a so called configuration file for the service to tell the UWS what he should do. This file must be a xml file with the following content.
<uws> <!-- settings of the logging (using log4net) - see log4net documentation for further information --> <log4net> <appender name="File" type="log4net.Appender.FileAppender"> <file value="uws.log"/> <appendToFile value="true"/> <layout type="log4net.Layout.PatternLayout"> <conversionPattern value="%date [%thread] %-5level %logger - %message%newline"/> </layout> </appender> <logger name="uws"> <level value="ALL"/> <appender-ref ref="File"/> </logger> </logger name="Notepad"> <level value="ALL"/> <appender-ref ref="File"/> </logger> </log4net> <!-- configuration of the universal windows service by itself --> <application name="Notepad" enabled="true"> <executable> <path value="c:\winnt\notepad.exe"/> </executable> <triggers> <trigger type="uws.Triggers.IntervalTrigger"> <minutes value="20"/> </trigger> </triggers> </application> </uws>
Now save this text file in the installation directory of your software package where the binary files of the UWS are. The file must have the name of our service which here would be uniserv.config.
After that you could start the UWS service by clicking the start button at the windows service management dialog shown below
Now every 20 minutes a notepad would be started until you stop the service or reboot. Try it!