Coding Services

  • Thread starter Thread starter Christoph Duesmann
  • Start date Start date
C

Christoph Duesmann

Hi !

I wan't to code a service which will be installed on some clients in our
network.
The service should have the following features :

- Scan all properties of the Client (Hardware, Software etc)
- Create a log (eg. logfile.txt)
- Optional : Insert the data directly in an SQL-Database
- All these functions should occur, when a Timer elapsed or when I send a
command to do this.

My problem : Up to the manual command all functions have been implemented.
So, my question is : How can i communicate with these services to do things
when i want them to do ?
For better understanding : The service has started succesfully and is now
waiting for commands like "Start Scan"

Thanks !!!!!

Christoph
 
H Ghrisoph,

In my opinion is all you ask as samples in the resource kit

Using WMI
The service sample has a part for updating the logfile
Data Entry sample shows how to update the database.
And there are more timer samples.

See the links bellow

I hope this helps?

Cor

VB.net Resource kit
http://msdn.microsoft.com/vbasic/vbrkit/default.aspx

And if you have problems installing the resource kit
http://msdn.microsoft.com/vbasic/vbrkit/faq/#installvdir

Another resource for learning is the Quick Starts
http://samples.gotdotnet.com/quickstart/
I hope this helps a little bit?

Cor
 
Hi Cor !

thanks for answering my question.
But my only problem is to "trigger" my service to start the scan.
All other functions are already implemented.

Christoph
 
Hi Chrisoph,

I thought that that was as well in the service sample from the resource kit,
however from that one I am not completly sure.

Cor
 
Christoph,
The easiest way to have a service accept a "command" to do something is to
override the ServiceBase.OnCustomCommand method and have it call the same
procedure your Timer.Elapsed event handler calls.

Then you can use ServiceController.ExecuteCommand to invoke this custom
command.

Note I would probably define an Enum of CustomCommands that my service
supported so its easier to keep track of them. A custom command for
OnCustomCommand is an integer between 128 & 256, which also means you can
have multiple custom commands defined.

Remember that ServiceController can control services on your local machine
as well as services on remote machines. Note you may need to configure the
various machines to allow remote control of services.

An alternative, more flexible method, which also entails more work, is to
enable your service for .NET Remoting. You could either make it a .NET
Remoting Server, in which case you call a method to have it perform some
action, or a .NET Remoting Client, and possible handle an "update data
event" on your server remoting object that says to update data...

Both of the custom commands & remoting with a service are discussed in
Matthew MacDonalds book "Microsoft Visual Basic .NET Programmer's Cookbook"
from MS Press.

Hope this helps
Jay
 
Back
Top