Does anyone have a working script for windows update? to automate it?


  1. Posts : 13
    win7 pro x64, win7 ultimate x64 win8.1 x64,
       #1

    Does anyone have a working script for windows update? to automate it?


    Hello all,

    For platform: Windows 7 Professional x64

    I need a way to automate windows update with a .vbs script if possible. I'm not familiar with power shell so I prefer a .vbs script. I have searched and searched but have not been able to find a reliable .vbs script.

    I need it not to have any user interaction so No prompts to search, download, or install the updates. 100% automated and silent. just a simple double click and launch or it can be called from a batch file, I would like to see the status in a window of some sort like cmd or something of course so I know what phase its in and when its complete.

    if anyone has something like this please post it....this would speed up my production line greatly.
      My Computer


  2. Posts : 2,573
    Win7 Ultimate X64
       #2

    Wouldn't it be easier to leave auto updates turned on and the machine will update itself - or am I missing something ? what are you trying to achieve with your script that WU wont do on its own
      My Computer


  3. Posts : 13
    win7 pro x64, win7 ultimate x64 win8.1 x64,
    Thread Starter
       #3

    In my production environment we receive users old laptops we backup their data then image the laptop then we install software and do the updates....we have to deploy the laptops with it being fully up to date and this is where we have been running windows update manually until its completely up to date and I would like to incorporate a windows update script into our other script that automates the software installation phase. doing windows update manually consumes a lot of time.

    this is a large organization so we are receiving several laptops a day.
      My Computer


  4. Posts : 21,482
    Win 7 x64 Home Premium (and x86 VirtualBox VM)/Win10
       #4

    I would have though you could do this with WSUS?
      My Computer


  5. Posts : 13
    win7 pro x64, win7 ultimate x64 win8.1 x64,
    Thread Starter
       #5

    WSUS is for domain environments and it still doesn't do updates instantly... my environment is not a domain.
      My Computer


  6. Posts : 13
    win7 pro x64, win7 ultimate x64 win8.1 x64,
    Thread Starter
       #6

    Ok so I found this vbs script for updating windows its not exactly what I would like but its the best I've found thus far... the only problem im having now is getting it to run with the "cscript" from a usb drive i've tested it locally it works fine. but when I try running from usb it doesn't recognize "cscript" I can't get my main script to run locally so that's why im running from usb.... I need to incorporate the windows update.vbs into my main script which runs from usb.

    I have tried making a directory on the C: drive and coping my windows update script and a .bat file to the local drive the .bat file calls the cscript windowsupdate.vbs script from that directory but it still doesn't recognize "cscript"

    then in my main script once I've made the directory and copied the files I call the .bat file to call the windowsupdate script locally. but still fails....

    any suggestions?

    also if you know how to take the prompts out let me know....

    heres the windowsupdate.vbs script (must be run from cmd with cscript locally to work)

    Set updateSession = CreateObject("Microsoft.Update.Session")
    updateSession.ClientApplicationID = "MSDN Sample Script"
    Set updateSearcher = updateSession.CreateUpdateSearcher()
    WScript.Echo "Searching for updates..." & vbCRLF
    Set searchResult = _
    updateSearcher.Search("IsInstalled=0 and Type='Software' and IsHidden=0")
    WScript.Echo "List of applicable items on the machine:"
    For I = 0 To searchResult.Updates.Count-1
    Set update = searchResult.Updates.Item(I)
    WScript.Echo I + 1 & "> " & update.Title
    Next
    If searchResult.Updates.Count = 0 Then
    WScript.Echo "There are no applicable updates."
    WScript.Quit
    End If
    WScript.Echo vbCRLF & "Creating collection of updates to download:"
    Set updatesToDownload = CreateObject("Microsoft.Update.UpdateColl")
    For I = 0 to searchResult.Updates.Count-1
    Set update = searchResult.Updates.Item(I)
    addThisUpdate = false
    If update.InstallationBehavior.CanRequestUserInput = true Then
    WScript.Echo I + 1 & "> skipping: " & update.Title & _
    " because it requires user input"
    Else
    If update.EulaAccepted = false Then
    WScript.Echo I + 1 & "> note: " & update.Title & _
    " has a license agreement that must be accepted:"
    WScript.Echo update.EulaText
    WScript.Echo "Do you accept this license agreement? (Y/N)"
    strInput = WScript.StdIn.Readline
    WScript.Echo
    If (strInput = "Y" or strInput = "y") Then
    update.AcceptEula()
    addThisUpdate = true
    Else
    WScript.Echo I + 1 & "> skipping: " & update.Title & _
    " because the license agreement was declined"
    End If
    Else
    addThisUpdate = true
    End If
    End If
    If addThisUpdate = true Then
    WScript.Echo I + 1 & "> adding: " & update.Title
    updatesToDownload.Add(update)
    End If
    Next
    If updatesToDownload.Count = 0 Then
    WScript.Echo "All applicable updates were skipped."
    WScript.Quit
    End If

    WScript.Echo vbCRLF & "Downloading updates..."
    Set downloader = updateSession.CreateUpdateDownloader()
    downloader.Updates = updatesToDownload
    downloader.Download()
    Set updatesToInstall = CreateObject("Microsoft.Update.UpdateColl")
    rebootMayBeRequired = false
    WScript.Echo vbCRLF & "Successfully downloaded updates:"
    For I = 0 To searchResult.Updates.Count-1
    set update = searchResult.Updates.Item(I)
    If update.IsDownloaded = true Then
    WScript.Echo I + 1 & "> " & update.Title
    updatesToInstall.Add(update)
    If update.InstallationBehavior.RebootBehavior > 0 Then
    rebootMayBeRequired = true
    End If
    End If
    Next
    If updatesToInstall.Count = 0 Then
    WScript.Echo "No updates were successfully downloaded."
    WScript.Quit
    End If
    If rebootMayBeRequired = true Then
    WScript.Echo vbCRLF & "These updates may require a reboot."
    End If
    WScript.Echo vbCRLF & "Would you like to install updates now? (Y/N)"
    strInput = WScript.StdIn.Readline
    WScript.Echo
    If (strInput = "Y" or strInput = "y") Then
    WScript.Echo "Installing updates..."
    Set installer = updateSession.CreateUpdateInstaller()
    installer.Updates = updatesToInstall
    Set installationResult = installer.Install()

    'Output results of install
    WScript.Echo "Installation Result: " & _
    installationResult.ResultCode
    WScript.Echo "Reboot Required: " & _
    installationResult.RebootRequired & vbCRLF
    WScript.Echo "Listing of updates installed " & _
    "and individual installation results:"

    For I = 0 to updatesToInstall.Count - 1
    WScript.Echo I + 1 & "> " & _
    updatesToInstall.Item(i).Title & _
    ": " & installationResult.GetUpdateResult(i).ResultCode
    Next
    End If
      My Computer


 

  Related Discussions
Our Sites
Site Links
About Us
Windows 7 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 7" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd
All times are GMT -5. The time now is 18:42.
Find Us