Example Code

Install Application as Windows Service in LabVIEW

Products and Environment

This section reflects the products and operating system used to create the example.

To download NI software, including the products shown below, visit ni.com/downloads.

    Software

  • LabVIEW

Code and Documents

Attachment

Description

1. Overview:

This VI will automate the process of installing a application as a windows service to run in the background

 

2. Description: 

This VI automates the steps described in this KB in order to install an application as a Windows Service.

 

It requires that the Microsoft Resource Kit be installed. This kit can be installed for the following operating systems:

    • Windows XP
    • Windows Server 2003 family
    • Windows 7 

When installing the Microsoft Resource Kit in Windows 7, a compatibility issue pop up will appear. Skip it and continue with the installation.

 

3. Requirements

  • LabVIEW 2012 (or compatible)

4. Steps to Implement or Execute Code

  1. Assure that Microsoft Resource Kit is installed 
  2. Run LabVIEW as administrator
  3. Select a service name, provide application path and SrvAny.exe path (by default c:\Program Files\Windows Resource Kits\Tools\srvany.exe)
  4. When the process is complete check the service is created in Windows Service list

 5. Additional Information or References 

VI Snippet

Block Diagram.JPG

**This document has been updated to meet the current required format for the NI Code Exchange.**

Sappster

Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.

Comments
D60
Active Participant
Active Participant
on

Perfect!    

---
+++ In God we believe, in Trance we Trust +++
[Hungary]
Joe_Guo
Active Participant
Active Participant
on

It worked nicely, however, if the service name has space in it, it must be enclosed within a pair of quotes "%s".  In fact, i used this with a "Format Into String" primitive vi:

"%s" "%s" "%s"

in details:

"path_to_instsrv.exe" "my service name" "path_to_srvany.exe"

English (auto-detected) » English
Rashid-Malik
Active Participant
Active Participant
on

Service name with spaces and version number does not work. Any solutions? No even surrounding the service name with quotes did not help. The service name would register but then it would not start, not even manully, from windows services applet.

GretchenSkellyZimmer
Member
Member
on

will this work for Windows Server 2008?

Sappster
Member
Member
on

GretchenSkellyZimmer, I cannot confirm that it does but this post suggests that it will work: http://social.technet.microsoft.com/Forums/en-US/winserverMigration/thread/98a97aee-c62b-4683-94ab-3...

Sappster
mo786
Member
Member
on

I am running windows server 2008 R2 64bit. I noticed that on the Microsoft Resource Kit download page, the notes at the requirements states that it will not supported on 64 bit platforms. What should I do in this case?

battler.
Active Participant
Active Participant
on

Is this solution still applicable for Windows 7 and 8.1??

Sappster
Member
Member
on

Hi Battler,

I haven't tried this code on windows 7 or 8 so I can't confirm. Best thing to do would be try it and report back on your findings. I did however find this forum that suggests that the Windows 2003 Resources will function in later versions of the OS, but that it might have limited capabilities.

If I find time to test it I will let you know what I find.

Sappster
RJ_15
Member
Member
on

Hi,

I had tried it on a Win7 machine and am getting Error2- LabVIEW memory is Full error.

Any ideas ?

Runjhun.

Sappster
Member
Member
on

That sounds like a run-time issue related tot the application. Do you receive any issues when you are installing the service? Can you create a simple application to test that the service installs correctly?

Sappster
RJ_15
Member
Member
on

This error is coming from the System Exec.vi function. Hence, the service is not created/installed.

RJ_15
Member
Member
on

I have resolved the error now. The changes are refelcted in the registry but it doesn't have the registry key 'Application' = "App path".

And its not visible in the 'servcies.msc' list.

Sappster
Member
Member
on

Create indicators for the system exec standard output and error output. I ran a test on a win 7 computer and received permissions errors for the instsrv call. You will have to run this with administrative privileges. You might find this forum thread of interest: Running system exec vi as administrator in win7

Sappster
Antipholus
Member
Member
on

Note: The Windows Server 2003 Resource Kit Tools are not supported on 64-bit platforms.This is from the system requirements at the Microsoft download site. So... how does one install a LabVIEW application as a WinService on Win 7 - 64-bit since this resource kit cannot be used.

Not applicable
on

Hello,

I did it the same way. It is a pain. But I found that it is much easier with this: https://nssm.cc/

It has an User Interface to create the Service easily.
It much better & Freeware and there is also a 64 Bit Version.

Kegraus
Member
Member
on

It is working on W7 without any problems.