Quantcast
Channel: Setup Deployment forum
Viewing all articles
Browse latest Browse all 2818

Adding a Custom Script...and getting it to run.

$
0
0

Afternoon, I am having a bit of difficulty getting a bog standard vbs script to run.

We are a school and have purchased quite a few ACER Switch 10, tablet / laptop hybrid devices which has really caused a shed load of issues.

However for now I want to focus on a specific task. I created a custom Windows 8.1 Ent x86 image, loaded up the various pieces of software, one of which was Sophos AV. Normally Sophos agents are deployed over the domain through a management console, but the ACERs are standalone and won't be on the domain anytime soon, so not an option.

So rather then have to manually install Sophos on all these devices once imaged, I decided to add the AV software to the master image. Using the Sophos instructions I had to remove some reg entries and disable some services prior to capturing the image.

I deployed the image to some test ACERs - all worked well. However as it stands it means I have  to log into the device and manually enable the Sophos services again which is a pain.

So I put together some code sourced of the net, copied it over to the scripts folder on the share, finally adding a 'Post Install' task' Run Command Line', just before the 'Computer Restart'. In the 'Command Line box I have put:

cscript.exe "%SCRIPTROOT%\SOPHOSSRVS.wsf     - but it doesn't seem to run.

If I run this script directly on a newly imaged Win 8.1 Client, logged on a locak Admin, I have to run open  an administrative CMD prompt, then run the script, this it works.

I don't seem to be able to automate this during the process and all out of ideas. Any help greatly appreciated and understand I am not a scripting guy.

Below the code:

<job id="SOPHOSSRVS">

 <script language="VBScript">

'Start Sophos Anti Virus SAV Service
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

Set colServiceList = objWMIService.ExecQuery _
    ("Select * from Win32_Service where Name = 'SAVService'")

For Each objService in colServiceList
    If objService.State = "Running" Then
        objService.StopService()
        Wscript.Sleep 5000
    End If
    errReturnCode = objService.ChangeStartMode("Automatic")  
Next

'Start Service
 strServiceName = "SAVService"
 Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
 Set colListOfServices = objWMIService.ExecQuery ("Select * from Win32_Service Where Name ='" & strServiceName & "'")
 For Each objService in colListOfServices
 objService.StartService()
 Next
 
'Start Sophos Anit Virus Admin Reporter SAVAdminSerice
 strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

Set colServiceList = objWMIService.ExecQuery _
    ("Select * from Win32_Service where Name = 'SAVAdminService'")

For Each objService in colServiceList
    If objService.State = "Running" Then
        objService.StopService()
        Wscript.Sleep 5000
    End If
    errReturnCode = objService.ChangeStartMode("Automatic")  
Next

'Start Service
 strServiceName = "SAVAdminService"
 Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
 Set colListOfServices = objWMIService.ExecQuery ("Select * from Win32_Service Where Name ='" & strServiceName & "'")
 For Each objService in colListOfServices
 objService.StartService()
 Next
 
'Start Sophos AutoUpdate Service Auto Update Service
 
  strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

Set colServiceList = objWMIService.ExecQuery _
    ("Select * from Win32_Service where Name = 'Sophos AutoUpdate Service'")

For Each objService in colServiceList
    If objService.State = "Running" Then
        objService.StopService()
        Wscript.Sleep 5000
    End If
    errReturnCode = objService.ChangeStartMode("Automatic")  
Next

'Start Service
 strServiceName = "Sophos AutoUpdate Service"
 Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
 Set colListOfServices = objWMIService.ExecQuery ("Select * from Win32_Service Where Name ='" & strServiceName & "'")
 For Each objService in colListOfServices
 objService.StartService()
 Next

'Start Sophos Web Filter swi_filter

  strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

Set colServiceList = objWMIService.ExecQuery _
    ("Select * from Win32_Service where Name = 'swi_filter'")

For Each objService in colServiceList
    If objService.State = "Running" Then
        objService.StopService()
        Wscript.Sleep 5000
    End If
    errReturnCode = objService.ChangeStartMode("Automatic")  
Next

'Start Service
 strServiceName = "swi_filter"
 Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
 Set colListOfServices = objWMIService.ExecQuery ("Select * from Win32_Service Where Name ='" & strServiceName & "'")
 For Each objService in colListOfServices
 objService.StartService()
 Next
 
'Start Sophos Web Intelligence Service swi_service

  strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

Set colServiceList = objWMIService.ExecQuery _
    ("Select * from Win32_Service where Name = 'swi_service'")

For Each objService in colServiceList
    If objService.State = "Running" Then
        objService.StopService()
        Wscript.Sleep 5000
    End If
    errReturnCode = objService.ChangeStartMode("Automatic")  
Next

'Start Service
 strServiceName = "swi_service"
 Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
 Set colListOfServices = objWMIService.ExecQuery ("Select * from Win32_Service Where Name ='" & strServiceName & "'")
 For Each objService in colListOfServices
 objService.StartService()
 Next
 
 </script>
</job>

 


Viewing all articles
Browse latest Browse all 2818

Trending Articles