none
Running a Custom Script Post Deployment RRS feed

  • Question

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

    One other thing of note is that I have got it to a point of trying to apply the code but fails with what I understand is a permissions error: LiteTouch Deployment failed, Return Code = -2147467259 0x80004005; The specified service does not exist as an installed service. Error 00000424.

    To make sure the code was indeed working on a new imaged machine with the Sophos AV services disabled I ran the script - it wouldn't work until I ran it from an administrative cmd prompt. Is this then a case that to run the script the privledges aren't high enough?

    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>


    • Edited by seanhaynes Monday, March 2, 2015 6:27 AM
    Saturday, February 28, 2015 6:44 AM

All replies

  • I did notice your quotations are off. Your missing one at the end of your command line....
    Monday, March 2, 2015 3:13 AM
  • ....ah that's actually a typo on the post - it does have it within MDT.

    cheers

    Monday, March 2, 2015 6:26 AM
  • Have you tried adding .wsf as an application and running it like that?
    Tuesday, March 3, 2015 7:00 PM
  • no I haven't - I'll give that a go tomorrow!
    Tuesday, March 3, 2015 7:36 PM
  • Sean,

    I would suggest never putting av software on an image. Sophos allows you to download the standalone client as part of the sub. I image computers not on the domain and add sophos standalone silently in the TS.

    -tip

    Wednesday, March 4, 2015 2:37 PM
  • YES YES YES.. AV software should NEVER be part of the image. I thought in Sean's case he had no choice?? 

    I hope he can shed some light on this...

    Wednesday, March 4, 2015 5:28 PM
  • Ah ok - I did check with the Sophos who said it was perfectly fine and gave me the instructions on what to do.

    Key thing here is that prior to taking and image all the services were disabled. So when I deploy an image they are still disabled so from my perspective shouldn't cause any issues. The script I am trying to run is to enable the services once the image has been deployed.

    I've been toying with it a bit more and as Prince Ali Ababwa suggested tried running it as an application. Now I get another massage: "LiteTouch is trying to install applications. This cannot be performed in Windows PE.
    If booting from a USB Flash Disk, please remove all drives before restarting."

    Progress? Who knows but I'll keep plodding on at this.

    Thursday, March 5, 2015 7:49 AM
  • Where are you placing this install? It cannot be during the WinPE stage. It should be during your application install after Windows 8 has been laid down... Does this make sense? You can do it right before your TS completes.....
    Thursday, March 5, 2015 5:52 PM
  • I've got it right at the end after everything is completed - I think, but I won't know until tomorrow that it's going to work. I'll let you know - and many thanks, much appreciated.

    Well that didn't work - got to say the more I get into MDT, the less I seemingly understand.......entries in the Custom Settings ini are completely ignored, like work group settings, the name I enter for each machine during the initial stages gets ignored and all machines =named the same, lastly I can not get any of the scripts to run as a 'run command' or as an application.

    I going to take a step back, review and start again.

    • Edited by seanhaynes Friday, March 6, 2015 1:24 PM
    Thursday, March 5, 2015 6:05 PM
  • Can you post a screenshot of your task sequence in the deployment workbench or something? What you are trying to accomplish really should work.

    Is your script being run in the State Restore section of the task sequence?

    Tuesday, March 17, 2015 12:19 AM