WSUS Support Forums: Force installation of WSUS or Windows Updates, email results - WSUS Support Forums

Jump to content

  • (8 Pages)
  • +
  • « First
  • 4
  • 5
  • 6
  • 7
  • 8
  • You cannot start a new topic
  • You cannot reply to this topic

Force installation of WSUS or Windows Updates, email results Version 2.5

#101 User is offline   Michael P. Fender 

  • Newbie
  • Pip
  • Group: Regular Members
  • Posts: 3
  • Joined: 31-Mar-08

Posted 18 Apr 2008, 11:04

I have recently moved to Rob's newest(?) version on the forced update script "2.7" and I must say that so far I am quite impressed. I have the script sitting in a shared folder on my wsus server along with the latest version on Windows Update Agent. I set up a scheduled task on each of my test machines to run the script at 2:00 a.m. every morning. So far, everything is going well! This version looks to see if WUA is up to date with the version listed in the script. If it isn't, It will install it from wherever you dasignate to install from. If WUA is up to date or newer than the version in the script the script moves on to the update phase. I have been test running the script in two labs over the last week and so far it works just fine. I will be using the script on a bigger scale as soon as i figure out a way to copy the 'task' I have set up to run the script on more than just one machine at a time.
0

#102 User is offline   Nerdcentric 

  • Newbie
  • Pip
  • Group: New Members
  • Posts: 2
  • Joined: 25-Feb-08

Posted 15 Aug 2008, 08:23

First, thanks for an excellent script. I am using it to manage our ~30 servers and it works great!

