tags:

views:

15

answers:

2

Hello! I want to get list of installed windows hotfix and updates. I use script below:

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

Set colQuickFixes = objWMIService.ExecQuery _
("Select * from Win32_QuickFixEngineering")

Set objDateTime = CreateObject("WbemScripting.SWbemDateTime")

For Each objQuickFix in colQuickFixes
Wscript.Echo "Computer: " & objQuickFix.CSName
Wscript.Echo "Description: " & objQuickFix.Description
Wscript.Echo "Hot Fix ID: " & objQuickFix.HotFixID
If Not (IsNull(objQuickFix.InstallDate) Or _
IsEmpty(objQuickFix.InstallDate)) Then
objDateTime.Value = objQuickFix.InstallDate
Wscript.Echo "Installation Date: " & objDateTime.GetFileTime
Else
WScript.Echo "Install Date Type: " &
TypeName(objQuickFix.InstallDate)
End If
Wscript.Echo "Installed By: " & objQuickFix.InstalledBy
Next

When I run this script I get Error message:

Syntax error
Error Code 800A03EA

What's wrong in this piece of code? Thanks! Sorry if my English is not perfect.

A: 

You are missing the line continuation character (_) here:

''#                        -----------
''#                                  |
''#                                  \/

WScript.Echo "Install Date Type: " & _
TypeName(objQuickFix.InstallDate)

Either add it or put the code in a singe line:

WScript.Echo "Install Date Type: " & TypeName(objQuickFix.InstallDate)
Helen
A: 

Oh, it's stupid mistake.. Helen, thank you! I simplified this code:

Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
Set colQuickFixes = objWMIService.ExecQuery("Select * from Win32_QuickFixEngineering")
Set objDateTime = CreateObject("WbemScripting.SWbemDateTime")

For Each objQuickFix in colQuickFixes
    Wscript.Echo "Computer: " & objQuickFix.CSName
    Wscript.Echo "Description: " & objQuickFix.Description
    Wscript.Echo "Hot Fix ID: " & objQuickFix.HotFixID  
    objDateTime.Value = objQuickFix.InstalledOn
    Wscript.Echo "Installation Date: " & objDateTime.GetFileTime
    Wscript.Echo "Installed By: " & objQuickFix.InstalledBy
Next

And now I have error

Syntax Error
Error code: 80041021
Source: SWbemDateTime
Line: 10

I found in MSDN following text:

The format of strFileTime is not valid.

Maybe I have to convert objQuickFix.InstalledOn to other data type? Thanks

dvrs