Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Patch management

Status
Not open for further replies.

WhiteWiz

MIS
Jan 29, 2001
113
CA
how do I ;
-display the o/s patch level from a command line
-schedule a task from the command line, (something better than at)
 
''******************************************************************************
'* scriptenv.vbs
'* Gets versions of OS, WSH, WMI & ADSI on local machine
'* and determines which are up-to-date.
'******************************************************************************

On Error Resume Next

Const MAXIMIZE_WINDOW = 3

strComputer = "." ' local computer
strNamespace = "\root\cimv2" ' default namespace
blnWSHUpToDate = False
blnWMIUpToDate = False
blntADSIUpToDate = False

'******************************************************************************
'* Call functions to get information on default WSH host.
'* If Wscript.exe, temporarily change to Cscript.exe
'******************************************************************************

strWshHost = GetWshHost
ChangeToCscript(strWshHost)

'******************************************************************************
'* Connect to WMI Service.
'******************************************************************************

Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" _
& strComputer & strNamespace)

If Err.Number <> 0 Then
WScript.Echo &quot;Error 0x&quot; & hex(Err.Number) & &quot; &quot; & _
Err.Description & &quot;. &quot; & VbCrLf & _
&quot;Unable to connect to WMI. WMI may not be installed.&quot;
Err.Clear
WScript.Quit
End If


'******************************************************************************
'* Call functions to get information on OS, WSH, WMI and ADSI.
'******************************************************************************

intOSVer = GetOSVer
blnWSHUpToDate = GetWSHVer(intOSVer, strWshHost)
blnWMIUpToDate = GetWMIVer(intOSVer)
blnADSIUpToDate = GetADSIVer(intOSVer)

'******************************************************************************
'* Call sub to list which versions are current.
'******************************************************************************

ListUpToDate blnWSHUpToDate, blnWMIUpToDate, blnADSIUpToDate

'******************************************************************************
'* Determines WSH script host.
'******************************************************************************

Function GetWshHost()

strErrorMessage = &quot;Could not determine default script host.&quot;
strFullName = WScript.FullName

If Err.Number <> 0 Then
WScript.Echo &quot;Error 0x&quot; & hex(Err.Number) & &quot; &quot; & _
Err.Description & &quot;. &quot; & VbCrLf & strErrorMessage
Err.Clear
Exit Function
End If

If IsNull(strFullName) Then
WScript.Echo strErrorMessage
Exit Function
End If

strWshHost = Right(LCase(strFullName), 11)
If Not((strWshHost = &quot;wscript.exe&quot;) Or (strWshHost = &quot;cscript.exe&quot;)) Then
WScript.Echo strErrorMessage
Exit Function
End If

GetWshHost = strWshHost

End Function

'******************************************************************************
'* If default Windows Script Host is Wscript, change to Cscript.
'******************************************************************************

Sub ChangeToCscript(strWshHost)


If strWshHost = &quot;wscript.exe&quot; Then
Set objShell = CreateObject(&quot;WScript.Shell&quot;)
objShell.Run _
&quot;%comspec% /k &quot;&quot;cscript //h:cscript&&cscript scriptenv.vbs&quot;&quot;&quot;, _
MAXIMIZE_WINDOW
If Err.Number <> 0 Then
WScript.Echo &quot;Error 0x&quot; & hex(Err.Number) & &quot; occurred. &quot; & _
Err.Description & &quot;. &quot; & VbCrLf & _
&quot;Could not temporarily change the default script host to Cscript.&quot;
Err.Clear
WScript.Quit
End If
WScript.Quit
End If

End Sub

'******************************************************************************
'* Get OS information.
'******************************************************************************

Function GetOSVer()

intOSType = 0
intOSVer = 0
strOSVer = &quot;&quot;

Set colOperatingSystems = objWMIService.ExecQuery _
(&quot;Select * from Win32_OperatingSystem&quot;)

