db
2007-02-28 16:28:53 UTC
I'm having some trouble getting queries to work. I'm experimenting with some
of the scripts that come with ScriptomaticV2 by adding a WHERE clause. The
queries work just fine without the clause but when I add the clause it fails
every time - even for things the first query found.
Example.
The Win32_ShortcutFile script returns info on shortcuts including a Name
field. When I add a WHERE clause for the name of one of the shortcuts it
finds, I get 0x80041017. (Comment out the 'On Error Resume Next')
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_ShortcutFile " _
& "WHERE Name = """ & tstName & """", "WQL")
Where tstName is the value of the Name field of one of the objects returned
in the original script.
I tried with single quotes and double double quotes.
I tried with 0, 16, 32, and 48 as the flag value.
The original script is
On Error Resume Next
Const wbemFlagReturnImmediately = &h10
Const wbemFlagForwardOnly = &h20
arrComputers = Array("xp_box")
For Each strComputer In arrComputers
WScript.Echo
WScript.Echo "=========================================="
WScript.Echo "Computer: " & strComputer
WScript.Echo "=========================================="
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
Set colItems = objWMIService.ExecQuery("SELECT * FROM
Win32_ShortcutFile", "WQL", _
wbemFlagReturnImmediately +
wbemFlagForwardOnly)
For Each objItem In colItems
WScript.Echo "AccessMask: " & objItem.AccessMask
WScript.Echo "Archive: " & objItem.Archive
WScript.Echo "Caption: " & objItem.Caption
WScript.Echo "Compressed: " & objItem.Compressed
WScript.Echo "CompressionMethod: " & objItem.CompressionMethod
WScript.Echo "CreationClassName: " & objItem.CreationClassName
WScript.Echo "CreationDate: " &
WMIDateStringToDate(objItem.CreationDate)
WScript.Echo "CSCreationClassName: " & objItem.CSCreationClassName
WScript.Echo "CSName: " & objItem.CSName
WScript.Echo "Description: " & objItem.Description
WScript.Echo "Drive: " & objItem.Drive
WScript.Echo "EightDotThreeFileName: " & objItem.EightDotThreeFileName
WScript.Echo "Encrypted: " & objItem.Encrypted
WScript.Echo "EncryptionMethod: " & objItem.EncryptionMethod
WScript.Echo "Extension: " & objItem.Extension
WScript.Echo "FileName: " & objItem.FileName
WScript.Echo "FileSize: " & objItem.FileSize
WScript.Echo "FileType: " & objItem.FileType
WScript.Echo "FSCreationClassName: " & objItem.FSCreationClassName
WScript.Echo "FSName: " & objItem.FSName
WScript.Echo "Hidden: " & objItem.Hidden
WScript.Echo "InstallDate: " & WMIDateStringToDate(objItem.InstallDate)
WScript.Echo "InUseCount: " & objItem.InUseCount
WScript.Echo "LastAccessed: " &
WMIDateStringToDate(objItem.LastAccessed)
WScript.Echo "LastModified: " &
WMIDateStringToDate(objItem.LastModified)
WScript.Echo "Manufacturer: " & objItem.Manufacturer
WScript.Echo "Name: " & objItem.Name
WScript.Echo "Path: " & objItem.Path
WScript.Echo "Readable: " & objItem.Readable
WScript.Echo "Status: " & objItem.Status
WScript.Echo "System: " & objItem.System
WScript.Echo "Target: " & objItem.Target
WScript.Echo "Version: " & objItem.Version
WScript.Echo "Writeable: " & objItem.Writeable
WScript.Echo
Next
Next
Function WMIDateStringToDate(dtmDate)
WScript.Echo dtm:
WMIDateStringToDate = CDate(Mid(dtmDate, 5, 2) & "/" & _
Mid(dtmDate, 7, 2) & "/" & Left(dtmDate, 4) _
& " " & Mid (dtmDate, 9, 2) & ":" & Mid(dtmDate, 11, 2) & ":" &
Mid(dtmDate,13, 2))
End Function
of the scripts that come with ScriptomaticV2 by adding a WHERE clause. The
queries work just fine without the clause but when I add the clause it fails
every time - even for things the first query found.
Example.
The Win32_ShortcutFile script returns info on shortcuts including a Name
field. When I add a WHERE clause for the name of one of the shortcuts it
finds, I get 0x80041017. (Comment out the 'On Error Resume Next')
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_ShortcutFile " _
& "WHERE Name = """ & tstName & """", "WQL")
Where tstName is the value of the Name field of one of the objects returned
in the original script.
I tried with single quotes and double double quotes.
I tried with 0, 16, 32, and 48 as the flag value.
The original script is
On Error Resume Next
Const wbemFlagReturnImmediately = &h10
Const wbemFlagForwardOnly = &h20
arrComputers = Array("xp_box")
For Each strComputer In arrComputers
WScript.Echo
WScript.Echo "=========================================="
WScript.Echo "Computer: " & strComputer
WScript.Echo "=========================================="
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
Set colItems = objWMIService.ExecQuery("SELECT * FROM
Win32_ShortcutFile", "WQL", _
wbemFlagReturnImmediately +
wbemFlagForwardOnly)
For Each objItem In colItems
WScript.Echo "AccessMask: " & objItem.AccessMask
WScript.Echo "Archive: " & objItem.Archive
WScript.Echo "Caption: " & objItem.Caption
WScript.Echo "Compressed: " & objItem.Compressed
WScript.Echo "CompressionMethod: " & objItem.CompressionMethod
WScript.Echo "CreationClassName: " & objItem.CreationClassName
WScript.Echo "CreationDate: " &
WMIDateStringToDate(objItem.CreationDate)
WScript.Echo "CSCreationClassName: " & objItem.CSCreationClassName
WScript.Echo "CSName: " & objItem.CSName
WScript.Echo "Description: " & objItem.Description
WScript.Echo "Drive: " & objItem.Drive
WScript.Echo "EightDotThreeFileName: " & objItem.EightDotThreeFileName
WScript.Echo "Encrypted: " & objItem.Encrypted
WScript.Echo "EncryptionMethod: " & objItem.EncryptionMethod
WScript.Echo "Extension: " & objItem.Extension
WScript.Echo "FileName: " & objItem.FileName
WScript.Echo "FileSize: " & objItem.FileSize
WScript.Echo "FileType: " & objItem.FileType
WScript.Echo "FSCreationClassName: " & objItem.FSCreationClassName
WScript.Echo "FSName: " & objItem.FSName
WScript.Echo "Hidden: " & objItem.Hidden
WScript.Echo "InstallDate: " & WMIDateStringToDate(objItem.InstallDate)
WScript.Echo "InUseCount: " & objItem.InUseCount
WScript.Echo "LastAccessed: " &
WMIDateStringToDate(objItem.LastAccessed)
WScript.Echo "LastModified: " &
WMIDateStringToDate(objItem.LastModified)
WScript.Echo "Manufacturer: " & objItem.Manufacturer
WScript.Echo "Name: " & objItem.Name
WScript.Echo "Path: " & objItem.Path
WScript.Echo "Readable: " & objItem.Readable
WScript.Echo "Status: " & objItem.Status
WScript.Echo "System: " & objItem.System
WScript.Echo "Target: " & objItem.Target
WScript.Echo "Version: " & objItem.Version
WScript.Echo "Writeable: " & objItem.Writeable
WScript.Echo
Next
Next
Function WMIDateStringToDate(dtmDate)
WScript.Echo dtm:
WMIDateStringToDate = CDate(Mid(dtmDate, 5, 2) & "/" & _
Mid(dtmDate, 7, 2) & "/" & Left(dtmDate, 4) _
& " " & Mid (dtmDate, 9, 2) & ":" & Mid(dtmDate, 11, 2) & ":" &
Mid(dtmDate,13, 2))
End Function