Windows services management

Wow, it's been a long time since I last updated the blog. Life, you know.

OK, today I bring you a very simple library to manage the Windows services you may have created (either with LabVIEW or in another language, it doesn't matter). These VIs allow to install and uninstall the service, as well as running it, stopping it and getting its current status. A lot of extra functionalities could be added if ever needed, you'll see they're extremely easy to use and modify.

Download Services LLB (library and class for LabVIEW 2016)

The main part of the library is made up of service.lvclass, a LabVIEW class that wraps the provided functions: install, start, stop, get status and uninstall. Maybe using GOOP here is overkill, but it's easier this way, just deploy init and close to create and dispose an instance and call the other VIs in between. This class uses .NET methods inside and as such is only valid for a Windows OS, but we are talking about Windows services here, so no problem 😉.

Now, if you open service.lvlib (the tree screenshot is on the right) you'll see that, aside from the LV class, there are some non .NET functions (up in the tree). They rely in command-line execution and Windows registry access, and are needed at least to install and uninstall the service. There are also some methods for starting, stopping and getting the service status through CLI; as I said before the class uses .NET for the same functionalities but I thought you may still find them useful as standalones and so I have put them outside the class.

Alright, let's go with the operation. If your service is already installed, you just need its name to identify it. Be careful, the service name is not the name that appears on the service list (services.msc), that's just the public name. Right-click on the service and select "properties" to retrieve the actual service name. Pass this name to init.vi and go ahead running it or whatever you want.

If the service is not installed the class initialization will go on, but obviously you won't be able to do anything with the service. Install it through install.vi and pass as inputs the public name, the associated exe file and, optionally, its dependencies (these are already installed services that this service will depend upon). Once this is done, continue as previously, for example running it.

And that's it. Play with the functions and remember that adding new ones (for advanced service management) will be as easy as deploying the appropriate .NET methods and properties.

Comentarios

Entradas populares de este blog

SNMP library for LabVIEW

Base64 Encoding

Retrieve CPU temperature