LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Windows Service

Hi,
 
I have been trying for a while to write some windows services using various versions of labview.  In the past I have used srvany or even firedemon.  This time I need to do it properly as I want to take advantage of the fact that windows will be able to act as a watchdog for my service, not to mention more graceful exit.
 
Looking at the winapi it seems quite straight forward.  Windows calls your service program main, your then have to call it back (startServiceCtrlDispacher())  with the function you want it to run as a service.  Windows will then call this function etc...
 
Immediate problem is Labview datatypes.  Allot of the win32 service api functions use structures that dont seem possible to create from labview using a call library function.
 
Before I invest allot of time on this, writing wrapper dlls etc. I really wanted to see if anone has done this before?  I think there could be some show stoper alsong the way, like how will windows call back a function name, would a lv written dll be the answer or just multiple top level VIs in one exe?
 
For me it actually seems strange that creating a service is not a built in feature of LV?  Services seem the perfect answer for most process control?
 
I really would appreciate any help or comments.
 
Pete
 
 
 
 
Message 1 of 5
(4,667 Views)
Creating services is not a built in part of LabVIEW as the use of services is generally only in advanced applications. Also code running as a service needs to be very well written as it is running constantly. Making this easily accessible to all users could cause a lot of problems for people who don't understand fully how services work.

What data structures are you having trouble with and what dll are you using? I have have only used srvany and firedemon before aswell, never done it through the win32 API.

Regards

Jon B
Applications Engineer
NI UK & Ireland
Message 2 of 5
(4,634 Views)

There is an example on NI website teach you how to do this:

Creating a Windows NT Service Using LabVIEW: http://zone.ni.com/devzone/cda/tut/p/id/3185

 

George Zou

http://gtoolbox.yeah.net

 

 

George Zou
Message 3 of 5
(4,621 Views)

Thanks for the replies. 

George, I think that link just goes back to the old srvany bodge which isn't really the solution I was after in this case.

Jon, I hadent actually got to any coding yet - still very much in the design phase.

The first api call I think should be the following: 
Advapi32.dll StartServiceCtrlDispatcher(const SERVICE_TABLE_ENTRY* lpServiceTable)
http://msdn2.microsoft.com/en-us/library/ms686324.aspx
Where lpServiceTable is a pointer to an array of structures with each structure being more pointers to service main functions.

There are a few people on the web who seem to have simplified what is available on MSDN:

http://www.google.co.uk/search?hl=en&q=write+windows+service&meta=
(first link is quite good but sometimes dosent respond so try googles cache)

Thing is while I'm sure most of the problems calling these functions can be overcome either with some creative datatype use in LV or a simple wrapper dll I'm more concerned about getting 90% of the way through and finding something that just isnt possible in LV - like if the windows service manager can't call back the service by function name or something. 

I'm still a little surprised there is not more demand for this. - Some of the places I have worked have security policies in place that don't allow process software to run on logged in machines, this seems more and more common actually.

Again I'm very grateful for any comments.

Pete

0 Kudos
Message 4 of 5
(4,600 Views)


@petere wrote:
Hi,
 
I have been trying for a while to write some windows services using various versions of labview.  In the past I have used srvany or even firedemon.  This time I need to do it properly as I want to take advantage of the fact that windows will be able to act as a watchdog for my service, not to mention more graceful exit.
 
Looking at the winapi it seems quite straight forward.  Windows calls your service program main, your then have to call it back (startServiceCtrlDispacher())  with the function you want it to run as a service.  Windows will then call this function etc...
 
Immediate problem is Labview datatypes.  Allot of the win32 service api functions use structures that dont seem possible to create from labview using a call library function.
 
Before I invest allot of time on this, writing wrapper dlls etc. I really wanted to see if anone has done this before?  I think there could be some show stoper alsong the way, like how will windows call back a function name, would a lv written dll be the answer or just multiple top level VIs in one exe?
 
For me it actually seems strange that creating a service is not a built in feature of LV?  Services seem the perfect answer for most process control?
 
I really would appreciate any help or comments.
 
Pete 


While the service API is not really very complicated it is a bit difficult to interface to LabVIEW since you need to provide callback possibilities into LabVIEW to inform your app about system events. This is not just doable with some simple Call Library Node calls. You really need some intermediate DLL doing some translation work for you and also implement some kind of queue that can be updated from your code and polled by LabVIEW (or since LabVIEW 7.1 possibly be implemented as user event).

This is quite some work to do and if you want to safe yourself that work you can go to http://www.citengineering.com/pagesEN/products/service.aspx
and checkout that library. Sorry it is not free.

Rolf Kalbermatter

Message Edited by rolfk on 02-13-2007 09:08 AM

Rolf Kalbermatter  My Blog
DEMO, Electronic and Mechanical Support department, room 36.LB00.390
Message 5 of 5
(4,587 Views)