Windows Vista Tips

Windows Vista Tips > Newsgroups > Windows Update > Script Remote Force Wsus in a Range

Reply
Thread Tools Display Modes

Script Remote Force Wsus in a Range

 
 
Jeferson Propheta
Guest
Posts: n/a

 
      08-07-2007
************************************************** ************************************************** *******
'* Wsus Remote Force in Network Range
*
'* -------------------------------------
*
'* Written by : Jeferson Propheta
*
'* Date : August / 2007
*
'* Description: Create 2 Process in a Remoter Computer using a stipulate
Range in order to Force WSUS *
'* Detection and Report
*
'* -------------------------------------
*
'* Configure #Sessions
*
'* #1 - to specify the Location of Log File and Log File Name
*
'* #2 - to mount the Network Range
*
'*
*
'*
*
'************************************************* ************************************************** ************
On Error Resume Next

Const HKEY_LOCAL_MACHINE = &H80000002
Const ForReading = 1, ForAppending = 8

'************************************************* ************************************************** ************
'* WSUS Commands
*
'* -------------------------------------
*
'************************************************* ************************************************** ************

strWsusCommand = "wuauclt /ResetAuthorization /DetectNow"
strWsusCommand2 = "wuauclt /ReportNow"
ServiceName = "wuauserv"

'************************************************* ************************************************** ************
'* Script initial Sets
*
'* -------------------------------------
*
'************************************************* ************************************************** ************

Set objShell = CreateObject("WScript.Shell")
Set objOUTFSO = CreateObject("Scripting.FileSystemObject")

'#Session 1
'************************************************* ************************************************** ************
'* Output File name and Folder
*
'* -------------------------------------
*
'************************************************* ************************************************** ************

strOutDirectory = "C:\Temp\"
strOutFile = "\WsusRangeForceReport.txt"
LineSeparator = 48
LineSeparatorChar = "-"

'************************************************* ************************************************** ************
'* Output Folder Structure and File Creation
*
'* -------------------------------------
*
'************************************************* ************************************************** ************
If objOUTFSO.FolderExists(strOutDirectory) Then
Set objFolder = objOUTFSO.GetFolder(strOutDirectory)
Else
Set objFolder = objOUTFSO.CreateFolder(strOutDirectory)
End If

If objOUTFSO.FileExists(strOutDirectory & strOutFile) Then
Set objFolder = objOUTFSO.GetFolder(strOutDirectory)
strOutpath = strOutDirectory & strOutFile
objOUTFSO.DeleteFile(strOutpath)
Else
Set objFile = objOUTFSO.CreateTextFile(strOutDirectory &
strOutFile)
End If

'#Session 1
'************************************************* ************************************************** ************
'* Subnet Settings
*
'* -------------------------------------
*
'************************************************* ************************************************** ************
Subnet = "192.168.25" 'Subnet Start

For ii = 1 to 7 'i.e.: 192.168.251.xxx to 192.168.257.xxx
For i = 0 to 254 'i.e.: 192.168.251.0 to 192.168.257.254

strTarget = Subnet & ii & "." & i

'************************************************* ************************************************** ************
'* Target IP Test
*
'* -------------------------------------
*
'************************************************* ************************************************** ************

