Installing Windows Services
Previous Top Next

Thinstall allows you to deploy Windows Service Applications in one of 2 ways. One method only provides protection for the byte code and uses the user's pre-installed .NET Framework. The second method allows you to link all the required portions of the .NET Framework with your Windows Service Application so that it can be installed and run without installing the .NET Framework.

The typical procedure for Installing Windows Services written for the .NET platform is to use the utility InstallUtil.exe.
Because a program packaged with Thinstall is no longer a .NET assembly, installation as a system service differs slightly.


Installing a Thinstall protected .NET Windows Service for applications that do not Link with the .NET Framework

1. You must enable the option "Thinstall Loads all EXEs". This permits the any program your program executes directly to access the original version of your files. For best security purposes, we recommend linking the .NET Framework with your EXE (see discussion below).

2. You will modify your program's Main function so that checks for command-line arguments to install or uninstall the service. When it sees these command-line arguments, it will execute InstallUtil.exe.

Example source code:

static string GetFrameworkPath()
{
return
Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\.NETFramework").GetValue("InstallRoot").ToString();
}

static
string GetExeName()
{
return
System.Reflection.Assembly.GetExecutingAssembly().Location;
}

static
void Main( string [] args)
{
IList a=args;

if
(a.Contains("-install"))
Process.Start(GetFrameworkPath() + "v1.1.4322\\InstallUtil.exe", "\""+GetExeName()+"\"");
else
if (a.Contains("-uninstall"))
Process.Start(GetFrameworkPath() + "v1.1.4322\\InstallUtil.exe", "-uninstall " + "\""+ GetExeName()+"\"");
else
{
// Run Service Normally
System.ServiceProcess.ServiceBase[] ServicesToRun;
ServicesToRun = new
System.ServiceProcess.ServiceBase[] { new Service1() };
System.ServiceProcess.ServiceBase.Run(ServicesToRun);
}
}




Installing a .NET Windows Service for applications that Link with the .NET Framework

In this case you do not need to enable the option "Thinstall loads all EXEs". Instead you should add InstallUtil.exe directly to your project file so it can be run by your program directly from the archive. The code above works exactly the same when the .NET Framework is linked with your EXE, but in this case InstallUtil.exe will be run directly from your Thinstall package.

How to add InstallUtil.exe to your project:
1. Drag the file from c:\windows\microsoft.net\framework\v1.1.4322\InstallUtil.exe to your Thinstall project Window
2. Select any Virtual Path option from the list presented (none are appropriate)
3. Double click on InstallUtil.exe in your project file
4. Edit the virtial path to read %InstallPath%\Framework_files\v1.1.4322\InstallUtil.exe

When you link the .NET Framework with your application, you can install and run the service without installing the .NET Framework on the user's computer.
Simply type "Myprogram.exe -install" to install the service, and "Myprogram.exe -uninstall" to remove it.