For Each objOperatingSystem In colOperatingSystems
Wscript.Echo vbCrLf & &quot;Operating System&quot; & vbCrLf & _
&quot;================&quot; & vbCrLf & _
&quot;Caption: &quot; & objOperatingSystem.Caption & VbCrLf & _
&quot;OSType: &quot; & objOperatingSystem.OSType & VbCrLf & _
&quot;Version: &quot; & objOperatingSystem.Version & VbCrLf & _
&quot;Service Pack: &quot; & _
objOperatingSystem.ServicePackMajorVersion & _
&quot;.&quot; & objOperatingSystem.ServicePackMinorVersion & VbCrLf & _
&quot;Windows Directory: &quot; & objOperatingSystem.WindowsDirectory & VbCrLf
intOSType = objOperatingSystem.OSType
strOSVer = Left(objOperatingSystem.Version, 3)
Next

Select Case intOSType
Case 16 'Windows 95
intOSVer = 1
Case 17 'Windows 98
intOSVer = 2
' Note: Windows Millennium is not included as an OSType by WMI.
Case 18
Select Case strOSVer
Case 4.0
intOSVer = 4 'Windows NT 4.0
Case 5.0
intOSVer = 5 'Windows 2000
Case 5.1
intOSVer = 6 'Windows XP
Case 5.2
intOSVer = 7 'Windows Server 2003
Case Else
intOSVer = 0 'Older or newer version
End Select
Case Else
intOSVer = 0 'Older or newer version
End Select

GetOSVer = intOSVer

End Function

'******************************************************************************
'* Display WSH information.
'******************************************************************************

Function GetWSHVer(intOSVer, strWshHost)

Wscript.Echo &quot;Windows Script Host&quot; & vbCrLf & _
&quot;===================&quot;

If Not strWshHost = &quot;&quot; Then
strVersion = WScript.Version
strBuild = WScript.BuildVersion
Wscript.Echo _
&quot;WSH Default Script Host: &quot; & strWshHost & VbCrLf & _
&quot;WSH Path: &quot; & WScript.FullName & VbCrLf & _
&quot;WSH Version & Build: &quot; & strVersion & &quot;.&quot; & strBuild & VbCrLf
Else
Wscript.Echo &quot;WSH information cannot be retrieved.&quot;
End If

sngWSHVer = CSng(strVersion)
intBuild = CInt(strBuild)

If (sngWSHVer >= 5.6 And intBuild >= 8515) Then
GetWSHVer = True
Else
GetWSHVer = False
End If

End Function

'******************************************************************************
'* Display WMI information.
'******************************************************************************

Function GetWMIVer(intOSVer)

dblBuildVersion = 0

If (intOSVer >= 1 And intOSVer <= 5) Then
strWmiVer = &quot;1.5&quot;
ElseIf intOSVer = 6 Then
strWmiVer = &quot;5.1&quot;
ElseIf intOSVer = 7 Then
strWmiVer = &quot;5.2&quot;
Else
strWmiVer = &quot;?.?&quot;
End If

Set colWMISettings = objWMIService.ExecQuery _
(&quot;Select * from Win32_WMISetting&quot;)

For Each objWMISetting In colWMISettings
Wscript.Echo &quot;Windows Management Instrumentation&quot; & vbCrLf & _
&quot;==================================&quot; & vbCrLf & _
&quot;WMI Version & Build: &quot; & _
strWmiVer & &quot;.&quot; & objWMISetting.BuildVersion & vbCrLf & _
&quot;Default scripting namespace: &quot; & _
objWMISetting.ASPScriptDefaultNamespace & vbCrLf
dblBuildVersion = CDbl(objWMISetting.BuildVersion)
Next

If (intOSVer = 7 And dblBuildVersion >= 3790.0000) Or _
(intOSVer = 6 And dblBuildVersion >= 2600.0000) Or _
(intOSVer <= 5 And dblBuildVersion >= 1085.0005) _
Then
GetWMIVer = True
Else
GetWMIVer = False
End If

End Function

'******************************************************************************
'* Display ADSI provider and version information.
'******************************************************************************

Function GetADSIVer(intOSVer)

