Click here to Skip to main content
16,018,802 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I create windows services & Event log in my project.But not run shortly below code:
VB
Dim ServicesToRun() As System.ServiceProcess.ServiceBase
ServicesToRun = New System.ServiceProcess.ServiceBase() {New NotificationService()}
System.ServiceProcess.ServiceBase.Run(ServicesToRun)

NotificationService is a constructor.
And msg is shown 'Cannot start service from command line or debugger. A Windows service mest first be install(using installutil.exe) and then start with the ServerExplorer, Windows Services Administrative tool or the NET START command'
Posted
Updated 21-Nov-11 1:25am
v2

1 solution

You need to do exactly what the message tells you. You are trying to run interactively the application designed to run hosted by the system service host only. You really need to install it and run using Services applet; use "Services.msc".

If you want to install with InstallUtil.exe: it works in conjunction with classes in the System.Configuration.Install namespace which you will need to implement.
See:
http://msdn.microsoft.com/en-us/library/50614e95%28v=VS.100%29.aspx[^],
http://msdn.microsoft.com/en-us/library/system.configuration.install.aspx[^].

You will need to provide implementation of ServiceProcessInstaller and ServiceInstaller, see:
http://msdn.microsoft.com/en-us/library/system.serviceprocess.serviceinstaller.aspx[^],
http://msdn.microsoft.com/en-us/library/system.serviceprocess.serviceprocessinstaller.aspx[^].

These are just links to the API you will need to get into it. You will need to learn these techniques thoroughly as they are not very simple and somewhat counter-intuitive. MSDN is your friend.

—SA
 
Share this answer
 
Comments
Abhinav S 21-Nov-11 13:43pm    
5. Useful to the OP.
Sergey Alexandrovich Kryukov 21-Nov-11 13:45pm    
Wow! You've been very fast.
Thank you, Abhinav.
--SA
Abhinav S 22-Nov-11 0:50am    
You are welcome. :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900