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
Solved

How to check a service is running then install an executable

Posted on 2011-02-22
3
414 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
  • 2
3 Comments
 
LVL 76

Accepted Solution

by:
David Lee earned 500 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

839 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