Set objWMIServicePing = GetObject("winmgmts:\\.\root\cimv2")
Set colItems = objWMIServicePing.ExecQuery ("Select * from
Win32_PingStatus " & "Where Address = '" & strTarget & "'")
Set objFile = Nothing
Set objFolder = Nothing
Set objOutTextFile = objOUTFSO.OpenTextFile (strOutDirectory
& strOutFile, ForAppending, True)



For Each objItem in colItems
If objItem.StatusCode = 0 Then

strComputer = strTarget

'************************************************* ************************************************** ************
'* Check Service
*
'* -------------------------------------
*
'************************************************* ************************************************** ************

If ServiceExist(ServiceName) = True Then

Set objWMIService = GetObject("winmgmts:" &
"{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colServices = objWMIService.ExecQuery ("SELECT *
FROM Win32_Service WHERE Name = 'wuauserv'")
For Each objService in colServices
errReturnCode = objService.StopService()
errReturnCode = objService.StartService()
Next

'************************************************* ************************************************** ************
'* Write IP Address and Response Time
*
'* -------------------------------------
*
'************************************************* ************************************************** ************
Set objProcess = objWMIService.Get("Win32_Process")

objOutTextFile.WriteLine String(LineSeparator,
LineSeparatorChar)
objOutTextFile.WriteLine ("IP Address : "
& strTarget)
objOutTextFile.WriteLine ("Reply received at : "
& Now())

'************************************************* ************************************************** ************
'* Start Process One
*
'* -------------------------------------
*
'************************************************* ************************************************** ************
intReturn = objProcess.Create (strWsusCommand,
Null, Null, intProcessID)

If intReturn = 0 Then
objOutTextFile.WriteLine ("Process ID 1 Created : "
& intProcessID)
Else
objOutTextFile.WriteLine ("Process 1 could not be
created!!!!")
End If

'************************************************* ************************************************** ************
'* Start Process Two
*
'* -------------------------------------
*
'************************************************* ************************************************** ************
intReturn = objProcess.Create (strWsusCommand2,
Null, Null, intProcessID)

If intReturn = 0 Then
objOutTextFile.WriteLine ("Process ID 2 Created : "
& intProcessID)
Else
objOutTextFile.WriteLine ("Process 2 could not be
created!!!!")
End If


Else

'************************************************* ************************************************** ************
'* Write Cannot Find the Service (Probably 9x or Non-Windows O.S.)
*
'* -------------------------------------
*
'************************************************* ************************************************** ************

objOutTextFile.WriteLine String(LineSeparator,
LineSeparatorChar)
objOutTextFile.WriteLine ("IP Address : " &
strTarget & " Cannot Find the Service... Process Aborted!")

End IF


Else

'************************************************* ************************************************** ************
'* Write Ping Not-Reply
*
'* -------------------------------------
*
'************************************************* ************************************************** ************

objOutTextFile.WriteLine String(LineSeparator,
LineSeparatorChar)
objOutTextFile.WriteLine ("IP Address : " & strTarget & "
Reply Not received " & Now())
End If



Next



Next
Next


'************************************************* ************************************************** ************
'* Write End of Log
*
'* -------------------------------------
*
'************************************************* ************************************************** ************

objOutTextFile.WriteLine String(LineSeparator, LineSeparatorChar)
objOutTextFile.WriteLine String(LineSeparator, LineSeparatorChar)
objOutTextFile.WriteLine ("WSUS Range Force v0.1")
objOutTextFile.WriteLine ("This Report summarizes the status of the Update
Services Force in the Range.")
objOutTextFile.WriteLine ("Report Finished at: " & Now())
objOutTextFile.WriteLine String(LineSeparator, LineSeparatorChar)
objOutTextFile.WriteLine String(LineSeparator, LineSeparatorChar)


Wscript.Quit






'************************************************* ************************************************** ************
'* Services Function
*
'* -------------------------------------
*
'************************************************* ************************************************** ************

Function ServiceExist(ServiceName)
strComputer = strTarget

Set objWMIService = GetObject("winmgmts:\\" & strTarget &
"\root\CIMV2")
Set colItems = objWMIService.ExecQuery("SELECT * FROM
Win32_Service",,48)

For Each objItem in colItems

If objItem.Name = ServiceName Then
ServiceExist = True
End If

Next
End Function


Function SetStartType(StartMode, ServiceName)


If ServiceExist(ServiceName) = True Then
Set objWMIService = GetObject("winmgmts:\\" & strTarget &
"\root\CIMV2")
Set objShare = objWMIService.Get("Win32_Service.Name='" &
ServiceName & "'")
Set objInParam =
objShare.Methods_("ChangeStartMode").inParameters. SpawnInstance_()

objInParam.Properties_.Item("StartMode") = StartMode

Set objOutParams =
objWMIService.ExecMethod("Win32_Service.Name='"& ServiceName & "'",
"ChangeStartMode", objInParam)
SetStartType = objOutParams.ReturnValue
Else
SetStartType = 9
End If
End Function
 
Reply With Quote
 
 
 
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Force a specific update from WSUS Erin Windows Update 2 09-19-2006 06:54 PM
Force WSUS to update Tagnutter Windows Update 1 07-27-2006 12:03 PM
Is there anyway to force the WSUS server to update clients only at a weekend? test2005@bgop.org.uk Windows Update 2 03-21-2006 11:06 AM
force install on shutdown in WSUS WTB Windows Update 1 09-03-2005 03:35 AM
Is there a way to force the install of WSUS updates at shutdown o dsm Windows Update 1 05-06-2005 05:32 PM



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59