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

shanew919

New member
Member
Local time
2:15 PM
Messages
13
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 My Computer

Computer type
PC/Desktop
OS
win7 pro x64, win7 ultimate x64 win8.1 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 Computer My Computer

Computer type
PC/Desktop
Computer Manufacturer/Model Number
Pauly Special
OS
Win7 Ultimate X64
CPU
Intel i5 3570K
Motherboard
Gigabyte Z77X-DS3H
Memory
8GB DDR3 1600
Graphics Card(s)
Onboard
Sound Card
Onboard
Screen Resolution
1280x1024
Hard Drives
Samsung 840 Evo SSD (OS)
1TB Spinner (Data)
PSU
800W Arctic
Case
Cooler Master
Cooling
3x120mm Fans
Keyboard
MS Wireless
Mouse
MS Wireless
Internet Speed
20M
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 My Computer

Computer type
PC/Desktop
OS
win7 pro x64, win7 ultimate x64 win8.1 x64,
I would have though you could do this with WSUS?
 

My Computer My Computer

Computer type
Laptop
Computer Manufacturer/Model Number
Asus K52F or Lenovo B51-80
OS
Win 7 x64 Home Premium (and x86 VirtualBox VM)/Win10
CPU
i3 370M/i7 6500U
Motherboard
Asus/Lenovo
Memory
8GB - finally :)/8GB
Graphics Card(s)
it's an i3, dude!/dual Intel&nVidia
Sound Card
onboard
Monitor(s) Displays
15.6" built-in
Screen Resolution
1366x768/1920x1080
Hard Drives
750GB Seagate internal
Sundry external drives attached to other computers on the local network
1TB SSD on the Lenovo
PSU
n/a
Internet Speed
as much as I can get - usually on a dongle/phone, so <1MB/s
Antivirus
MSE/Defender
Browser
IE11/12/Edge/Chrome/FF(if I must)
WSUS is for domain environments and it still doesn't do updates instantly... my environment is not a domain.
 

My Computer My Computer

Computer type
PC/Desktop
OS
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 Computer My Computer

Computer type
PC/Desktop
OS
win7 pro x64, win7 ultimate x64 win8.1 x64,
Back
Top