Video Screencast Help
Symantec Appoints Michael A. Brown CEO. Learn more.

Getting the results from a WMI call to use in WiseScript

Created: 26 Aug 2010 | 6 comments

I am trying to use WMI to determine if a package can be run on a computer. I'm not sure how to start with this. I know that i will need the WMI to set a variable and from that i can have wisescript run or not run.

This is the WMI that i have started.

For Each objItem in colItems
    Wscript.Echo objItem.DriverVersion
NextstrComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
Set colItems = objWMIService.ExecQuery( _
    "SELECT * FROM Win32_VideoController",,48)

how would i get this to output to a variable?

Comments 6 CommentsJump to latest comment

EdT's picture

Is your wisescript going to be used as a custom action in an MSI, or are you working entirely with Wisescript as your installation language. Or are you just using wisescript for control purposes?
Also, which version of which Wise tool do you have?
A more extensive description of what you are trying to achieve would also be helpful.

In general though, I would recommend using the WMI script to get a final result of whatever "test" you are carrying out, then write this to a registry key or a temp file. The wisescript can then retrieve this registry key or temp file information and continue on with the rest of the logic.

If your issue has been solved, please use the "Mark as Solution" link on the most relevant thread.

rugsyj's picture

I plan on working entirely with Wisescript. The version that we have is the latest 8.0

We have a video driver update that we need to publish to our software library. The WMI that i have is a call to see what version of the driver that they have. and depending and if they don't have the latest then they can run the file. 

The part about using the WMI script to get the final result and writing it to a file might be a good idea, but not as clean as i want it. Let me know what other ideas you have. I am also going to look at the comments that the other person had. 

EdT's picture

I would normally expect the registry to contain information about any driver on the system, so perhaps your optimum solution, if your current installation does not already record the driver version in the registry, is to define a location where this information will be stored in future releases.
Then author your WMI code to read the current driver version and save it to the defined location in the registry. The installer for your updated driver can then deploy the latest files, and update the defined location in the registry with the newest version information.
Thereafter, you won't need to use WMI for future upgrades, as the information will be readable from the registry.
Actually, do you need to use WMI at all?
Wisescript's Get System Information command allows you to retrieve the file version information of a specified file.
If your existing driver has a file version defined within, then you can retrieve it directly with Wisescript and base your install logic on the version returned.

If your issue has been solved, please use the "Mark as Solution" link on the most relevant thread.

VBScab's picture

...if a) the code was WiseScript (it's VBScript) and b) it were correct. It references an object before it's been created. Try:
[code]
Option Explicit
'// ALWAYS declare your variables: the line above forces that
Dim strComputer
Dim objWMIService
Dim colItems
Dim objItem

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
If Not IsObject(objWMIService) Then
   '// ALWAYS trap for errors - assume that nothing will work, even the basics

   '// Show some sort of error message
   '// Exit the script or sub/function here
End If

Set colItems = objWMIService.ExecQuery( "SELECT * FROM Win32_VideoController",,48)
If Not IsObject(colItems) Then
   '// Show some sort of error message
   '// Exit the script or sub/function here
End If

For Each objItem in colItems
    If Not IsObject(colItems) Then
       '// Show some sort of error message
       '// Exit the script or sub/function here
    End If

    '// If your aim is to get data into anMSI, then use Session.Property:
    '// Wscript.Echo objItem.DriverVersion
    Session.Property("DRIVER_VERSION") = objItem.DriverVersion
Next

Set objWMIService = Nothing
Set colItems = Nothing

[/code]

Don't know why 'x' happened? Want to know why 'y' happened? Use ProcMon and it will tell you.
Think about using http://www.google.com before posting.