Here is a script that will configure SP2 and above machines to use SUS
This script was adapted from a script written by Tony Skinner.
The original required reg.exe from the Recource kit, which I didn't want to
use. So I rewrote it to use WMI. I also added some logic that was not in
the original.
The Auto Update client "wuau22.msi" is available from microsoft.
'## MSUS/Automatic Update Client Push Script (for Non-Active Directory
Environments)
Const Version = "3.0"
'## Script Configuration
Const Test_Deploy = 0 ' Set to 0 for production deployments
Const Failure_Logging = 1 'Default is 1 (0 turns failure logging off)
Const Failure_Log_Filename = "msusfail.txt" ' valid filename
Const Failure_Log_Path = "C:\" ' Valid path (dont forget the backslash!)
Const Server_List_Filename = "msus.txt" 'List of machines that the
script will be run against.
Const Server_List_Path = "C:\" 'Location of the Server List File
Const MSUS_Test_Server = "
HTTP://TestServer.mydomain.com" ' Test Server
Short Name (Can use FQDN)
Const MSUS_Prod_Server = "
http://ProdServer.mydomain.com" ' Production
Server Short Name (Can use FQDN)
Const AU_Software_UNC_Path = "\\Server\Share\susclient\" ' Share Name
and/or UNC Path to Automatic Update .MSI file
Const AU_Msi_Filename = "wuau22.msi"' Automatic Update .MSI File Name
'## Registry Variables for Automatic Update Client
Const NoAutoUpdate = "0" ' Set to 1 to disable Automatic Updates
Const AUOptions = "4"' 2: Notify for download/install, 3: Auto download,
notify install 4: Auto download/install
Const ScheduledInstallDay = "0" ' 0: Every Day, 1 - 7: Sunday (1) to
Saturday (7)
Const ScheduledInstallTime = "3" ' Range = n where n = 0-23 (time of day
in 24hr format)
Const UseWUServer = "1" 'Tells Automatic Update client to use specified
MSUS Server for Update
Const RescheduleWaitTime = "5" 'Tells Automatic Update Client to
reschedule missed deployments this number of minutes after next bootup
Const NoAutoRebootWithLoggedOnUsers = "1" 'Set to 1 prompt user to
reboot after installation, Set to 0 to automatically reboot (no warning)
'## Generic commands - Dont Edit These
Const Ping = "cmd /c Ping -n 2"
Const HKEY_LOCAL_MACHINE = &H80000002
Const ALL_USERS = True
'## Open the Server List file
Set oShell = CreateObject("Wscript.Shell")
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oStream = oFSO.OpenTextFile(Server_List_Path + Server_List_Filename,
1, -2)
WScript.Echo "MSUS/Automatic Update Client - Push Script"
WScript.Echo "Version " &Version
WScript.Echo ""
If Failure_Logging = 1 Then
Set oFS1 = CreateObject("Scripting.FileSystemObject")
Set oStream1 = oFS1.CreateTextFile(Failure_Log_Path +
Failure_Log_Filename, 2)
oStream1.Writeline "MSUS/Automatic Update Client Push Script - Error
Log"
oStream1.Writeline "Version " &Version
oStream1.Writeline "Date: " &CStr(Date)
oStream1.Writeline "Time: " &CStr(Time)
oStream1.Writeline ""
End If
'## Main
Do Until oStream.AtEndOfStream
Target = oStream.ReadLine
WScript.Echo " "
WScript.Echo "Target: " + Target
'## Verify host is active on the network
If Ping_Host(Target) <> 1 Then
oStream1.Writeline "Host " + Target + " not Found"
Else
OperatingSystem = Find_OS(Target)
'## Verify host operating system is Win2000
If OperatingSystem = "Microsoft Windows 2000 Professional" Then
'## Verify Service Pack level
Service_Pack = Right(Find_ServicePack(Target),1)
If Service_Pack = "2" then
If(Check_WUService(Target)) <> 1 Then 'check to see if
the Auto Update Client is already installed
Install_WUService(Target) 'Install client if missing
End If
Configure_WUService(Target) 'add registry entries
WScript.Echo "Proccess Complete On " + target
ElseIf Service_Pack = "3" Or Service_Pack = "4" Then
'Service pack 3 and 4 machines already have the client installed
Configure_WUService(Target) 'all these machines need is
the registry entries.
WScript.Echo "Proccess Complete On " + target
Else
WScript.echo "Host " + Target + " is Pre Service Pack 2"
'do not perform any action on pre service pack 2 machines
oStream1.Writeline "Host " + Target + " is Pre Service
Pack 2"
End If
Elseif OperatingSystem = "Microsoft Windows XP Professional"
Then
Find_ServicePack Target
Configure_WUService(Target) 'all these machines need is the
registry entries.
WScript.Echo "Proccess Complete On " + target
Else
WScript.Echo "Host " + Target + " is not running Windows
2000 Professional"
oStream1.writeline "Host " + Target + " is not running
Windows 2000 Professional"
End If
End If
Loop
If Failure_Logging = 1 Then
Set oStream1 = Nothing
Set oFS1 = Nothing
End If
Set oStream = Nothing
Set oFS0 = Nothing
WScript.Echo "Last Host Complete"
'## Verify if Window Update is installed, if not, install it
Function Check_WUService(Target)
Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &
Target & "\root\default:StdRegProv")
strKeyPath = "SYSTEM\CurrentControlSet\Services\"
oReg.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubKeys
For Each subkey In arrSubKeys
If subkey = "wuauserv" then
Check_WUService = 1
WScript.Echo "Windows Update is Installed"
Exit Function
End If
Next
Check_WuService = 0 'Did not find the wuau service key.
End Function
'## Install Windows Update Service
Function Install_WUService(Target)
Dim CommandLine, objWMIService, objSoftware
'## xcopy \\mycomp\au_dir\ausoftware.msi \\target\c$
Wscript.Echo "Copying " + AU_Msi_Filename + " to " + Target
CommandLine = "xcopy /Y " + AU_Software_UNC_Path + AU_Msi_Filename + "
\\" + Target + "\c$"
Error = Exe(CommandLine)
If Error <> 0 Then
WScript.Echo "Error copying " + AU_Msi_Filename + " to " + Target
oStream1.Writeline "Error copying " + AU_Msi_Filename + " to " +
Target
Exit Function
End If
Set objWMIService = GetObject("winmgmts:\\" & Target & "\root\cimv2")
Set objSoftware = objWMIService.Get("Win32_Product")
Wscript.Echo "Installing Windows Update Client on " + Target
Error = objSoftware.Install("c:\" + AU_Msi_Filename, , ALLUSERS)
If Error <> 0 Then
WScript.Echo "Error Installing " + AU_Msi_Filename + " to " + Target
+ ". Error: " + Error
oStream1.Writeline "Error Installing " + AU_Msi_Filename + " to " +
Target + ". Error: " + Error
End If
WScript.Echo "Deleting " + AU_Msi_Filename + " from " + Target
'## Delete MSI file when done
CommandLine = "cmd /c Del \\"+target+"\c$\"+AU_Msi_Filename+ " /q"
Error = Exe (CommandLine)
If Error <> 0 Then
WScript.Echo "Error Deleting " + AU_Msi_Filename + " from " + Target
+ ". Error: " + Error
oStream1.Writeline "Error Deleting " + AU_Msi_Filename + " from " +
Target + ". Error: " + Error
End If
End Function
'## Configure Windows Update inside Registry
Function Configure_WUService(Target)
Set ObjRegistry = GetObject("winmgmts:{impersonationLevel =
impersonate}!\\" & Target & "\root\default:StdRegProv")
'## Set MSUS_Server variable based on value of Test_Deploy (Test or
Prod)
If Test_Deploy = 1 Then
MSUS_Server = MSUS_Test_Server
Else
MSUS_Server = MSUS_Prod_Server
End If
WScript.Echo "Performing Registry Changes"
'## Root Key Locations for Automatic Update Client
strPath = "SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate"
objRegistry.CreateKey HKEY_LOCAL_MACHINE, strPath
'Return = objRegistry.CreateKey(HKEY_LOCAL_MACHINE, strPath)
strValueName = "WUServer"
objRegistry.SetStringValue HKEY_LOCAL_MACHINE,
strPath,strValueName,MSUS_Server
strValueName = "WUStatusServer"
objRegistry.SetStringValue HKEY_LOCAL_MACHINE,
strPath,strValueName,MSUS_Server
strPath = "SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU"
objRegistry.CreateKey HKEY_LOCAL_MACHINE, strPath
'Return = objRegistry.CreateKey(HKEY_LOCAL_MACHINE, strPath)
strValueName = "AUOptions"
Value = AUOptions
objRegistry.SetDWORDValue HKEY_LOCAL_MACHINE, strPath,strValueName,Value
strValueName = "NoAutoUpdate"
Value = NoAutoUpdate
objRegistry.SetDWORDValue HKEY_LOCAL_MACHINE, strPath,strValueName,Value
strValueName = "ScheduledInstallDay"
Value = ScheduledInstallDay
objRegistry.SetDWORDValue HKEY_LOCAL_MACHINE, strPath,strValueName,Value
strValueName = "ScheduledInstallTime"
Value = ScheduledInstallTime
objRegistry.SetDWORDValue HKEY_LOCAL_MACHINE, strPath,strValueName,Value
strValueName = "UseWUServer"
Value = UseWUServer
objRegistry.SetDWORDValue HKEY_LOCAL_MACHINE, strPath,strValueName,Value
strValueName = "RescheduleWaitTime"
Value = RescheduleWaitTime
objRegistry.SetDWORDValue HKEY_LOCAL_MACHINE, strPath,strValueName,Value
strValueName = "NoAutoRebootWithLoggedOnUsers"
Value = NoAutoRebootWithLoggedOnUsers
objRegistry.SetDWORDValue HKEY_LOCAL_MACHINE, strPath,strValueName,Value
End Function
'## Get Operating System
Function Find_OS(Target)
Dim objWMIService, colItems
Set objWMIService = GetObject("winmgmts:\\" & Target & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from
Win32_OperatingSystem",,48)
For Each objItem in colItems
Find_OS = objItem.Caption
Next
Wscript.echo "Host " + Target + " is running " + Find_OS
End Function
'## Get Service Pack Level
Function Find_ServicePack(Target)
Dim objWMIService, colItems
Set objWMIService = GetObject("winmgmts:\\" & Target & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from
Win32_OperatingSystem",,48)
For Each objItem in colItems
Find_ServicePack = ObjItem.CSDVersion
Next
Wscript.echo "Found " & Find_ServicePack
End Function
'## Ping the host twice, on first Reply message found and exit function else
fail
Function Ping_Host(Target)
Dim oExec, CommandLine
CommandLine = Ping + " " + Target
Set oExec = oShell.Exec(CommandLine)
'## Examine output of exec command line by line (kill loop when no more
input)
Do Until oExec.StdOut.AtEndOfStream
Input = oExec.StdOut.ReadLine
'## If host replies, set ping_host to 1 then exit
If InStr(Input, "Reply") Then
WScript.Echo "Host " + Target + " Found"
Ping_Host = 1
Exit Function
End If
Loop
WScript.Echo "Host " + Target + " not Found"
Ping_Host = 0
End Function
'## Execution Function - Processes command line strings and executes
Function Exe(CmdLn)
Dim Error, Msg
Error = oShell.Run(CmdLn, 6, True)
Exe = Error
End Function