Windows 7 Forums

Welcome to Windows 7 Forums. Our forum is dedicated to helping you find support and solutions for any problems regarding your Windows 7 PC be it Dell, HP, Acer, Asus or a custom build. We also provide an extensive Windows 7 tutorial section that covers a wide range of tips and tricks.


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

26 Apr 2015   #1
shanew919

win7 pro x64, win7 ultimate x64 win8.1 x64,
 
 
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 System SpecsSystem Spec
.
26 Apr 2015   #2
Pauly

Win7 Ultimate X64
 
 

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 System SpecsSystem Spec
26 Apr 2015   #3
shanew919

win7 pro x64, win7 ultimate x64 win8.1 x64,
 
 

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 System SpecsSystem Spec
.

27 Apr 2015   #4
NoelDP

Microsoft Community Contributor Award Recipient

Win 7 x64 Home Premium (and x86 VirtualBox VM)/Win10
 
 

I would have though you could do this with WSUS?
My System SpecsSystem Spec
27 Apr 2015   #5
shanew919

win7 pro x64, win7 ultimate x64 win8.1 x64,
 
 

WSUS is for domain environments and it still doesn't do updates instantly... my environment is not a domain.
My System SpecsSystem Spec
07 May 2015   #6
shanew919

win7 pro x64, win7 ultimate x64 win8.1 x64,
 
 

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 System SpecsSystem Spec
Reply

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




Thread Tools Search this Thread
Search this Thread:

Advanced Search




Similar help and support threads
Thread Forum
W10 TP : Old Windows Update Batch/Script
Hi, I need you for obtain a batch for apply this custom : Retrouvez votre bon vieux Windows Update sous Windows 10 - Le comptoir du hardware Can you help me ? Thanks Have a good day !
Windows Updates & Activation
Automate windows update on new machine
Has anyone have a way to automate the window 7 updates on a new machine. Maybe a script that will run at boot time to run updates, install updates and reboot if necessary. And keep going until the system is up to date. I have a bunch of windows seven machines to build and don't want to babysit them...
Windows Updates & Activation
Internet not working, windows update, ping, DNS, etc. working fine
Hello, I've got a Dell laptop here that isn't functioning properly. I can't get this to work for the life of me! I am currently using this laptop with a different hard drive, it's the install on the SSD that doesn't work. I know that the quick fix would be to simply reload windows, but I don't...
Network & Sharing
Windows Update is not working/Update Readiness Tool won't install
Win 7 64 Windows Update not working (post migration), nor is Windows Update Readiness tool installing. I have renamed catroot and stopped services, nothing working. I just migrated HD to a hybrid solid state (Seagate Momentus). I had this problem both with Acronis 2009 and Acronis 2013, and...
Windows Updates & Activation
A script to automate moving files off C: prior to backup?
I back up my files and system image weekly. I move the recorded TV shows (broadcast TV, nothing illegal) before that from my hard drive onto an external drive. Another drive in the same cabinet does the backup. It saves time and I won't want those files after a disc failure anyway. It would be...
General Discussion
Standard Windows batch script not working
I am trying to run a simple shutdown script..easy no big deal shutdown -r -t 00 And I created a desktop shortcut and assigned a hot key to it to speed up the process. Problem is I try to launch the batch script and instead I get a command prompt window that goes to the script directory, types...
General Discussion


Our Sites

Site Links

About Us

Find 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 19:27.

Twitter Facebook Google+



Windows 7 Forums

Seven Forums Android App Seven Forums IOS App