PC Review Forums Newsgroups Microsoft DotNet Microsoft Dot NET Framework Self installing services

Reply

Self installing services

 
Thread Tools Rate Thread
Old 24-11-2004, 11:13 PM   #1
=?Utf-8?B?QnVyZ2E=?=
Guest
 
Posts: n/a
Default Self installing services


I have a simple service written in VB.net that can be installed and removed
successfully using srvinst. I'd like to make this file self installing though
(for example, run from the command line with an argument to get it
instantiated in the SCM). I've done this in the past by calling createprocess
WinAPI directly... but I'm guessing there must be a way to do this better in
VB.Net. I began looking at calling the Install method on ServiceInstaller and
ServiceProcessInstaller, but anything I try fails with a crash. From what I
can tell, MS does not expect you to write to these methods as they are to be
called by install programs. Usage and examples are hard to find.

Does anybody know how to call the ServiceInstall and ServiceProcessInstall
methods to install the service successfully?
  Reply With Quote
Old 25-11-2004, 12:19 AM   #2
Hayato Iriumi
Guest
 
Posts: n/a
Default Re: Self installing services

Hello Burga,

If you are trying to install Windows Service created by VB .NET, can't you use InstallUtil to install it? What exactly do you need to accomplish on installation?

> I have a simple service written in VB.net that can be installed and
> removed successfully using srvinst. I'd like to make this file self
> installing though (for example, run from the command line with an
> argument to get it instantiated in the SCM). I've done this in the
> past by calling createprocess WinAPI directly... but I'm guessing
> there must be a way to do this better in VB.Net. I began looking at
> calling the Install method on ServiceInstaller and
> ServiceProcessInstaller, but anything I try fails with a crash. From
> what I can tell, MS does not expect you to write to these methods as
> they are to be called by install programs. Usage and examples are
> hard to find.
>
> Does anybody know how to call the ServiceInstall and
> ServiceProcessInstall methods to install the service successfully?
>


  Reply With Quote
Old 25-11-2004, 02:04 AM   #3
David Browne
Guest
 
Posts: n/a
Default Re: Self installing services


"Burga" <Burga@discussions.microsoft.com> wrote in message
news:C73F2C8D-A4A9-4212-840F-6113DBF8B0B1@microsoft.com...
>I have a simple service written in VB.net that can be installed and removed
> successfully using srvinst. I'd like to make this file self installing
> though
> (for example, run from the command line with an argument to get it
> instantiated in the SCM). I've done this in the past by calling
> createprocess
> WinAPI directly... but I'm guessing there must be a way to do this better
> in
> VB.Net. I began looking at calling the Install method on ServiceInstaller
> and
> ServiceProcessInstaller, but anything I try fails with a crash. From what
> I
> can tell, MS does not expect you to write to these methods as they are to
> be
> called by install programs. Usage and examples are hard to find.
>
> Does anybody know how to call the ServiceInstall and ServiceProcessInstall
> methods to install the service successfully?


Create your service following this walkthrough
http://msdn.microsoft.com/library/d...application.asp

You will add an installer class to your service assembly. This installer
class knows how to intall or install your service. Usually the installer
class is invoked by the InstallUtil utility. Here's a description of what
InstallUtil does

Installutil.exe uses reflection to inspect the specified assembly and find
all Installer types with the RunInstallerAttribute set to true. The tool
then executes either the Install Method or the Uninstall Method on each
instance of the Installer type. Installutil.exe performs installation in a
transactional manner; if one of the assemblies fails to install, it rolls
back the installations of all other assemblies. Uninstall is not
transactional.

http://msdn.microsoft.com/library/d...tallutilexe.asp


Here's an article on how to write your own code to invoke your installer, so
you don't need installUtil

http://groups.google.com/groups?sel...m&output=gplain


David


  Reply With Quote
Old 29-11-2004, 11:13 PM   #4
=?Utf-8?B?QnVyZ2E=?=
Guest
 
Posts: n/a
Default Re: Self installing services


Thanks David. I tried making that work, but I get the following exception
when I try to set the context.
An unhandled exception of type 'System.NullReferenceException'
occurred in system.configuration.install.dll

Additional information:
Object reference not set to an instance of an object.

I am working in VB.net, so I had to change the provided code a little from
the c# sample. I experimented a little also, and the following is what I
currently have:

Dim ti As New TransactedInstaller
Dim mi As New ProjectInstaller
Dim cmdline(1) As String

ti.Installers.Add(mi)
cmdline(0) =
System.Reflection.Assembly.GetExecutingAssembly().Location
ti.Context = (New InstallContext("", cmdline))
ti.Install(New Hashtable)

Any idea why I should be getting that exception when setting ti.exception?
This might be really obvious to someone who has done this before...

Thanks!


"David Browne" wrote:

>
> "Burga" <Burga@discussions.microsoft.com> wrote in message
> news:C73F2C8D-A4A9-4212-840F-6113DBF8B0B1@microsoft.com...
> >I have a simple service written in VB.net that can be installed and removed
> > successfully using srvinst. I'd like to make this file self installing
> > though
> > (for example, run from the command line with an argument to get it
> > instantiated in the SCM). I've done this in the past by calling
> > createprocess
> > WinAPI directly... but I'm guessing there must be a way to do this better
> > in
> > VB.Net. I began looking at calling the Install method on ServiceInstaller
> > and
> > ServiceProcessInstaller, but anything I try fails with a crash. From what
> > I
> > can tell, MS does not expect you to write to these methods as they are to
> > be
> > called by install programs. Usage and examples are hard to find.
> >
> > Does anybody know how to call the ServiceInstall and ServiceProcessInstall
> > methods to install the service successfully?

>
> Create your service following this walkthrough
> http://msdn.microsoft.com/library/d...application.asp
>
> You will add an installer class to your service assembly. This installer
> class knows how to intall or install your service. Usually the installer
> class is invoked by the InstallUtil utility. Here's a description of what
> InstallUtil does
>
> Installutil.exe uses reflection to inspect the specified assembly and find
> all Installer types with the RunInstallerAttribute set to true. The tool
> then executes either the Install Method or the Uninstall Method on each
> instance of the Installer type. Installutil.exe performs installation in a
> transactional manner; if one of the assemblies fails to install, it rolls
> back the installations of all other assemblies. Uninstall is not
> transactional.
>
> http://msdn.microsoft.com/library/d...tallutilexe.asp
>
>
> Here's an article on how to write your own code to invoke your installer, so
> you don't need installUtil
>
> http://groups.google.com/groups?sel...m&output=gplain
>
>
> David
>
>
>

  Reply With Quote
Reply



Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off