This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Force Update via Script...

Some of our clients have a drive protection software installed so that all changes made are reverted on reboot. Naturally, this conflicts with Sophos updates. So here's how we want to approach this issue:

There is a mechanism that automatically deactivates the drive protection (once a week, for example) and executes a previously configured batch script. (Any user interaction is blocked during that time.) Upon termination of that script, disk protection is re-enabled and everything is going back to normal. So what we're looking for is something that can be called from cmd that forces an update and terminates only after the update has completed.

Now, we already did some experiments with ALUpdate (9.5 and 10.0). Under Windows XP simply calling ALUpdate does nothing while under Windows 7 there was - according to client side logs - a successful update. (In that test scneario however there was nothing to be updated, yet.) The only problem is, that ALUpdate at least seemed to terminate right away. (The update was very quick so it's really hard to tell...) That's a bad thing because there's no way to know when the updated is actually finished. So we're able to call an update (at least under Windows 7), but we don't know when it's done...

Under Windows XP I've also tried the Visual Basic Script to trigger an immediate update. This actually does call the update, but it also terminates right away.

I'm aware that this might be a very race scenario, but it'd be really nice to find a solution to cope with it...

Thomas

:26885


This thread was automatically locked due to age.
  • Hello Thomas, maybe the LastUpdateTime registry key http://www.sophos.com/en-us/support/knowledgebase/36262.aspx would help (and there's probably a way to check for success - maybe an obvious key in the vicinity). This is right off the top of my head though ... Christian
    :26887
  • HI,

    How about a bit of VBS that kicks off an update, then checks if the alupdate.exe process is running, if not, then it's done.  In this example it kicks off an update, then every 5 seconds checks if the process alupdate.exe is running.  As this runs for the entire update it should do the trick.

    'Call UpdateNow and Monitor For Progress
    
    'Global Objects
    Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
    
    If CheckIfAlupdateRunning() = true then
    	wscript.quit(1)
    End if
    
    CallUpdate()
    wscript.sleep (2000) ' to ensure it starts an update before checking.
    
    
    Do Until CheckIfAlupdateRunning() = false
        wscript.sleep (5000)
    loop
    
    Set objWMIService = nothing
    
    ' Functions-------------------------------------------------------------------
    Function CallUpdate()
      dim objALC : set objALC = CreateObject("ActiveLinkClient.ClientUpdate.1")
      objALC.UpdateNow 1,1
      set objALC = nothing
    End Function 
    
    Function CheckIfAlupdateRunning()
    
    	dim colProcesses : Set colProcesses = objWMIService.ExecQuery _
    		("SELECT * FROM Win32_Process WHERE Name = 'alupdate.exe'")
    
    	If colProcesses.Count = 0 Then
    		CheckIfAlupdateRunning = false
    	Else
    		CheckIfAlupdateRunning = true
    	End If
    
    End Function
    '-------------------------------------------------------------------------------

    Regards,

    Jak

    :26889
  • Calling my knowledge of Visual Basic "limited" would be an exaggeration, but this doesn't look like a loop to me:

    if CheckIfAlupdateRunning() then
    	wscript.sleep (5000) 'wait 5 seconds before checking again.
    	CheckIfAlupdateRunning()
    end if

     I suppose the following might work, though:

    Do Until CheckIfAlupdateRunning() = false
        wscript.sleep (5000)
    loop

     Something like that...

    Apart from that I understand the idea behind the script and from what I can tell it looks good to me. We'll give it a try and I'll post the results here. (Might take a while, though, because this is low priority at the moment... ;-))

    :26915
  • You're quite right, I'm not sure what I was thinking there!  I think it would also be worth adding a check at the start to see if it's already updating, and exit.  I've also added "on error resume next" to ensure if it does fail for any reason the user isn't shown anything.

    on error resume next
    'Call UpdateNow and Monitor For Progress 'Global Objects Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2") If CheckIfAlupdateRunning() = true then wscript.quit(1) End if CallUpdate() wscript.sleep (2000) ' to ensure it starts an update before checking. Do Until CheckIfAlupdateRunning() = false wscript.sleep (5000) loop Set objWMIService = nothing ' Functions------------------------------------------------------------------- Function CallUpdate() dim objALC : set objALC = CreateObject("ActiveLinkClient.ClientUpdate.1") objALC.UpdateNow 1,1 set objALC = nothing End Function Function CheckIfAlupdateRunning() dim colProcesses : Set colProcesses = objWMIService.ExecQuery _ ("SELECT * FROM Win32_Process WHERE Name = 'alupdate.exe'") If colProcesses.Count = 0 Then CheckIfAlupdateRunning = false Else CheckIfAlupdateRunning = true End If End Function '-------------------------------------------------------------------------------
    :26923
  • Great, that seems to work. One final problem, although I think the solution is rather easy:

    The Script may not terminate, but it's backgrounding upon execution so there is - once again - no way to tell whether it's actually finished. Is there on option or something like that that keeps it in the foreground?

    :26925
  • Urhm. I'm not quite sure how this is being intergrated.

    One example I can think of would be, if you have a batch file that needs to call this script, where you only want the batch file to terminate once the thing it called completes.  In that case you could do something like this:

    @echo off
    echo "Starting..."
    start /wait /MIN cscript CallAndCheckUpdate.vbs
    echo "Done"

    You'd only get the "Done", once CallAndCheckUpdate.vbs completes.  I can see that it wouldn't complete if alupdate.exe got stuck.  To handle this case, you could check the start time of the alupdate.exe process and if it's more than 1hr ago, assume the worst, kill it and return that it failed?  At least you'd get a return.

    Jak

    :26929