I also wanted to share some info on how I am using a tool I developed named Script Zombie (Freeware available at http://www.Nerdcentric.com) to remotely run the script and easily do updates without having to schedule an event on each server.

Script Zombie allows you to manage a hostlist and easily spawn scripted tasks to a single or multiple machines. With two simple scripts (one local and one remote) I was able to copy the .VBS file to the remote server and force it to execute now. Here's what I am using:

Local Script - Script executed by Script Zombie (ForceUpdate.cmd)
@echo off
Echo.
Echo Force Microsoft Patches
Echo -----------------------
:UpdateScript
echo.
echo Refreshing Update.Cmd and UpdateHF.vbs on %1
echo.
If NOT EXIST \\%1\c$\Scripts md \\%1\c$\Scripts
xcopy /y c:\Script Zombie\RemoteScripts\Update*.* \\%1\c$\Scripts
echo.
echo Starting Update.Cmd using PSExec
echo.
:Update
psexec \\%1 -u DOMAIN\USERNAME -p PASSWORD c:\scripts\update.cmd


The script above copies the UpdateHF.vbs and an Update.cmd file to the remote server. It then uses PSExec (http://technet.microsoft.com/en-us/sysinternals/bb897553.aspx) to run Update.cmd on the remote system. Here's a copy of Update.cmd:

Remote Script - Script executed by PSExec on Target Server (Update.cmd)
@echo off
echo.
echo Set Date Variables for Log
echo.
for /f "tokens=2,3,4 delims=/- " %%x in ("%date%") do set d=%%x%%y%%z
echo.
echo Archiving old WindowsUpdate.log on %computername%
echo.
xcopy /i %systemroot%\WindowsUpdate.* \\SOMEFILESERVER\UpdateLogs\%d%\%COMPUTERNAME%
echo.
echo Running WSUS Update Check
echo.
wuauclt /detectnow
echo.
echo Running UpdateHF.vbs on %computername%
echo.
c:\scripts\updatehf.vbs action:install mode:silent email:SOMEBODY@EMAIL.COM restart:1


Hope that helps someone. It actually makes updating kinda fun. You just select a group of servers, click go and wait for the emails to start rolling in. :P:

This post has been edited by Nerdcentric: 15 Aug 2008, 08:24

0

#103 User is offline   tiescarbo 

  • Newbie
  • Pip
  • Group: New Members
  • Posts: 1
  • Joined: 19-Dec-08

Posted 19 Dec 2008, 06:42

First of all I would like to thank you for all your good work!

At the moment I am using the 2.6 beta of your script. It works on some pc's. On others it gives an error message.

Script: C:\updateHF.vbs
Line: 747
Char: 3
Error: Object required: "installer"
Code: 800A01A8
Source: Microsoft VBScript runtime error

I hope someone knows an answer for this problem.
0

#104 User is offline   numishra 

  • Member
  • PipPip
  • Group: Regular Members
  • Posts: 8
  • Joined: 11-Apr-08

Posted 23 Dec 2008, 09:10

Hi Rob,

Great work done by you.

Thanks a lot!

I am using version 2.5 without any issue.

I have a question:If I don't want to check and install WU agent then what codes I need to remove from the script without affecting other things .


Thanks,
Umesh
0

#105 User is offline   numishra 

  • Member
  • PipPip
  • Group: Regular Members
  • Posts: 8
  • Joined: 11-Apr-08

Posted 23 Dec 2008, 09:39

Hi Rob,

Great work done by you.

Thanks a lot!

I am using version 2.5 without any issue.

I have a question:If I don't want to check and install WU agent then what codes I need to remove from the script without affecting other things .


Thanks,
Umesh
0

#106 User is offline   amacca 

  • Newbie
  • Pip
  • Group: New Members
  • Posts: 1
  • Joined: 05-Feb-09

Posted 05 Feb 2009, 17:12

Something I came accross from Microsoft.....

Firstly a big thanks to Rob for a great script which I was able to use successfully with some of our older OS's.

I came across a script trolling through a technet blog or some such and thought I would share it here. It doesn't have any facility to email a result but does work with ALL the systems we have so far including 2008 server, 2008 server core, vista SP1, 2003 Server and XP SP2.... It also asks wether you want to actually install any updates and tells you if a reboot is required without just doing it :-)

To the best of my knowledge it is OK to share but please feel free to correct me if I'm wrong.


------------------------------------------------------------------------------------------------------------------------- ------------------------------------------------------------


Set updateSession = CreateObject("Microsoft.Update.Session")
Set updateSearcher = updateSession.CreateupdateSearcher()

WScript.Echo "Searching for updates..." & vbCRLF

Set searchResult = _
updateSearcher.Search("IsInstalled=0 and Type='Software'")


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)
WScript.Echo I + 1 & "> adding: " & update.Title
updatesToDownload.Add(update)
Next

WScript.Echo vbCRLF & "Downloading updates..."

Set downloader = updateSession.CreateUpdateDownloader()
downloader.Updates = updatesToDownload
downloader.Download()

WScript.Echo vbCRLF & "List of downloaded updates:"

For I = 0 To searchResult.Updates.Count-1
Set update = searchResult.Updates.Item(I)
If update.IsDownloaded Then
WScript.Echo I + 1 & "> " & update.Title
End If
Next

Set updatesToInstall = CreateObject("Microsoft.Update.UpdateColl")

WScript.Echo vbCRLF & _
"Creating collection of downloaded updates to install:"

For I = 0 To searchResult.Updates.Count-1
set update = searchResult.Updates.Item(I)
If update.IsDownloaded = true Then
WScript.Echo I + 1 & "> adding: " & update.Title
updatesToInstall.Add(update)
End If
Next

WScript.Echo vbCRLF & "Would you like to install updates now? (Y/N)"
strInput = WScript.StdIn.Readline
WScript.Echo

If (strInput = "N" or strInput = "n") Then
WScript.Quit
ElseIf (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


------------------------------------------------------------------------------------------------------------------------- ------------------------------------------------------------


Hope it helps some others out there running 2008 core....
0

#107 User is offline   warden 

  • Member
  • PipPip
  • Group: Regular Members
  • Posts: 5
  • Joined: 06-Feb-09

Posted 11 Feb 2009, 06:06

hi,

great job!
actually works very good for me, apart from one thing: it has to be run from a logged in user, if I try to run it before logon, then I get:
the operation being requested was not performed because the user has not logged on to the network.
the specified service does not exist.

any idea how to solve that?
0

#108 User is offline   warden 

  • Member
  • PipPip
  • Group: Regular Members
  • Posts: 5
  • Joined: 06-Feb-09

Posted 11 Feb 2009, 09:39

ok, actually there is some problem with this, I'm using a silent version of your script:

Set updateSession = CreateObject("Microsoft.Update.Session")
Set updateSearcher = updateSession.CreateupdateSearcher()

Set searchResult = updateSearcher.Search("IsInstalled=0 and Type='Software'")

For I = 0 To searchResult.Updates.Count-1
Set update = searchResult.Updates.Item(I)
Next

If searchResult.Updates.Count = 0 Then
WScript.Quit
End If

Set updatesToDownload = CreateObject("Microsoft.Update.UpdateColl")

For I = 0 to searchResult.Updates.Count-1
Set update = searchResult.Updates.Item(I)
updatesToDownload.Add(update)
Next

Set downloader = updateSession.CreateUpdateDownloader()
downloader.Updates = updatesToDownload
downloader.Download()

For I = 0 To searchResult.Updates.Count-1
Set update = searchResult.Updates.Item(I)
Next

Set updatesToInstall = CreateObject("Microsoft.Update.UpdateColl")

For I = 0 To searchResult.Updates.Count-1
set update = searchResult.Updates.Item(I)
If update.IsDownloaded = true Then
updatesToInstall.Add(update)
End If
Next

Set installer = updateSession.CreateUpdateInstaller()
installer.Updates = updatesToInstall
installer.Install()


The problem is that sometimes it works, and sometimes it fails on the last line with the error:
Error: 0x80240016
Source: (null)

Any ideas?
0

#109 User is offline   warden 

  • Member
  • PipPip
  • Group: Regular Members
  • Posts: 5
  • Joined: 06-Feb-09

Posted 11 Feb 2009, 10:24

Ok, problem solved, maybe you will find it useful:

Set wshShell = WScript.CreateObject("WSCript.shell")
wshShell.run "net stop wuauserv",0,True
wshShell.run "net start wuauserv",0,True

Set updateSession = CreateObject("Microsoft.Update.Session")
Set updateSearcher = updateSession.CreateupdateSearcher()

Set searchResult = updateSearcher.Search("IsInstalled=0 and Type='Software'")

For I = 0 To searchResult.Updates.Count-1
Set update = searchResult.Updates.Item(I)
Next

If searchResult.Updates.Count = 0 Then
wshShell.run "shutdown -r -f -t 0"
End If

Set updatesToDownload = CreateObject("Microsoft.Update.UpdateColl")

For I = 0 to searchResult.Updates.Count-1
Set update = searchResult.Updates.Item(I)
updatesToDownload.Add(update)
Next

Set downloader = updateSession.CreateUpdateDownloader()
downloader.Updates = updatesToDownload
downloader.Download()

For I = 0 To searchResult.Updates.Count-1
Set update = searchResult.Updates.Item(I)
Next

Set updatesToInstall = CreateObject("Microsoft.Update.UpdateColl")

For I = 0 To searchResult.Updates.Count-1
set update = searchResult.Updates.Item(I)
If update.IsDownloaded = true Then
updatesToInstall.Add(update)
End If
Next

Set installer = updateSession.CreateUpdateInstaller()
installer.Updates = updatesToInstall
installer.Install()

wshShell.run "shutdown -r -f -t 0"
0

#110 User is offline   superpatches 

  • Newbie
  • Pip
  • Group: Regular Members
  • Posts: 3
  • Joined: 11-Feb-09

Posted 15 Feb 2009, 07:46

Here's an error I am receiving on some machines running 2.6 beta:

Line 686 Char 3
Object required: 'installer'
code 800a01a8

on other machines I am receiving the:

741, 1 runtime error : Object required: 'l'

Any ideas?
0

#111 User is offline   warden 

  • Member
  • PipPip
  • Group: Regular Members
  • Posts: 5
  • Joined: 06-Feb-09

Posted 16 Feb 2009, 02:12

View Postsuperpatches, on Mon 16th Feb 2009, 01:46 am, said:

Here's an error I am receiving on some machines running 2.6 beta:

Line 686 Char 3
Object required: 'installer'
code 800a01a8

on other machines I am receiving the:

741, 1 runtime error : Object required: 'l'

Any ideas?


yes, installer is defined too late in the script.
find the first occurence and move it few lines up before the statements that set things on it.
0

#112 User is offline   jeppjepp 

  • Newbie
  • Pip
  • Group: Validating
  • Posts: 1
  • Joined: 02-Mar-09

Posted 02 Mar 2009, 06:20

anyone who can post the newest complete version?
0

#113 User is offline   easyermoney 

  • Newbie
  • Pip
  • Group: New Members
  • Posts: 1
  • Joined: 12-Mar-09

Posted 12 Mar 2009, 17:50

Thanks a lot Rob for the script. We have computers in our domain that have not been updated in over 16 months. ( I just started here two months ago so don't blame me...)

I banged my head against the wall for the last 4 days trying to get this to work using psexec to a remote computer. Finally I have it working. I'm including the psexec command line and the updated script. This was the 2.6_beta script which I downloaded 4 or 5 days ago.

The change I was forced to make to the script was exactly what Warden posted above. The "installer" was defined too late in the script. I moved the definition line up to before the command to call the installation. Without this change the script would force the computer to detect updates and download them but not install them.

psexec.exe \\[PCNAME] -u [DOMAIN]\[ADMIN] -p [PASSWORD] -i wscript //B \\[PATH TO UPDATEHT.VBS]\updatehf.vbs mode:silent restart:1 force:1

So far the only way I can get the remote computer to restart is with the "restart:1 force:1" flags. I have tested this with computers that use an internal WSUS server as well as computers that use Microsoft Updates and they both work.

Be sure you download the latest version of the WSUS client listed below. I used v.7.2.6001.788. You'll also need to download psexec with the pstools pack from http://technet.micro...s/bb896649.aspx.

Good luck.

GP

strScriptVer = "2.6 beta - Rob Dunn (uphold2001@hotmail.com)"
'~~[author]~~
'Rob Dunn
'with some additional improvements made by the WSUS and VBSHF community
' - thank you!
'~~[/author]~~
'
'~~[emailAddress]~~
'uphold 2001 (at) hot mail (dot)com
'~~[/emailAddress]~~
'
'~~[website]~~
'For future versions and support:
'http://www.vbshf.com
'~~[/website]~~
'
'~~[scriptType]~~
'vbscript
'~~[/scriptType]~~

'~~[subType]~~
'SystemAdministration
'~~[/subType]~~

'~~[keywords]~~
'wsus, windows, updates, hotfixes, email, windowsupdate, microsoft, wua, sus,
'~~[/keywords]~~
'
'~~[usage]~~
'Install updates silently, email you a logfile, then restart the computer ->
'updatehf.vbs action:install mode:silent email:you@yourdomain.com restart:1
'
'Detect missing updates, email you a logfile, then do nothing (no restart) ->
'updatehf.vbs action:detect mode:verbose email:you@yourdomain.com restart:0
'
'Prompt user to let them decide whether or not to install updates, email
' you a logfile, prompt user for restart ->
'updatehf.vbs action:prompt mode:verbose email:you@yourdomain.com restart:1
'
'Install updates silently, email you a logfile, then shutdown the computer
' if a reboot is pending->
'updatehf.vbs action:install mode:silent email:you@yourdomain.com restart:2
'
'Install updates silently, email you a logfile, then shutdown the computer
' no matter if a reboot is pending or not->
'updatehf.vbs action:install mode:silent email:you@yourdomain.com restart:2 force:1
'
'Detect missing updates or pending reboot silently, email you a logfile, then
' restart if there is a pending reboot ->
'updatehf.vbs action:detect mode:silent email:you@yourdomain.com restart:1
'
'Detect missing updates or pending reboot silently, email you a logfile, then
' restart no matter if there is a pending reboot ->
'updatehf.vbs action:detect mode:silent email:you@yourdomain.com restart:1 force:1
'
'~~[/usage]~~
'This script (the core was pulled from Microsoft's website, and the
' WindowsUpdate agent install was borrowed from Torgeir Bakken - thank
' you!) will tell the WU agent to 'detectnow', download and install
' missing windows updates as compared to it's update server. Works for
' WSUS and regular Windows Update site.
'
'This will now reboot the computer if specified after the udpates have
' been applied (or if there is a reboot pending from a previous update session).
'
'NOTE: If there are a LOT of downloads to pull, the status window (or log)
' will say "Downloading" for that entire time. I'm not sure how to get
' a download progress of each update...maybe someone can help me with that.
'
'Note on command-line switches: If you don't specify a switch (for
' example, 'email:') the corresponding variable defined in the script will
' provide the needed information (command-line switches take precedence).
'
'Why I put this script together:
'Our desktop deployment technicians needed a script that would pull
' updates immediately and install.
'
'We have some computers that are sometimes logged on or not (but
' they run services that must be running almost constantly), and are never rebooted.
'
'The user ignores the 'you have new updates available' message, so updates are
' never installed. This script will let you install the updates, and then it
' tells the WUA to present the 'restart' message - which more users are apt to
' respond to.
'
'If the client running the script doesn't have the specified version of the WUA ' installed, Torgeir's portion of the script will automatically install it (
' please contact me if this doesn't work - I modified his script slightly to
' plug into mine!).
'
'After the script runs, it will email a recipient the resulting logfile that is
' produced. Very handy for running with my Front-end to PSEXEC tool.
'
'****************************************************************************
***
'You need to edit the following variables:
'sExePath - this is the location of the WindowsUpdateAgent20-x86.exe.
'Download links:
'Version 2.0 - http://go.microsoft....k/?LinkId=43264
'Version 3.0 - http://download.wind...Agent30-x86.exe
'
'strMailFrom - arbitrary reply-to address
'strMailto - email address you want the report to mail to (this is for manual
' mode
' - or if the command-line switch isn't specified).
'strSMTPServer - the IP address of the email server you are sending the reports
' through.
'
'****************************************************************************
***
'Optional variables:
'Silent - 0 = verbose, 1 = silent (no windows or visible information)
'Intdebug - 0 = off, 1 = 1 (see some variables that are being passed)
'strAction - prompt|install|detect. Prompt gives users opportunity to install
' updates or not, install just installs them, detect updates the WU collection
' and downloads the updates (but does not install them) - useful if you want to
' have the computer refresh its stats to the stat server but not install the
' updates.
'blnEmail - 0 = off|1 = on. If set to 0, the script will not email a log file.
' If you specify an email address in the command-line, this will force the
' script to switch blnEmail to '1'.
'strRestart - 0 = Do nothing|1 = restart|2 = shutdown. Command-switch 'restart:'
' supercedes this variable.
'
'****************************************************************************
***
'Command line switches:
'action: prompt|install|detect
'mode: silent|verbose
'email: you@yourdomain.com
'restart: 0 (do nothing)| 1 (restart) | 2 (shutdown)
'force: 0 (do not enforce restart action - this is optional, by default it is
' set to 0) | 1 (enforce restart action).
'SMTPServer: x.x.x.x or hostname; overrides strSMTPServer above.
'emailsubject: "this is a subject" Overrides default subject. Server name is appended to this text. Use quotes if spaces exist.
'emailifallok: 0|1, where 0 = dont send email if server up to date and no
' reboot pending, and 1 = always send email
'fulldnsname: 0|1, where 0 = use server name only in subject, and 1 = use full
' dns name in email subject
'authtype: cdoAnonymous|cdoNTLM|cdoBasic - authentication type for SMTP (default
' is 'cdoAnonymous', no creds needed)
'authID: SMTP authentication ID
'authPassword: SMTP authentication password
'Finally, rename the file with .vbs
'****************************************************************************
***

Const HKEY_CURRENT_USER = &H80000001
Const HKEY_LOCAL_MACHINE = &H80000002
Const ForAppending = 8
Const ForWriting = 2
Const ForReading = 1
Const cdoAnonymous = 0 'Do not authenticate
Const cdoBasic = 1 'basic (clear-text) authentication
Const cdoNTLM = 2 'NTLM
Const cdoSendUsingMethod = "http://schemas.microsoft.com/cdo/configuration/sendusing", _
cdoSendUsingPort = 2, _
cdoSMTPServer = "http://schemas.microsoft.com/cdo/configuration/smtpserver", _
cdoSMTPServerport = "http://schemas.microsoft.com/cdo/configuration/smtpserverport", _
cdoSMTPconnectiontimeout = "http://schemas.microsoft.com/cdo/configuration/Connectiontimeout"

On Error Resume Next

'below variables for progress indicators
Dim objShell, objProcessEnv, objSystemEnv, objNet, objFso, objSwitches
Dim query, item, acounter, blnExtendedWMI, blnProcessEvents
Dim dlgBarWidth, dlgBarHeight, dlgBarTop, dlgBarLeft, dlgProgBarWidth, dlgProgBarHeight
Dim dlgProgBarTop, dlgProgBarLeft
Dim dlgBar, dlgProgBar, wdBar, objPBar, objBar, blnSearchWildcard
Dim blnProgressMode, blnDebugMode, dbgTitle
Dim dbgToolBar, dbgStatusBar, dbgResizable
Dim IE, objDIV, objDBG, strMyDocPath, strSubFolder, strTempFile, f1, ts, File2Load, objFlash
Dim dbgWidth, dbgHeight, dbgLeft, dbgTop, dbgVisible
'above variables for progress indicators
Dim blnRebootRequired

Dim strAction, regWSUSServer, ws, l, wshshell, wshsysenv, strMessage, strFrom
Dim strRestart, silenttext, restarttext, blnCallRestart, blnInstall, blnPrompt, strStatus
Dim blnIgnoreError, blnCScript, strLocaleDelim

Set WshShell = WScript.CreateObject("WScript.Shell")
Set WshSysEnv = WshShell.Environment("PROCESS")
Set ws = wscript.CreateObject("Scripting.FileSystemObject")
Set objADInfo = CreateObject("ADSystemInfo")

'Try to pick up computername via AD'
strComputer1 = objADInfo.ComputerName

'As a backup, use the environment strings to pick up the computer
' name.
strComputer = wshShell.ExpandEnvironmentStrings("%Computername%")

strUser = WshSysEnv("username")
strDomain = WshSysEnv("userdomain")

'Get computer OU
strOU = "Computer OU: Not detected"

Set objComputer = GetObject("LDAP://" & strComputer1)
If objComputer.Parent <> "" Then
strOU = "Computer OU: " & replace(objComputer.Parent,"LDAP://","")
End If

If InStr(ucase(WScript.FullName),"CSCRIPT.EXE") Then
blnCScript = TRUE
Else
blnCScript = FALSE
End If

blnCloseIE = true

'****************************************************************************
***' User variables
'****************************************************************************
***
'Turn on debugging. This will show some of the variables that are being passed
' while the script executes.
Intdebug = 0

'How long between the time that the script is finished and the IE window stays
' on the screen. Set to '0' if you don't want the status window to close
' automatically.
intSleep = 60

'Whether or not the user will see the status window.
' Possible options are:
'0 = verbose, progress indicator, status window, etc.
'1 = silent, no progress indicators. Everything occurs in the background
Silent = 0

'The location of the logfile (this is the file that will be parsed
' and the contents will be sent via email.
logfile = WshSysEnv("TEMP") & "\" & "vbswsus-status.log"

'This won't attach and mail yet - WUA holds on to the file, so I can't email it.
' ...yet.
' Maybe for future versions...
'WSUSLog = wshShell.ExpandEnvironmentStrings("%windir%") & "\" & "WindowsUpdate.log"

'Full EXE path to Windows Update Agent installation exe. It will install it
' slently if the PC needs it
sExePath = Chr(34) & "\\server\path\WindowsUpdateAgent30-x86.exe" & Chr(34)

'arbitrary email address - reply-to
strMailFrom = "wsus_script@domain.com"

'who are you mailing to? Input mode only. Command-line parameters take
' precedence
strMailto = "user@domain.com"

'set SMTP email server address here
strSMTPServer = "x.x.x.x"

'set SMTP email server port (default is 25)
iSMTPServerPort = 25

'The computer name will follow this text when the script completes.
strSubject = "[WSUS Update Script] - WSUS Update log file from"

'Version number of the Windows Update agent you wish to compare installed
' version against. If the version installed is not equal to this version, then
' it will install the exe referred to in var 'sExePath' above.
strWUAgentVersion = "7.2.6001.788"
'version 2.0 SP1 is 5.8.0.2469
'version 3.0 is 7.0.6000.374

'Deliminator in above strWUAgentVersion - some locales might have "," instead
' (Non English) - leave as "." if you aren't sure.
strLocaleDelim = "."

'default option for manual run of the script. Possible options are:
' prompt - (user is prompted to install)
' install - updates will download and install
' detect - updates will download but not install
strAction = "install"

'Turns email function on/off. If an email address is specified in the
' command-line arguments, then this will automatically turn on ('1').
' 0 = off, don't email
' 1 = on, email using default address defined in the var 'strMailto' above.
blnEmail = 1

'strEmailIfAllOK Determines if email always sent or only if updates or reboot
' needed.
' 0 = off, don't send email if no updates needed and no reboot needed
' 1 = on always send email
strEmailIfAllOK = 1

'strFullDNSName Determines if the email subject contains the full dns name of
' the server or just the computer name.
' 0 = off, just use computer name
' 1 = on, use full dns name
strFullDNSName = 0

'tells the script to prompt the user (if running in verbose mode) to input the
' email address of the recipient they wish to send the script log file to. The
' default value in the field is determined by the strMailto variable above.
'
'This only appears if no command-line arguments are given.
'0 = do not prompt the user to type in an email address
'1 = prompt user to type in email address to send the log to.
promptemail = 0

'Tells the computer what to do after script execution if the script detects that
' there is a pending reboot.
'
'Command-prompt supercedes this option.
'0 = do nothing
'1 = reboot
'2 = shutdown
strRestart = 0

'Try to force the script to work through any errors. Since some are recoverable
' this might be an option for troubleshooting. Default is 'true'
blnIgnoreError = true

'sets font for display status dialog and sent formatted logfile
strFontStyle = "arial"

'set your SMTP server authentication type.
' Possible values:cdoAnonymous|cdoBasic|cdoNTLM
' You do not need to configure an id/pass combo with cdoAnonymous
strAuthType = "cdoAnonymous"

'SMTP authentication ID
strAuthID = ""

'Password for the ID
strAuthPassword = ""

'
'****************************************************************************
***
'End of User variables
'****************************************************************************
***
Set objArgs = WScript.Arguments

'writelog("Arguments: " & wscript.arguments)
writelog("Log file used: " & logfile)
If intdebug = 1 then wscript.echo "Objargs.count = " & objArgs.count

If objArgs.Count > 0 Then
For I = 0 to objArgs.Count - 1
If objArgs.Count > 0 Then
if instr(LCase(objargs(i)),"action:") Then
strArrAction = split(objargs(0),":")
strAction = strArrAction(1)
if intdebug = 1 then wscript.echo strAction
ElseIf instr(LCase(objargs(i)),"mode:") Then
strArrMode = split(objargs(i),":")
silent = strArrMode(1)
If lcase(silent) = "silent" then
silent = 1
Elseif lcase(silent) = "verbose" then
silent = 0
blnCloseIE = true
Else
strMsg = "Invalid mode switch: " & silent & ". Now aborting."
'Call ErrorHandler("Command Switches",strMsg,"true")
End If
Silenttext = strArrMode(1)
ElseIf instr(LCase(objargs(i)),"email:") Then
strArrEmail = split(objargs(i),":")
strMailto = strArrEmail(1)
blnEmail = 1
ElseIf instr(LCase(objargs(i)),"logfile:") Then
strArrLogfile = split(objargs(i),"logfile:")
LogFile = strArrLogFile(1)
ElseIf InStr(LCase(objargs(i)),"restart:") Then
strArrAction = split(objargs(i),":")
strRestart = strArrAction(1)
ElseIf InStr(LCase(objargs(i)),"force:") Then
strArrForceAction = split(objargs(i),":")
strForceaction = strArrForceAction(1)
ElseIf InStr(LCase(objargs(i)),"smtpserver:") Then
strArrSMTPServer = split(objargs(i),":")
strSMTPServer = strArrSMTPServer(1)
ElseIf InStr(LCase(objargs(i)),"emailifallok:") Then
strArrEmailIfAllOK = split(objargs(i),":")
strEmailIfAllOK = strArrEmailIfAllOK(1)
ElseIf InStr(LCase(objargs(i)),"fulldnsname:") Then
strArrFullDNSName = split(objargs(i),":")
strFullDNSName = strArrFullDNSName(1)
ElseIf InStr(LCase(objargs(i)),"emailsubject:") Then
strArrSubject = split(objargs(i),":")
strSubject = strArrSubject(1)
ElseIf InStr(LCase(objargs(i)),"authtype:") Then
strArrAuthType = split(objargs(i),":")
strAuthType = strArrAuthType(1)
ElseIf InStr(LCase(objargs(i)),"authid:") Then
strArrAuthID = split(objargs(i),":")
strAuthID = strArrAuthID(1)
ElseIf InStr(LCase(objargs(i)),"authpassword:") Then
strArrAuthPassword = split(objargs(i),":")
strAuthPassword = strArrAuthPassword(1)
End If
End If
Next
Else
'strAction = "prompt"
If blnEmail = 1 and silent = 0 and promptemail = 1 Then strMailto = InputBox("Input the email address you would like the " _
& "Windows Update agent log sent to:","Email WU Agent logfile to recipient",strMailto)
If strMailto = "" Then wscript.quit
End If

Set l = ws.OpenTextFile (logfile, ForWriting, True)
l.writeline "------------------------------------------------------------------"
l.writeline "WU force update VBScript" & vbcrlf & Now & vbcrlf & "Computer: " & strComputer
l.writeline "Script version: " & strScriptVer
l.writeline strOU
For I = 0 to objArgs.Count - 1
strArguments = strArguments & " " & objArgs(I)
Next
l.writeline "Executed by: " & strDomain & "\" & strUser
l.writeline "Command arguments: " & strArguments
l.writeline "------------------------------------------------------------------"

If blnEmail = 1 then
writelog("SMTP Authentication type specified: " & strAuthType)
If lcase(strAuthType) <> "cdoanonymous" Then
If strAuthType = "" Then
strAuthType = "cdoanonymous"
Else
writelog("SMTP Auth User ID: " & sAuthID)

If SMTPUserID = "" then
writelog("No SMTP user ID was specified, even though SMTP Authentication was configured for " & strAuthType & ". Attempting to switch to anonymous authentication...")
strAuthType = "cdoanonymous"
If strAuthPassword <> "" then writelog("You have specified a SMTP password, but no user ID has been configured for authentication. Check the INI file (" & sINI & ") again and re-run the script.")
Else
if strAuthPassword = "" then writelog("You have specified a SMTP user ID, but have not specified a password. Switching to anonymous authentication.")
strAuthType = "cdoanonymous"
End if
If strAuthPassword <> "" then writelog("SMTP password configured, but hidden...")

End If
End If
End If

Call checkupdateagent

Select Case silent
Case 0
silenttext = "Verbose"
Case 1
silenttext = "Silent"
Case Else
End Select

If strForceaction = 1 Then
strForceText = " (enforce action)"
Else
strForceText = " (only if action is pending)"
End If

Select Case strRestart
Case 0
restarttext = "Do nothing"
Case 1
restarttext = "Restart"
Case 2
restarttext = "Shut down"
Case Else
End Select

restarttext = restarttext & strForceText

writelog("Script action is set to: " & strAction)
writelog("Verbose/Silent mode is set to: " & silenttext)
writelog("Restart action is set to: " & restarttext)

Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &_
strComputer & "\root\default:StdRegProv")
strKeyPath = "SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate"
strValueName = "WUServer"
oReg.GetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,regWSUSServer
writelog("Checking local WU settings...")

Call GetAUSchedule()

If regWSUSServer then
Else
regWSUSServer = "Microsoft Windows Update"
End If

writelog("Update Server: " & regWSUSServer)

strValueName = "TargetGroup"

oReg.GetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,regTargetGroup
if regTargetGroup <> "" then
writelog("Target Group: " & regTargetGroup)
Else
writelog("Target Group: Not specified")
End If

Set autoUpdateClient = CreateObject("Microsoft.Update.AutoUpdate")
Set updateInfo = autoUpdateClient.Settings

Select Case updateInfo.notificationlevel
Case 0
writelog("WUA mode: WU agent is not configured.")
Case 1
writelog("WUA mode: WU agent is disabled.")
Case 2
writelog("WUA mode: Users are prompted to approve updates prior to installing")
Case 3
writelog("WUA mode Updates are downloaded automatically, and users are prompted to install.")
Case 4
writelog("WUA mode: Updates are downloaded and installed automatically at a pre-determined time.")
Case Else
End Select


fstyle = "tahoma,arial,verdana"
bgcolor1 = "aliceblue"
fformat = "<font face='" & fstyle & "'>"

'set some IE status indicator variables...
blnDebugMode = True
blnProcessEvents = True
blnSearchWildcard = False
blnProgressMode = True

On Error Resume Next

Set updateSession = CreateObject("Microsoft.Update.Session")
Set updateSearcher = updateSession.CreateupdateSearcher()

writelog("Instantiating Searcher")
Set searchResult = updateSearcher.Search("IsAssigned=1 and IsHidden=0 and IsInstalled=0 and Type='Software'")

'Handle some common errors here
If cstr(err.number) <> 0 Then
If cstr(err.number) = "-2147012744" Then
strMsg = "ERROR_HTTP_INVALID_SERVER_RESPONSE - The server response could not be parsed." & vbcrlf & vbcrlf & "Actual error was: " _
& " - Error [" & cstr(err.number) & "] - '" & err.description & "'"
blnFatal = true
ElseIf CStr(err.number) = "-2145107924" Then
strMsg = "WU_E_PT_WINHTTP_NAME_NOT_RESOLVED - Winhttp SendRequest/ReceiveResponse failed with 0x2ee7 error. Either the proxy " _
& "server or target server name can not be resolved. Corresponding to ERROR_WINHTTP_NAME_NOT_RESOLVED. " _
& "Stop/Restart service or reboot the machine if you see this error frequently. " _
& vbcrlf & vbcrlf & "Actual error was [" & err.number & "] - " & chr(34) _
& err.description & chr(34)
blnFatal = false
ElseIf cstr(err.number) <> 0 and cstr(err.number) = "-2147012867" Then
strMsg = "ERROR_INTERNET_CANNOT_CONNECT - The attempt to connect to the server failed." & vbcrlf _
& vbcrlf & "Actual error was [" & err.number & "] - " & chr(34) _
& err.description & chr(34)
blnFatal = true
ElseIf CStr(err.number) = "-2145107941" Then
strMsg = "SUS_E_PT_HTTP_STATUS_PROXY_AUTH_REQ - Http status 407 - proxy authentication required" & vbcrlf & vbcrlf & "Actual " _
& "error was [" & err.number & "]" & chr(34) & err.description & chr(34)
ElseIf CStr(err.number) = "-2145124309" Then
strMsg = "WU_E_LEGACYSERVER - The Sus server we are talking to is a Legacy Sus Server (Sus Server 1.0)" _
& vbcrlf & vbcrlf & "Actual error was [" & err.number & "] - " & chr(34) & err.description & chr(34)
blnFatal = true
ElseIf CStr(err.number) = "7" Then
strMsg = "Out of memory - In most cases, this error will be resolved by rebooting the client." _
& VbCrLf & VbCrLf & "Actual error was [" & err.number & "] - " & chr(34) & err.description & chr(34)
blnFatal = True
Else
If err.description = "" Then
errdescription = "No error description given"
Else
errdescription = err.description
End If
If blnIgnoreError = false Then
blnFatal = true
strScriptAbort = vbcrlf & vbcrlf & "Script will now abort. - if you want to force the script to continue, change the 'blnIgnoreError' variable " _
& "to the value 'true'"
Else
strScriptabort = vbcrlf & vbcrlf & "Script will attempt to continue."
End If
strAddr = "http://www.vbshf.com/vbshf/wsus/sus_error_code.htm "
strMsg = "Error - [" & err.number & "] - " & chr(34) & errdescription & chr(34) & "." & vbcrlf & vbcrlf _
& "This error is undefined in the script, but you can refer to " & strAddr & "to look up the error number." _
& strScriptAbort
strMsgHTML = replace(strMsg,strAddr,"<a href='" & strAddr & "'>" & strAddr & "</a>")
If silent = 0 Then objdiv.innerhtml = replace(strMsgHTML,"vbcrlf","<br>")
End If

Call ErrorHandler("UpdateSearcher",strMsg,blnFatal)
End If
'ssManagedServer

If silent = 0 then
writelog("Calling IE Status Window")
on error goto 0
Call IEStatus
End If

Call CheckPendingStatus("beginning")

strMsg = "Refreshing WUA client information..."
if silent = 0 then objdiv.innerhtml = strMsg

'cause WU agent to detect
on error resume next
autoUpdateClient.detectnow()
if err.number <> 0 then call ErrorHandler("WUA refresh",err.number & " - " & err.description,false)
err.clear
on error goto 0

strMsg = "WUA mode: <font color='navy'>" & strACtion & "</font><br>WU Server: " & regWSUSServer _
& "<br>Target Group: " & regTargetGroup & "<br><br>List of applicable items on the machine: <br>"
writelog("WUA mode: " & straction)
writelog("WU Server: " & regWSUSServer)
If silent = 0 then objdiv.innerhtml = strMsg
writelog("Searching for missing or updates not yet applied...")

on error resume next
'Old code - replaced by below...thanks to WSUS user 'roos'
'For I = 0 To searchResult.Updates.Count-1
' Set update = searchResult.Updates.Item(I)
' strSearchResultUpdates = strSearchResultUpdates & update.Title & "<br>"
' writelog("Missing: " & searchResult.Updates.Item(i) & ", Category ID: " & objCategories.Item(i).CategoryID)
'Next

For i = 0 To searchResult.Updates.Count-1
Set update = searchResult.Updates.Item(i)
strSearchResultUpdates = strSearchResultUpdates & update.Title & "<br>"
Set objCategories = searchResult.Updates.Item(i).Categories
writelog("Missing: " & searchResult.Updates.Item(i) & ", Category ID: " & objCategories.Item(i).CategoryID)
Next

if err.number <> 0 then
writelog("An error has occured while instantiating search results. Error " & err.number & " - " & err.description _
& ". Check the " & wshShell.ExpandEnvironmentStrings("%windir%") & "\windowsupdate.log file for further information.")

blnFatal = false
End IF

if silent = 0 then objdiv.innerhtml = strMsg & strsearchResultUpdates

If searchResult.Updates.Count = 0 Then

strMsg = fformat & "There are no further updates needed for your PC at this time."
if silent = 0 then objdiv.innerhtml = strMsg

writelog(replace(strMsg,fformat,""))

Call EndOfScript
wscript.quit
End If

If intdebug = 1 then WScript.Echo vbCRLF & "Creating collection of updates to download:"
If strAction <> "detect" Then writelog("Creating a catalog of needed updates")

writelog("********** Cataloging updates **********")

Set updatesToDownload = CreateObject("Microsoft.Update.UpdateColl")

For I = 0 to searchResult.Updates.Count-1
Set update = searchResult.Updates.Item(I)
strUpdates = strUpdates & update.Title & "<br>"
writelog("Cataloged: " & update.Title)
If Not update.EulaAccepted Then update.AcceptEula
updatesToDownload.Add(update)
Next

if silent = 0 then objdiv.innerhtml = ""
strMsg = fformat & "This PC requires updates from the configured Update Server" _
& " (" & regWSUSServer & "). "
If strAction <> "detect" Then strmsg = strmsg & "<br><br> Downloading needed updates. Please stand by..."

if silent = 0 then objdiv.innerhtml = strMsg
writelog(replace(replace(strMsg,fformat,""),"<br>",""))

If strAction = "detect" Then

Else

Set downloader = updateSession.CreateUpdateDownloader()
on error resume next
downloader.Updates = updatesToDownload
writelog("********** Downloading updates **********")

downloader.Download()

if err.number <> 0 then
writelog("Error " & err.number & " has occured. Error description: " & err.description)
End if

strUpdates = ""
strMsg = ""
if silent = 0 then objdiv.innerhtml = ""
strMsg = fformat & "List of downloaded updates: <br><br>"
if silent = 0 then objdiv.innerhtml = strMsg

For I = 0 To searchResult.Updates.Count-1
Set update = searchResult.Updates.Item(I)
If update.IsDownloaded Then
strDownloadedUpdates = strDownloadedUpdates & update.Title & "<br>"
End If
On Error GoTo 0
'writelog(searchResult.Updates.Item(i))
writelog("Downloaded: " & update.Title)
if silent = 0 then objdiv.innerhtml = strMsg & strDownloadedUpdates
Next
Set updatesToInstall = CreateObject("Microsoft.Update.UpdateColl")

strUpdates = ""
strMsg = ""
if silent = 0 then objdiv.innerhtml = ""
strMsg = fformat & "Creating collection of updates needed to install:<br><br>"
if silent = 0 then objdiv.innerhtml = strMsg
writelog("********** Adding updates to collection **********")

For I = 0 To searchResult.Updates.Count-1
set update = searchResult.Updates.Item(I)
If update.IsDownloaded = true Then
strUpdates = strUpdates & update.Title & "<br>"
updatesToInstall.Add(update)
End If
writelog("Adding to collection: " & update.Title)
if silent = 0 then objdiv.innerhtml = strMsg & strUpdates
Next
End If


If lcase(strAction) = "prompt" Then
strMsg = "The Windows Update Agent has detected that this computer is missing updates from the " _
& " configured server (" & regWSUSServer & ")." & vbcrlf & vbcrlf & "Would you like to install updates now?"
strResult = MsgBox(strMsg,36,"Install now?")
strUpdates = ""
writelog(strMsg & " [Response: " & strResult & "]")
strMsg = ""
If silent = 0 then objdiv.innerhtml = ""

ElseIf strAction = "detect" Then
strMsg = fformat & "Windows Update Agent has finished detecting needed updates."
writelog(replace(strMsg,fformat,""))

if silent = 0 then objdiv.innerhtml = strMsg & "<br><br>"

Call EndOfScript
wscript.quit
ElseIf strAction = "install" Then
strResult = 6
End If

strUpdates = ""
if silent = 0 then objdiv.innerhtml = ""

If strResult = 7 Then
strMsg = strMsg & "<br>User cancelled installation. This window can be closed."
writelog(replace(strMsg,"<br>",""))

if silent = 0 then objdiv.innerhtml = strMsg

WScript.Quit
ElseIf strResult = 6 Then
strMsg = ""
Set installer = updateSession.CreateUpdateInstaller()
installer.AllowSourcePrompts = False
installer.ForceQuiet = True

strMsg = fformat & "Installing updates... <br><br>"
writelog(replace(replace(strMsg,fformat,""),"<br>",""))
if silent = 0 then objdiv.innerhtml = strMsg


if err.number <> 0 then
writelog("Error " & err.number & " has occured. Error description: " & err.description)

end if

installer.Updates = updatesToInstall
writelog("********** Installing updates **********")
blnInstall = true

on error resume next
Set installationResult = installer.Install()

If err.number <> 0 then
'strMsg = "Error installing updates... Actual error was " & err.number & " - " & err.description & "."
'writelog(strmsg)
if silent = 0 then objdiv.innerhtml = strMsg


End If
'Output results of install
strMsg = fformat & "Installation Result: " & installationResult.ResultCode & "<br><br>" _
& "Reboot Required: " & installationResult.RebootRequired & "<br><br>" _
& "Listing of updates installed and individual installation results: <br>"
For i = 0 to updatesToInstall.Count - 1
If installationResult.GetUpdateResult(i).ResultCode = 2 Then
strResult = "Installed"
ElseIf installationResult.GetUpdateResult(i).ResultCode = 1 Then
strResult = "In progress"
ElseIf installationResult.GetUpdateResult(i).ResultCode = 3 Then
strResult = "Operation complete, but with errors"
ElseIf installationResult.GetUpdateResult(i).ResultCode = 4 Then
strResult = "Operation failed"
ElseIf installationResult.GetUpdateResult(i).ResultCode = 5 Then
strResult = "Operation aborted"
End If
writelog(updatesToInstall.Item(i).Title & ": " & strResult)
strUpdates = strUpdates & updatesToInstall.Item(i).Title & ": " & strResult & "<br>"
Next
if silent = 0 then objdiv.innerhtml = strMsg & strUpdates
End If

Call EndOfScript
wscript.quit

'****************************************************************************
***'Function Writelog
'****************************************************************************
***
Function WriteLog(strMsg)
l.writeline "[" & time & "] - " & strMsg
' Output to screen if cscript.exe
If blnCScript Then WScript.Echo "[" & time & "] " & strMsg
End Function

'****************************************************************************
***'Function IE Status
'****************************************************************************
***
Function IEStatus

'added by Rob - IE status indicator code
If blnProgressMode Then
If blnDebugMode Then
dbgTitle = "Windows Update Script " & strScriptVer
Else
dbgTitle = "Windows Update Script " & strScriptVer
End If
dbgToolBar = False
dbgStatusBar = False
If blnDebugMode Then
dbgResizable = True
Else
dbgResizable = False
End If
dbgWidth = 500
dbgHeight = 320

on error resume next

'get video resolution via WMI
Set vids = GetObject("WinMgmts:").instancesof("Win32_VideoController")
for each v in vids
HorScreen = v.CurrentHorizontalResolution
VerScreen = v.CurrentVerticalResolution
next
If err.number <> 0 then
dbgLeft = 100
dbgTop = 200
err.clear
Else
HorScreen = 800
VerScreen = 600
dbgLeft = (HorScreen * .5) - (dbgWidth/2)
dbgTop = (VerScreen * .5) - (dbgHeight/2)
End if


dbgLeft = (HorScreen * .5) - (dbgWidth/2)
dbgTop = (VerScreen * .5) - (dbgHeight/2)
dbgVisible = True
dlgBarWidth = 380
dlgBarHeight = 23
dlgBarTop = 5
dlgBarLeft = 82
dlgProgBarWidth = 0
dlgProgBarHeight = 18
dlgProgBarTop = 82
dlgProgBarLeft = 50
dlgBar = "left: " & dlgBarLeft & "; top: " & dlgBarTop & "; width: " & dlgBarWidth _
& "; height: " & dlgBarHeight & ";"
dlgProgBar = "left: " & dlgProgBarLeft & "; top: " & dlgProgBarTop & "; width: " _
& dlgProgBarWidth & "; height: " & dlgProgBarHeight & ";"
wdBar = 1 * dlgBarWidth
End If

If blnProgressMode Then
' in case people has used the search bar in IE, turn it off
' Thank you Torgeir!
Set IEtmp = CreateObject("InternetExplorer.Application")
IEtmp.ShowBrowserBar "{30D02401-6A81-11D0-8274-00C04FD5AE38}", False
IEtmp.Quit

Set IEtmp = Nothing
WScript.Sleep 1000

Set IE = CreateObject("InternetExplorer.Application")
'strScriptVer = "version would go here"

strTempFile = WshSysEnv("TEMP") & "\progress.htm"
ws.CreateTextFile (strTempFile)
Set f1 = ws.GetFile(strTempFile)
Set ts = f1.OpenAsTextStream(2, True)
ts.WriteLine("<!-- saved from url=(0014)about:internet -->")
ts.WriteLine("<html><head><title>" & dbgTitle & " " & strScriptVer & " </title>")
ts.WriteLine("<style>.errortext {color:red}")
ts.WriteLine(".hightext {color:blue}</style>")
ts.WriteLine("</head>")
ts.WriteLine(strHDRCode & " <br><strong><font size='2' color='" & fcolor & "' face='" & fstyle & "'>" _
& "&nbsp Running Windows Update Client...<br>" _
& "&nbsp &nbsp<br>")
ts.WriteLine("<center><table width='100%' bgcolor='" & bgcolor1 & "'><tr><td>")
If blnDebugMode Then
ts.WriteLine("<body bgcolor ='" & stsBGColor & "' scroll='yes' topmargin='0' leftmargin='0'"_
& " style='font-family: " & fstyle & "; font-size: 0.6em color: #000000;"_
& " font-weight: bold; text-align: left'><center><font face=" & fstyle & ">"_
& " <font size='0.8em'> <hr color='blue'>")
Else
ts.WriteLine("<body bgcolor = '" & stsBGColor & "' scroll='no' topmargin='0' leftmargin='0' "_
& " style='font-family: " & fstyle & "; font-size: 0.6em color: #000000;"_
& " font-weight: bold; text-align: left'><center><font face=" & fstyle & ">"_
& " <font size='0.8em'> <hr color='blue'>")
End If
ts.WriteLine("<div id='ProgObject' align='left'align='left' style='width: 450px;height: 140px;overflow:scroll'></div><hr color='blue'>")
If blnDebugMode Then
ts.WriteLine("<div id='ProgDebug' align='left'></div>")
End If

ts.WriteLine("<script LANGUAGE='Javascript1.2'>")
ts.WriteLine("<!-- Begin")
ts.WriteLine("function initArray() {")
ts.WriteLine("this.length = initArray.arguments.length;")
ts.WriteLine("for (var i = 0; i < this.length; i++) {")
ts.WriteLine("this[i] = initArray.arguments[i];")
ts.WriteLine(" }")
ts.WriteLine("}")
ts.WriteLine("var ctext = ' ';")
ts.WriteLine("var speed = 1000;")
ts.WriteLine("var x = 0;")
ts.WriteLine("var color = new initArray(")
ts.WriteLine("'red',")
ts.WriteLine("'blue'")
ts.WriteLine(");")
ts.WriteLine("document.write('<div id=" & Chr(34) & "ProgFlash" & Chr(34) & ">"_
& "<center>'+ctext+'</center></div>');")
ts.WriteLine("function chcolor(){")
ts.WriteLine("document.all.ProgFlash.style.color = color[x];")
ts.WriteLine("(x < color.length-1) ? x++ : x = 0;")
ts.WriteLine("}")
ts.WriteLine("setInterval('chcolor()',1000);")
ts.WriteLine("// End -->")
ts.WriteLine("</script>")
ts.WriteLine("<div id='ProgBarId' align='left'></div>")
ts.WriteLine("</font></center>")
ts.WriteLine("</tr></td>")
ts.WriteLine("</table></center>")
ts.WriteLine("</body></html>")
ts.Close
fctSetupIE(strTempFile)
Set objDIV = IE.document.All("ProgObject")
If blnDebugMode Then
Set objDBG = IE.document.All("ProgDebug")
End If
Set objFlash = IE.document.All("ProgFlash")
Set objPBar = IE.document.All("ProgBarId")
Set objBar = IE.Document
End If
If silent = 1 Then
'remarked by Rob Set logwindow = ie.document.all.text1
End If
End Function
'****************************************************************************
***'* Name: fctSetupIE
'* Function: Setup an IE windows of 540 x 200 to display
'* progress information.
'****************************************************************************
***
Sub fctSetupIE(File2Load)
IE.Navigate File2Load
IE.ToolBar = dbgToolBar
IE.StatusBar = dbgStatusBar
IE.Resizable = dbgResizable
Do
Loop While IE.Busy
IE.Width = dbgWidth
IE.Height = dbgHeight
IE.Left = dbgLeft
IE.Top = dbgTop
IE.Visible = dbgVisible
wshshell.AppActivate("Microsoft Internet Explorer")
End Sub

Sub GetAUSchedule()
Set objAutoUpdate = CreateObject("Microsoft.Update.AutoUpdate")
Set objSettings = objAutoUpdate.Settings

Select Case objSettings.ScheduledInstallationDay
Case 0
strDay = "every day"
Case 1
strDay = "sunday"
Case 2
strDay = "monday"
Case 3
strDay = "tuesday"
Case 4
strDay = "wednesday"
Case 5
strDay = "thursday"
Case 6
strDay = "friday"
Case 7
strDay = "saturday"
Case Else
strDay = "The scheduled installation day is could not be determined."
End Select

If objSettings.ScheduledInstallationTime = 0 Then
strScheduledTime = "12:00 AM"
ElseIf objSettings.ScheduledInstallationTime = 12 Then
strScheduledTime = "12:00 PM"
Else
If objSettings.ScheduledInstallationTime > 12 Then
intScheduledTime = objSettings.ScheduledInstallationTime - 12
strScheduledTime = intScheduledTime & ":00 PM"
Else
strScheduledTime = objSettings.ScheduledInstallationTime & ":00 AM"
End If
'strTime = "Scheduled installation time: " & strScheduledTime
End If

writelog("Windows update agent is scheduled to run on " & strDay & " at " & strScheduledTime)
End Sub

Sub CheckUpdateAgent()

writelog("Checking version of Windows Update agent against version " _
& strWUAgentVersion & "...")

bUpdateNeeded = True ' init value

On Error Resume Next
Set updateSession = CreateObject("Microsoft.Update.AgentInfo")
If Err.Number = 0 Then
updateinfo = updateSession.GetInfo("ProductVersionString")
If replace(updateInfo,strLocaleDelim,"") = replace(strWUAgentVersion,strLocaleDelim,"") then
writelog("File versions match (" & updateinfo & "). Windows Update Agent is up to date.")
bUpdateNeeded = False
ElseIf updateInfo > strWUAgentVersion Then
writelog("Your installed version of the Windows Update Agent (" & updateinfo & ") is newer than the referenced version (" & strWUAgentVersion & ").")
bUpdateNeeded = False
End If
End If

If bUpdateNeeded Then
' stop the Automatic Updates service
writelog("File version (" & updateinfo & ") does not match. Windows Update Agent 2.0 required.")
writelog("Stopping service 'wuauserv'")
WshShell.Run "%SystemRoot%\system32\net.exe stop wuauserv", 1, True
' install tha AU client

Set WUAUService = GetObject("WinMgmts:{impersonationLevel=impersonate}!//./root/cimv2:Win32_Service.Name='wuauserv'")
serviceState = WUAUService.state
writelog("Automatic Updates Service State ('wuauserv'): " & serviceState & """")

' KG: Just in case it is taking a while to stop, we'll loop.
Do Until serviceState = "Stopped"
WScript.Sleep 3000
serviceState = WUAUService.State
writelog("Automatic Updates Service State ('wuauserv'): " & serviceState & """")
Loop


On Error Resume Next
Set oEnv = WshShell.Environment("PROCESS")
oEnv("SEE_MASK_NOZONECHECKS") = 1
writelog("Attempting to install agent from '" & sExePath & "'")
WshShell.Run sExePath & " /quiet /norestart", 1, True

If CStr(err.number) <> 0 Then
blnFatal = false
strMsg = "Error executing Agent EXE - [" & err.number & "]: " & err.description & " (" & sExePath & ")"
call ErrorHandler("Program Execution",strMsg,blnFatal)
End If
End If

End Sub

'****************************************************************************
***'Function SendMail - email the warning file
'****************************************************************************
***
Function SendMail(strFrom,strTo,strSubject,strMessage)
Dim iMsg, iConf, Flds

writelog("Calling sendmail routine")
writelog("To: " & strMailto)
writelog("From: " & strMailFrom)
writelog("Subject: " & strSubject)
writelog("SMTP Server: " & strSMTPServer)

'If silent = 0 Then objdiv.innerhtml = "<font face=" & strFontStyle & " color=" & strFontColor2& ">" _
' & "sending mail to " & strMailTo & "...</font><br>"

'// Create the CDO connections.
Set iMsg = CreateObject("CDO.Message")
Set iConf = CreateObject("CDO.Configuration")
Set Flds = iConf.Fields

If lcase(strAuthType) <> "cdoanonymous" Then
'Type of authentication, NONE, Basic (Base64 encoded), NTLM
iMsg.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = strAuthType

'Your UserID on the SMTP server
iMsg.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusername") = strAuthID

'Your password on the SMTP server
iMsg.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendpassword") = strAuthPassword

End if

'// SMTP server configuration.
With Flds
.Item(cdoSendUsingMethod) = cdoSendUsingPort
.Item(cdoSMTPServer) = strSMTPServer
.Item(cdoSMTPServerPort) = iSMTPServerPort
.Item(cdoSMTPconnectiontimeout) = 60
.Update
End With
'l.close

Dim r
Set r = ws.OpenTextFile (logfile, ForReading, False, TristateUseDefault)
strMessage = "<font face='" & strFontStyle & "' size='2'>" & r.readall & "</font>"

'// Set the message properties.
With iMsg
Set .Configuration = iConf
.To = strMailTo
.From = strMailFrom
.Subject = strSubject
'.TextBody = strMessage
End With

'iMsg.AddAttachment wsuslog
iMsg.HTMLBody = replace(strMessage,vbnewline,"<br>")
'// Send the message.
on error resume next

iMsg.Send ' send the message.
Set iMsg = nothing

If CStr(err.number) <> 0 Then
strMsg = "Problem sending mail to " & strSMTPServer & "." _
& "Error [" & err.number & "]: " & err.description & "<br>"

Call ErrorHandler("Sendmail function",replace(strMsg,"<br>",""),"false")
'writelog(strMsg)
strStatus = strMsg
If silent = 0 Then objdiv.innerhtml = strStatus
Else
strStatus = "Connected successfully to email server " & strSMTPServer
writelog(strStatus)
strStatus = strStatus & "<br><br><font face=" & strFontStyle & " color=" & strFontColor2& ">" _
& "sent email to " & strMailTo & "...</font><br><BR>" _
& "Script complete.<br><br><a href='" & logfile & "'>View log file</a>"
If silent = 0 Then objdiv.innerhtml = strStatus
End If

'cause WU agent to detect
autoUpdateClient.detectnow()
blnEmail = 0

End Function
'****************************************************************************
***'Function RestartAction
'Sub to perform a restart action against the computer
'****************************************************************************
***
Function RestartAction
If silent = 0 Then objdiv.innerhtml = strStatus & "<br> Now performing restart action (" & restarttext & ")."
wscript.sleep 4000
writelog("Processing RestartAction")
'On Error GoTo 0
Dim OpSysSet, OpSys
'writelog("Computer: " & strComputer & vbcrlf & "Restart Action: " & strRestart)

'On Error Resume Next

'Call WMI query to collect parameters for reboot action
Set OpSysSet = GetObject("winmgmts:{(Shutdown)}//" & strComputer & "/root/cimv2").ExecQuery("select * from Win32_OperatingSystem"_
& " where Primary=true")

If CStr(err.number) <> 0 Then
strMsg = "There was an error while attempting to connect to " & strComputer & "." & vbcrlf & vbcrlf _
& "The actual error was: " & err.description
writelog(strMsg)
blnFatal = true
Call ErrorHandler("WMI Connect",strMsg,blnFatal)
End If

Const EWX_LOGOFF = 0
Const EWX_SHUTDOWN = 1
Const EWX_REBOOT = 2
Const EWX_FORCE = 4
Const EWX_POWEROFF = 8

'set PC to reboot
If strRestart = 1 Then

For each OpSys in OpSysSet
opSys.win32shutdown EWX_REBOOT + EWX_FORCE
Next

'set PC to shutdown
ElseIf strRestart = 2 Then

For each OpSys in OpSysSet
opSys.win32shutdown EWX_POWEROFF + EWX_FORCE
Next

'Do nothing...
ElseIf strRestart = "0" Then

End If


End Function

'****************************************************************************
***
'Sub ErrorHandler
'Sub to help display/log any errors that occur
'****************************************************************************
***
Sub ErrorHandler(strSource,strMsg,blnFatal)
'Set theError = RemoteScript.Error

If silent = 0 then wscript.echo "Source: " & strSource & " - " & strMsg
writelog(strMsg)
If blnFatal = true then wscript.quit
err.clear
End Sub

'****************************************************************************
***'Function EndOfScript
'Function to close out the script
'****************************************************************************
***
Function EndOfScript

If blnInstall = true then Call CheckPendingStatus("end")
on error goto 0
writelog("Windows Update VB Script finished")
l.writeline "---------------------------------------------------------------------------"
If blnCallRestart = true then writelog("Restart action will be called. " _
& "Restart action is set to: " & restarttext & ".")


If blnEmail = 1 Then
If searchresult.updates.count = 0 and not blnRebootRequired and StrEmailifAllOK = 0 then
writelog ("No updates required, no pending reboot, therefore not sending email")
else
if strFullDNSName = 1 then
strDomainName = wshShell.ExpandEnvironmentStrings("%USERDNSDOMAIN%")
strOutputComputerName = strComputer & "." & StrDomainName
else
strOutputComputerName = strComputer
end if
if emailifallok = 0 or emailifallok = 1 then
if instr(strSMTPServer,"x") then
else
Call SendMail(strFrom,strTo,strSubject & " " & strOutputComputerName,strMessage)
end if
end if
end if
Else
'l.close

End If

strMsg = "The script has been configured to " & restarttext _
& ". The update script has detected that this " _
& "computer has a reboot pending from a previous update session." & vbcrlf & vbcrlf _
& "Would you like to perform this action now?"

If silent = 0 and blnPrompt = true Then
strResult = MsgBox(strMsg,36,"Perform restart/shutdown action?")
ElseIf blnPrompt = false Then
strResult = 6
End If

If blnCallRestart = true Then
If strResult = 6 Then call RestartAction
Else
on error resume next
If silent = 0 Then objdiv.innerhtml = strStatus & "<br>This computer has no pending reboots"
End If

If intSleep > 0 Then
' So the user have a chance to see the last output before closing IE
WScript.Sleep intSleep
' Just in case the IE window is already closed by the user
On Error Resume Next
' Close the IE window
IE.Quit
On Error Goto 0
End If
'l.close
wscript.quit

Exit Function

End Function
'****************************************************************************
***'Function CheckPendingStatus
'Function to restart the computer if there is a reboot pending...
'****************************************************************************
***
Function CheckPendingStatus(beforeorafter)
Set ComputerStatus = CreateObject("Microsoft.Update.SystemInfo")
Select case beforeorafter
Case "beginning"
strCheck = "Pre-check"
Case "end"
strCheck = "Post-check"
Case Else
End Select

blnRebootRequired = ComputerStatus.RebootRequired

If ComputerStatus.RebootRequired or strForceAction = 1 Then
If beforeorafter = "beginning" Then
If ComputerStatus.RebootRequired Then strMsg = "This computer has a pending reboot (" & strCheck & "). Switching to 'detect' mode."
If strAction = "prompt" Then blnPrompt = true
strAction = "detect"
blnCallRestart = true
Else
If ComputerStatus.RebootRequired Then strMsg = "This computer has a pending reboot (" & strCheck & "). Setting PC to perform post-script " _
& "execution..."
blnCallRestart = true
End If
Else
If not ComputerStatus.RebootRequired Then strMsg = "This computer does not have any pending reboots (" & strCheck & ")."
End If

If strMsg <> "" Then writelog(strMsg)
If silent = 0 and strMsg <> "" then objdiv.innerhtml = strMsg
'wscript.sleep 4000

End Function
'****************************************************************************
***
0

#114 User is offline   1suspect 

  • Member
  • PipPip
  • Group: Regular Members
  • Posts: 41
  • Joined: 08-Feb-05

Posted 20 Mar 2009, 12:54

psexec.exe \\[PCNAME] -u [DOMAIN]\[ADMIN] -p [PASSWORD] -i wscript //B \\[PATH TO UPDATEHT.VBS]\updatehf.vbs mode:silent restart:1 force:1


Hello,

I am trying the path you provided and am getting the following:

wscript exited on MACHINENAME with error code 1.

Any ideas what is causing this?

Thanks
0

#115 User is offline   1suspect 

  • Member
  • PipPip
  • Group: Regular Members
  • Posts: 41
  • Joined: 08-Feb-05

Posted 25 Mar 2009, 14:20

View Post1suspect, on Fri 20th Mar 2009, 03:54 pm, said:

Any ideas what is causing this?


Turns out the problem was we weren't passing credentials. They are required!

Thanks
0

#116 User is offline   Hector 

  • Newbie
  • Pip
  • Group: New Members
  • Posts: 1
  • Joined: 06-Feb-09

Posted 13 Apr 2009, 15:18

OK, I've posted this a couple of places.

The below WMI call doesn't work in an XP virtual machine hosted in a VMWare ESX environment, the error that results is always "There was an error while attempting to connect to <name>". Anyone seen this?

'Call WMI query to collect parameters for reboot action
Set OpSysSet = GetObject("winmgmts:{(Shutdown)}//" & strComputer & "/root/cimv2").ExecQuery("select * from Win32_OperatingSystem"_
& " where Primary=true")

If CStr(err.number) <> 0 Then
strMsg = "There was an error while attempting to connect to " & strComputer & "." & vbcrlf & vbcrlf _
& "The actual error was: " & err.description
writelog(strMsg)
blnFatal = true
Call ErrorHandler("WMI Connect",strMsg,blnFatal)
End If
0

#117 User is offline   dvanmeter 

  • Advanced Member
  • PipPipPip
  • Group: Advisory Members
  • Posts: 1522
  • Joined: 22-Jul-03

Posted 16 Apr 2009, 15:05

I put a tool out just last week. It uses Rob's script, coupled with a frontend script I wrote and a utility called atnow.exe. Its all combined into an exe (actually a silent selfextractor). It copies Rob's script to the remote computer and executes with a task scheduled within 60 seconds. I found PSEXEC was sometimes blocked by IPS systems. If you have a smtp server that doesnt require authentication it should send you an email etc. I am planning on making it more robust but it has been working from me for many servers. Look in the tools section, the actual tool is called remote update 1.6. http://www.wsus.info...showtopic=13401

This post has been edited by dvanmeter: 16 Apr 2009, 15:07

0

#118 User is offline   santito 

  • Newbie
  • Pip
  • Group: New Members
  • Posts: 1
  • Joined: 20-Apr-09

Post icon  Posted 21 Apr 2009, 11:57

I know this was asked much earlier in this post but never saw a reply... is there a way to either modify this script or is there a script available that will just install patches that have been downloaded and are waiting to be installed?
0

#119 User is offline   medoneit 

  • Newbie
  • Pip
  • Group: New Members
  • Posts: 1
  • Joined: 21-Apr-09

Posted 22 Apr 2009, 07:46

I found the CheckPendingStatus code would set strAction to detect, even though the computer had no reboot pending
My parameters are action:install restart:1 force:1

My Code ammendment is this:
If ComputerStatus.RebootRequired or strForceAction = 1 Then
If beforeorafter = "beginning" Then
If ComputerStatus.RebootRequired Then
strMsg = "This computer has a pending reboot (" & strCheck & "). Switching to 'detect' mode."
strAction = "detect"
end if

=====

Not sure why I seem to be the only one to come across this... in fact I did not come across this on the first computer I tested on.

Weird.
0

#120 User is offline   benwaynet 

  • Member
  • PipPip
  • Group: Regular Members
  • Posts: 6
  • Joined: 17-Feb-04

Posted 11 May 2009, 08:10

Just found this thread and started reading through it for a way to do a list of servers. It looks like Nerdcentric.com's script zombie will fit the bill with this script.
dvanmeter's atnow util looks interesting, but I need to do multiple servers, not one at a time.

Which version of the script should I get. I see the download of 2.5 on the first page. But i've seen people talk about 2.6 and 2.7?
0

  • (8 Pages)
  • +
  • « First
  • 4
  • 5
  • 6
  • 7
  • 8
  • You cannot start a new topic
  • You cannot reply to this topic

3 User(s) are reading this topic
0 members, 3 guests, 0 anonymous users