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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with CIM_Datafile query

Status
Not open for further replies.

mefanning

MIS
Apr 26, 2010
19
US
I'm putting a script together to query the flash install directory and log any ocx file and its file type.

When I execute it I get an error:

flash.vbs(12, 1) (null): 0x80041017

Any help is appreciated.

Const ForAppending = 8
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objLogFile = objFSO.OpenTextFile("c:\Temp\Flash.csv", _
ForAppending, True)
Set WshShell = CreateObject("Wscript.Shell")

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colFiles = objWMIService.ExecQuery _
("SELECT * FROM CIM_Datafile where extension = 'ocx' and path = 'C:\Windows\System32\Macromed\Flash'")
For Each objFile in colFiles
objLogFile.Write objFile.FileName & ","
objLogFile.Write objFile.Version & "," & vbCrLf
Next

 
Fixed it. If anyone is curious.



Const ForAppending = 8
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objLogFile = objFSO.OpenTextFile("c:\Temp\Flash.csv", _
ForAppending, True)
Set WshShell = CreateObject("Wscript.Shell")

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colFiles = objWMIService.ExecQuery _
("ASSOCIATORS OF {Win32_Directory.Name='C:\Windows\SysWOW64\Macromed\Flash'} Where " _
& "ResultClass = CIM_DataFile")
'("SELECT * FROM CIM_Datafile where extension = 'ocx' and path = 'C:\Windows\SysWOW64\Macromed\Flash'")

For Each objFile in colFiles
If objFile.Extension = "ocx" Then
objLogFile.Write objFile.FileName & ","
objLogFile.Write objFile.Version & "," & vbCrLf
End If
Next

 
OK another question on this script. When I use the full path C:\Windows\SysWOW64\Macromed\Flash, my script works. But when I sub in variables, it fails again with the null message:

Const ForAppending = 8
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objLogFile = objFSO.OpenTextFile("c:\Temp\Flash.csv", _
ForAppending, True)
Set WshShell = CreateObject("Wscript.Shell")

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

'x64 Query

strWinDir = WshShell.ExpandEnvironmentStrings("%WinDir%")
strSysWOW64 = strWinDir & "\SysWOW64\Macromed\Flash"
wscript.echo strSysWOW64

Set colFiles = objWMIService.ExecQuery _
'Old Code that works ("ASSOCIATORS OF {Win32_Directory.Name='C:\Windows\SysWOW64\Macromed\Flash'} Where " _ ---New Code giving error is below:
("ASSOCIATORS OF {Win32_Directory.Name= '" & strSysWOW64 & "'} Where " _
& "ResultClass = CIM_DataFile")

For Each objFile in colFiles
If objFile.Extension = "ocx" Then
objLogFile.Write objFile.FileName & ","
objLogFile.Write objFile.Version & "," & vbCrLf
End If
Next
 
Code:
Set colFiles = objWMIService.ExecQuery _
[red]'Old Code that works ("ASSOCIATORS OF {Win32_Directory.Name='C:\Windows\SysWOW64\Macromed\Flash'} Where " _ ---New Code giving error is below: [/red]
 ("ASSOCIATORS OF {Win32_Directory.Name= '" & strSysWOW64 & "'} Where " _
   & "ResultClass = CIM_DataFile")

Could the fact that you're [red]cutting the command in half[/red] have anything to do with it...just a thought...And also, why not make it one line?

Code:
Set colFiles = objWMIService.ExecQuery("ASSOCIATORS OF {Win32_Directory.Name= '" & strSysWOW64 & "'} Where " & "ResultClass = CIM_DataFile")

-Geates

"I hope I can feel and see the change - stop the bleed inside a feel again. Cut the chain of lies you've been feeding my veins; I've got nothing to say to you!"
-Infected Mushroom

"I do not offer answers, only considerations."
- Geates's Disclaimer
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top