Link to home
Start Free TrialLog in
Avatar of Peanutter571
Peanutter571Flag for United Kingdom of Great Britain and Northern Ireland

asked on

How to check a service is running then install an executable

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.
ASKER CERTIFIED SOLUTION
Avatar of David Lee
David Lee
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Peanutter571

ASKER

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 ?
Yes, that would be correct.