PC Review
Forums
Newsgroups
Microsoft DotNet
Microsoft Dot NET Framework
Self installing services
Forums
Newsgroups
Microsoft DotNet
Microsoft Dot NET Framework
Self installing services
![]() |
Self installing services |
|
|
Thread Tools | Rate Thread |
|
|
#1 |
|
Guest
Posts: n/a
|
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? |
|
|
|
#2 |
|
Guest
Posts: n/a
|
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? > |
|
|
|
#3 |
|
Guest
Posts: n/a
|
"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 |
|
|
|
#4 |
|
Guest
Posts: n/a
|
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 > > > |
|
![]() |
|
| Thread Tools | |
| Rate This Thread | |
|
|

Main Page 