Wscript.Echo &quot;Active Directory Service Interfaces&quot; & VbCrLf & _
&quot;===================================&quot; & vbCrLf

Set objShell = CreateObject(&quot;WScript.Shell&quot;)
strAdsiVer = _
objShell.RegRead(&quot;HKLM\SOFTWARE\Microsoft\Active Setup\Installed &quot; & _
&quot;Components\{E92B03AB-B707-11d2-9CBD-0000F87A369E}\Version&quot;)

If strAdsiVer = vbEmpty Then
strAdsiVer = _
objShell.RegRead(&quot;HKLM\SOFTWARE\Microsoft\ADs\Providers\LDAP&quot;)
If strAdsiVer = vbEmpty Then
strAdsiVer = &quot;ADSI is not installed.&quot;
Else
strAdsiVer = &quot;2.0&quot;
End If
ElseIf Left(strAdsiVer, 3) = &quot;5,0&quot; Then
If intOSVer = 5 Then
strAdsiVer = &quot;5.0.2195&quot;
ElseIf intOSVer = 6 Then
strAdsiVer = &quot;5.1.2600&quot;
ElseIf intOSVer = 7 Then
strAdsiVer = &quot;5.2.3790&quot;
Else
strAdsiVer = &quot;?.?&quot;
End If
End If

WScript.Echo &quot;ADSI Version & Build: &quot; & strAdsiVer & VbCrLf

If strAdsiVer <> &quot;ADSI is not installed.&quot; Then
Set colProvider = GetObject(&quot;ADs:&quot;)
Wscript.Echo &quot;ADSI Providers&quot; & VbCrLf & _
&quot;--------------&quot;
For Each objProvider In colProvider
Wscript.Echo objProvider.Name
Next
Wscript.Echo
End If

intAdsiVer = CInt(Left(strAdsiVer, 1))

If (intOSVer = 7 And intAdsiVer >= 5) Or _
(intOSVer = 6 And intAdsiVer >= 5) Or _
(intOSVer = 5 And intAdsiVer >= 5) Or _
(intOSVer = 4 And intAdsiVer >= 2) Or _
(intOSVer <= 3 And intAdsiVer >= 2) _
Then
GetADSIVer = True
Else
GetADSIVer = False
End If

End Function

'******************************************************************************
'* Test for current versions and display results.
'******************************************************************************

Sub ListUpToDate(blnWSHUpToDate, blnWMIUpToDate, blnADSIUpToDate)

Wscript.Echo &quot;Current Versions&quot; & vbCrLf & _
&quot;================&quot;

If blnWSHUpToDate Then
WScript.Echo &quot;WSH version: most recent for OS version.&quot;
Else
WScript.Echo &quot;WSH version: not most recent for OS version.&quot;
If intOSVer = 0 Then
WScript.Echo &quot;Windows Script not available for this OS&quot;
Else
WScript.Echo &quot;Get Windows Script 5.6, Build 8515&quot;
End If
End If

If blnWMIUpToDate Then
WScript.Echo &quot;WMI version: most recent for OS version.&quot;
Else
WScript.Echo &quot;WMI version: not most recent for OS version.&quot;
If intOSVer = 0 Then
WScript.Echo &quot;WMI not available for this OS&quot;
ElseIf intOSVer >= 1 And intOSVer <= 4 Then
WScript.Echo &quot;Get WMI CORE 1.5&quot;
Else
End If
End If

If blnADSIUpToDate Then
WScript.Echo &quot;ADSI version: most recent for OS version.&quot;
Else
WScript.Echo &quot;ADSI version: not most recent for OS version.&quot;
If intOSVer = 0 Then
WScript.Echo &quot;ADSI not available for this OS&quot;
ElseIf intOSVer >= 1 And intOSVer <= 4 Then
WScript.Echo &quot;Get Active Directory Client Extensions&quot;
Else
End If
End If

End Sub

===========================================================
nice little script from m$ to find the patch levels of different things.
just grep thru it for what u need

job sheduling is done thru .job files in the %windir%\tasks directory. You can copy them from a network share but they won't keep any account name and password saved.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top