Services under VisualBasic.Net

This blog is a way to help those unfortunates who are wanting to write a service in VB.NET. I have done this and I have seen the light. I am saved, since I read it all in a good book 🙂

There is an article on WROX about an error of System.ComponentModel.Win32Exception: The account name is invalid or does not exist, or the password is invalid for the account name specified. The simple solution to this is when InstallUtil is used that the full account name MUST be used. Rather than use “Darryl”, you must use “DELL-8600Darryl”. And the slash must be the right direction. And then you MUST get the password case right too.

This assumes that the user exists. You can add a user and edit the password in the control panel. But what you cannot do is to give the user the permission to actually do what it needs to do. You must go to Local Security Settings, and then find Local Policies, and then User Rights Assignment. There you must open up Log In As A Service, and add the user.

Another trick is making sure that the service starts when it is started. If OnStart does not stop, then the service will stop. Read that again, and it will make sense. If OnStart does not return quickly, the service will not be killed.

Now, another thing that happened was that I was having the service die soon after starting. This took some figuring, but looking at the event viewer found the solution. I had forgot to init a variable. Simple mistake.

So, how do you start a service by hand. Well, you run InstallUtil, and tell it to install it. Fairly simple. But you must have already told VB that there is an installer in your code which this installer looks for in order to install.

Here endeth my brain dump. I wonder where I can buy a farm cheap – one where there is no electricity or a phone so I want even be temted to use this horrible PC.