Solved

vbs to stop Sophos services prior to removal

Posted on 2015-01-22
1
224 Views
Last Modified: 2016-02-25
I have a script to stop all services as a pre-deployment task prior to uninstalling Sophos from a Windows 7 PC.
The works fine when I deploy manually on the PC and stops all the services. However via the deployment tool, the services don't stop. When I monitor processes I do see wscript running and among other things trustedinstaller. I am possibly thinking that the script runs, but the services haven't stopped before the uninstallation begins. The script is below, any idea on how to stop the script from finishing until all services were stopped? (to test this theory)

StopService ".", "Sophos Agent", True
StopService ".", "SAVService", True
StopService ".", "SAVAdminService", True
StopService ".", "Sophos AutoUpdate Service", True
StopService ".", "Sophos Device Control Service", True
StopService ".", "Sophos Message Router", True
StopService ".", "Sophos Web Control Service", True
StopService ".", "swi_service", True

Sub StopService(Computer, ServiceName, Wait)
  Dim cimv2, oService, Result

  'Get the WMI administration object    
  Set cimv2 = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _
    Computer & "\root\cimv2")

  'Get the service object
  Set oService = cimv2.Get("Win32_Service.Name='" & ServiceName & "'")
 
  'Stop the service
  Result  = oService.StopService
0
Comment
Question by:kwatt562
1 Comment
 
LVL 76

Accepted Solution

by:
David Lee earned 500 total points
ID: 40567061
Try this

StopService ".", "Sophos Agent", True
StopService ".", "SAVService", True
StopService ".", "SAVAdminService", True
StopService ".", "Sophos AutoUpdate Service", True
StopService ".", "Sophos Device Control Service", True
StopService ".", "Sophos Message Router", True
StopService ".", "Sophos Web Control Service", True
StopService ".", "swi_service", True

Sub StopService(Computer, ServiceName, Wait)
	Const MAX_LOOPS = 20
	Dim cimv2, oService, Result, iLoop, bStopped
	
	'Get the WMI administration object    
	Set cimv2 = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _
	Computer & "\root\cimv2")
	
	'Get the service object
	Set oService = cimv2.Get("Win32_Service.Name='" & ServiceName & "'")
	
	'Stop the service
	Result  = oService.StopService 
	
	'Test to see if the service has stopped
        bStopped = False
	For iLoop = 1 To MAX_LOOPS
		Set oService = cimv2.Get("Win32_Service.Name='" & ServiceName & "'")
		If oService.State = "Stopped" Then
                        bStopped = True
			Exit For
		Else
			WScript.Sleep 500 
		End If
	Next
        If Not bStopped Then
            Msgbox "I was unable to stop the " & ServiceName & " service.", vbCritical + vbOkOnly
        End If
 End Sub

Open in new window

0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

This script will sweep a range of IP addresses (class c only, 255.255.255.0) and report to a log the version of office installed. What it does: 1.)      Creates log file in the directory the script is run from (if it doesn't already exist) 2.)      Sweep…
Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

744 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now