Simple Service

Jay1b

Contributor
Joined
Aug 3, 2003
Messages
640
Location
Kent, Uk.
I am trying to create a simple service, actually all it does is present a msgbox upon the start and end. But once thats working it would be easy to build upon.

Anyway i have created the deployment project, and tried running the service and i am presented with this message "cannot start service from the command line or a debugger. A windows service must first be installed using installutil.exe and then started with the serverexpl, windows services or the NET START command."

So after a bit of research i went and ran the c:\winnt\Microsoft.Net\etc.....\installutil projectname.exe and was presented with the following errorlog.

Could someone please tell me where to go from here, as it still doesnt work?

--------------------------------------------------
Installing assembly 'c:\program files\servicemsgbox_install\servicemsgbox.exe'.
Affected parameters are:
assemblypath = c:\program files\servicemsgbox_install\servicemsgbox.exe
logfile = c:\program files\servicemsgbox_install\servicemsgbox.InstallLog
No public installers with the RunInstallerAttribute.Yes attribute could be found in the c:\program files\servicemsgbox_install\servicemsgbox.exe assembly.
Committing assembly 'c:\program files\servicemsgbox_install\servicemsgbox.exe'.
Affected parameters are:
assemblypath = c:\program files\servicemsgbox_install\servicemsgbox.exe
logfile = c:\program files\servicemsgbox_install\servicemsgbox.InstallLog
No public installers with the RunInstallerAttribute.Yes attribute could be found in the c:\program files\servicemsgbox_install\servicemsgbox.exe assembly.
Remove InstallState file because there are no installers.
------------------------------------------------------------

Also can i automate the installutil bit somehow, its not very user friendly for users to do.


Thanks.
 
I think you need to add a class that derives from Installer.

e.x.:
Visual Basic:
using System;
using System.Collections;
using System.ComponentModel;
using System.Configuration.Install;

namespace ServiceRestarter
{
	/// <summary>
	/// Summary description for Installer1.
	/// </summary>
	[RunInstaller(true)]
	public class Installer1 : System.Configuration.Install.Installer
	{
		private System.ServiceProcess.ServiceProcessInstaller serviceProcessInstaller1;
		private System.ServiceProcess.ServiceInstaller serviceInstaller1;

		public Installer1()
		{
			InitializeComponent();
		}

		/// <summary> 
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				serviceProcessInstaller1.Dispose();
				serviceInstaller1.Dispose();
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}


		#region Component Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			this.serviceProcessInstaller1 = new System.ServiceProcess.ServiceProcessInstaller();
			this.serviceInstaller1 = new System.ServiceProcess.ServiceInstaller();
			// 
			// serviceProcessInstaller1
			// 
			this.serviceProcessInstaller1.Account = System.ServiceProcess.ServiceAccount.LocalSystem;
			this.serviceProcessInstaller1.Password = null;
			this.serviceProcessInstaller1.Username = null;
			// 
			// serviceInstaller1
			// 
			this.serviceInstaller1.DisplayName = "Service Restarter";
			this.serviceInstaller1.ServiceName = "Service Restarter";
			// 
			// Installer1
			// 
			this.Installers.AddRange(new System.Configuration.Install.Installer[] {
																					  this.serviceProcessInstaller1,
																					  this.serviceInstaller1});

		}
		#endregion
	}
}
 
Easy option for you - if you have the service open in the designer (not the code window), right click on it and select the 'Add Installer' menu option, rebuild and try again.
 
Thanks PD. The service now appears in the service list, but when i try to start it i get the following error:

"Could not start the 'ServiceName' service on Local Computer. The service did not return an error. This could be an internal windows error or an internal service error"

Would this be due to the way i installed it, or due to the code in the program? At the moment the only code is msgbox upon start and another msgbox upon stop.

Thanks
 
The problem is probably the message box, services do not interact with the current user's desktop but have one of their own - the message box is not visible and the service will block till you hit OK. Try writing to the event log instead
Visual Basic:
me.EventLog.WriteEntry("sdf")
should do the trick.

The second problem is that the on Start method should exit fairly promptly - normally you would launch your 'real' work on a new thread and then let the OnStart exit. If OnStart doesn't complete in a timely fashion then the OS will think it is hung and terminate it.
 
Brilliant Thanks once again :D

At the moment i am just playing with services, trying to get a simple basic one working, so i can then feel confident to build upon it and create a 'proper' project using them.
 
Jay1b said:
Brilliant Thanks once again :D

At the moment i am just playing with services, trying to get a simple basic one working, so i can then feel confident to build upon it and create a 'proper' project using them.

If you do want to have the service talk to the desktop, I would look into remoting as this will allow you to create 2 apps. The first would be the windows service, and the second would be a management App. This management app could be installed on an other computer so that they can manage the service.

Also if remoting is not the way you could always use raw sockets to do the talking between apps.
 
Cool....... Thats actually something i was planning to look into a bit down the line. Nice to know its name though, its hard to look something up, when you dont know what its called :)

Thanks
 
Windows installer issue on Windows 2000

I've created a service in VB.net that installs on two XP pro machines (both of which have Visual Studio installed), but when I attempt to run the installutil on a windows 2000 server (sp 4, has v.4322 framework), it gives me this error above:
No public installers with the RunInstallerAttribute.Yes attribute
The installer has been added to the project, and the class is there in the VB. In addition, it does install on the XP machines just fine.

I've ensured when I run the installUtil, I point to the exe in 4322, and I know the installer is part of the project

Just looking for any more answers if I can find them. Thanks.

kurt B
 
Kurt B said:
I've created a service in VB.net that installs on two XP pro machines (both of which have Visual Studio installed), but when I attempt to run the installutil on a windows 2000 server (sp 4, has v.4322 framework), it gives me this error above:
No public installers with the RunInstallerAttribute.Yes attribute
The installer has been added to the project, and the class is there in the VB. In addition, it does install on the XP machines just fine.

I've ensured when I run the installUtil, I point to the exe in 4322, and I know the installer is part of the project

Just looking for any more answers if I can find them. Thanks.

kurt B

I solved my own issue. I had created the service to run under the local service account. A look through the "installutil" log in the directory I ran the installutil.bat file showed an account log on error. I recompiled the service to run under localsystem, and it did install.
I'm an admin on the computer as a certain ID. This ID doesn't have access to other directories in our network. So, I'll need to run the service under a different ID. However, trying to start the service under any other ID doesn't work. Access denied. But it did install when I put the right account, so this problem is solved.
 
Back
Top