Question about Windows Service and Setup projects

B

B. Chernick

I am reviewing Windows service programming. I'm running VS2005 and
programming in VB. I've just found an example in Support: 'How to create a
Setup project for a Windows Service in Visual Basic .NET or in Visual Basic
2005'
http://support.microsoft.com/kb/317421

I've been able to program and run this example without problems.

However, I wonder if I'm missing the point here. How do you deploy a
service like this to a machine without Visual Studio installed?

(Admittedly I have little experience writing setup projects either.)
 
A

Alex Clark

When you create a Windows Service project in VS, it should include the
installer classes in the service project itself (ServiceInstaller,
ServiceProcessInstaller). As you've probably determined already, these
allow for a command line install/uninstall of the service --- fine if you're
a developer, not so much fun if you're a regular user.

That's where the Setup project comes into play. You create the Setup
project in VS and add it to your current solution (side by side your Service
project), telling it that you want to install the output of your service
project. The installer, when run, will detect the fact that your service
..exe contains special installer classes (ServiceInstaller,
ServiceProcessInstaller) and will call the install methods of those classes
during the install. This means that a nice Wizard-esque GUI can be used to
install/uninstall your service.

The Setup project compiles down to an MSI file and a "Setup.exe" file, which
can be run on the target user's computer without VS installed. It can even
be configured to download and install prerequisites like .NET 2.0 for
example.

-Alex
 
B

B. Chernick

Thanks! (Right under my nose...)

As long as we're on the subject, what is the recommended method for
'configuring' a windows service, in the sense of passing it string values
such as locations or user ids? Is there a way to create a popup within a
setup project for user entry during setup?

For that matter, I've noticed some programs in the 'Add or Remove' screen of
the control panel have 'Repair' options. Is it possible to create 'repair'
options within this same setup project, in order to update operating settings
using the same hypothetical popup?

(I'm not really sure I'm using the correct terminology so feel free to
correct me.)
 
A

Alex Clark

Hi,

With regards to custom forms during the install process, I *believe* it's
possible but you may find the Setup project quite restrictive in that sense.
Often times I've found that VS's Setup projects don't offer enough
flexibility for things like that (I am by no means a Setup expert though,
and could well be wrong).

If it were me, I'd have a settings file (XML or otherwise) residing
somewhere easily accessible (AppData folder) and have a separate config app
to edit it. The service .exe just reads the settings and uses them. You
could probably shell out to the config app as soon as Setup completes
successfully, indicating to the user that they must first configure the
settings before they can run the service successfully.

Of course then you have a minor challenge of having the service pick up the
new settings, but you could accomplish that by having the config application
automatically restart the service, or even use the FileSystemWatcher object
within the service to detect changes to the config file and respond
accordingly. Alternatively, it could just re-read the settings every 5
seconds or so, but that could be a tad inefficient!

As for the Add/Remove "Repair" option, I've found that if you've installed
the product and you then try to run the installer again (or even do an
Add/Remove from control panel) it should give you two options: Repair or
Remove. Repair should just run the install again in a moderately silent
mode, overwriting any binary files that are older than the ones it's
instructed to install.

For some deep customisation of a Setup project, Orca (available as a free
download from MS) is capable of editing the internal database of an MSI file
and no doubt doing various other things, but it's not for the faint hearted.
I looked up a relatively simple "How to create an MSI patch file with Orca"
from the MS webby, and found myself deciding not to bother investing too
much time into it.

There is yet another tool out there called WiX which many people swear by.
It's an open-source project on SourceForge and basically takes XML files as
its input in order to generate MSI files. I've personally never tried it,
but some users are pushing for WiX to replace the default Setup project in
VS (maybe it really is that good!). If you're doing a lot of Setup work, it
may well be worth investigating, but I suspect there's a learning curve
associated with it.

Be nice if MS would ramp up the Setup templates for VS and give them some
real power, other than just "Here's how you can do a fairly mundane default
install of your application". They seem to be lagging far behind in that
area....


-Alex
 
B

B. Chernick

Actually 'App_Data' only applies to Web apps, right? I suppose I could put
the xml in Resources?
 
A

Alex Clark

Hi,

There's a commonly available application data folder which is under the "My"
helper namespace:

My.Computer.FileSystem.SpecialDirectories.AllUsersApplicationData

Which will put you directly into a path where you can store application data
from a WinForms app. Be aware that it will include company name, app name,
and then the sub-folder will represent the version string (I tend to go up a
level and store it in the \appname folder for simplicity after upgrades).

It's good practice to use the above path rather than your own app directory
(i.e. somewhere in Program Files) because of security restrictions. The
former will play nicely with Vista, whereas the latter won't (ask me how I
know, lol).

Kind Regards,
Alex
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top