Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How to check a service is running then install an executable

Posted on 2011-02-22
3
Medium Priority
?
419 Views
Last Modified: 2012-05-11
Hi this is my first question here and I'm new to VBScript as well, so apologies before hand.

I'm trying to build a VBS logon script that will check to see if a particular service is running (e.g wuauserv), then based on the result true/false either continue with the rest of the script or install an .exe file.
Ideally I would like a message box to be displayed informing the user that the exe is installing and it will take a few minutes to complete.

Currently this is done with a batch similar to the below

       ECHO.
      ECHO Update
      ECHO.
      ECHO Installing so and so  this might take a few minutes

      SC query wuauserv | find "RUNNING"
      ECHO.%ERRORLEVEL%
      IF NOT ERRORLEVEL=1 goto service_OK
      "%logonserver%\netlogon\logon\wsus.exe"
      :Service_OK



OS is Windows XP and 7

Any help will be much appreciated.
0
Comment
Question by:Peanutter571
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 76

Accepted Solution

by:
David Lee earned 2000 total points
ID: 34956858
Hi, Peanetter571.

This should do it.
On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select State from Win32_Service WHERE Name='wuauserv'",,48)
For Each objItem in colItems
    If objItem.State = "Running" Then
        WScript.Echo "Installing executable.  This may take a few minutes."
        'Your installation code goes here'
    End If
Next

Open in new window

0
 

Author Comment

by:Peanutter571
ID: 34959175
Great thanks very much BlueDevilFan, would I be right in thinking then if I changed the code to

 If NOT objItem.State = "Running" Then
        WScript.Echo "Installing executable.  This may take a few minutes."
        'Your installation code goes here'
    End If

Open in new window


This would look to see if the service state was not running i.e not installed ?
0
 
LVL 76

Expert Comment

by:David Lee
ID: 34962756
Yes, that would be correct.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question