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

asked on

vbs to stop Sophos services prior to removal

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
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