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

Make a WMI query return a single valuees existince or not?

Status
Not open for further replies.
Feb 11, 2005
153
US
Okay I don't get this - I am playing around with this WMI querying as I have only done VERY small simple single queries. I usually do like the below and then find the item I need and modify it and not worry about the other values. This time however I need it to report back if this value is there or not. I am not sure how to get this to not do this for each patch -

Code:
Set colHotfix = objWMIService.ExecQuery _
("Select * from Win32_QuickFixEngineering")

For Each objHotfix in colHotfix

If (objHotfix.ServicePackInEffect) = "KB928388" then
msg = "Hotfix Installed"
msgbox msg
Else
msg = "Hotfix Not Installed"
msgbox msg
End if

The problem is the Query returning all hotfixes and doing the for each statement applies it to each hotfix when this machine and most of them have a ton. My question is how do I modify this portion of the script to return only 1 single KB I am looking for?

I thought I could modify the query. I tried to do something like -

Code:
Set colHotfix = objWMIService.ExecQuery _
("Select ServicePackInEffect from Win32_QuickFixEngineering WHERE ServicePackInEffect = KB928388")

For Each objHotfix in colHotfix

If (objHotfix.ServicePackInEffect) = "KB928388" then
msg = "Hotfix Installed"
msgbox msg
Else
msg = "Hotfix Not Installed"
msgbox msg
End if

But this failed miserably. I don't think I know enough about the Select * line to be able to make a decient query if in fact this is even able to be modified.

Basically instead of having ALL of the items Win32_QuickFixEngineering returned I need a Single item to be verified. And then reported on if its there or not.

Maybe I need to change For Each objHotfix in colHotfix
to For Each (objHotfix.ServicePackInEffect) = "KB928388" in colHotfix?

If anyone can point me to this I know I am ALMOST there I just can't quite see the forest for the trees.
 
Try this:
Code:
Set colHotfix = objWMIService.ExecQuery _
("Select HotFixID from Win32_QuickFixEngineering Where HotFixID = 'KB928388'")

For Each objHotfix in colHotfix
	If objHotfix.HotFixID = "KB928388" Then
		msg = "Hotfix Installed"
		MsgBox msg
	Else
		msg = "Hotfix Not Installed"
		msgbox msg
	End If
Next

--------------------------------------------------------------------------------
dm4ever
My philosophy: K.I.S.S - Keep It Simple Stupid
 
Yeah that makes sense.... Have you ever used WMI explorer?

I use that to see which WMI values are for each Win32_ option out there (cause theres a ton). The nice thing is it shows me the values even on remote PC's so I can best judge their results. Also VERY nice as it has no install its just a standalone exe.

The problem is it is showing ServicePackInEffect with the KB indicator not the HotFixID. That HotfixID just shows File 1 as the value :/

Hrm possibly something wrong with the program?

The other thing I noted is you added single quotes into the query. I wonder if it just was the fact I didn't have the single quotes in there?

I guess I am just wanting to ensure you can do more than just a simple ("Select * from Win32_XXXXXXX). I'll play with it a little more tomorrow I was getting frustrated with the code this afternoon.

 
I have used WMI Explorer and WBEMTEST. They are useful tools to use in conjunction to Microsoft's Documentation. There is nothing wrong with the program. What you where looking at was probably something like this:
Win32_QuickFixEngineering.HotFixID="File 1",ServicePackInEffect="KB928388"
which is the specific instance for that hotfix.

--------------------------------------------------------------------------------
dm4ever
My philosophy: K.I.S.S - Keep It Simple Stupid
 
Nice, thank you it actually was syntax that made it not work.

The line that works is -


("Select ServicePackInEffect from Win32_QuickFixEngineering Where ServicePackInEffect = 'KB928388'")

Now I think I have another problem

It is not processing the -

Else
msg = "Hotfix Not Installed"
msgbox msg
End if

- When this script is ran on an SP2 machine without the patch.

I think that the query is ONLY hitting a single Hotfix and if the query does not see it it is not returning any result at all. This non result I think is making it so the - For Each objHotfix in colHotfix - line can't do what it needs because of lack of data? Does this sound feasible? How would I circumvent this?

I did try and "tweak the if statement a little?

Even with changing the If statement to an if not its still stopping at this point.

I thought about pssibly an Exit for but I don't see how that will do anything because I am convinced now the query not returning anything on a machine that does not have the patch is the issue.

Is there any way to make it so if the query is empty then to process something different?
 
NM - I found the answer I had to check the count on the colHotfix.

The final code that works is -

Code:
Set colHotfix = objWMIService.ExecQuery _
("Select ServicePackInEffect from Win32_QuickFixEngineering Where ServicePackInEffect = 'KB928388'")                  
If colHotfix.Count = 0 Then                         
msg = "Hotfix Not Installed"
msgbox msg                                      
Else
For Each objHotfix in colHotfix
If (objHotfix.ServicePackInEffect) = "KB928388" then
msg = "Hotfix Installed"
msgbox msg
End If
Next
End If

Thank you for all your help and explinations.
 
Great! I was actually going to suggest that since I recently provided that info to someone else on another forum for something similar ( [smile]

--------------------------------------------------------------------------------
dm4ever
My philosophy: K.I.S.S - Keep It Simple Stupid
 
Hello,

I have read your post...

I found out that it works only for Windows Hotfixes, and not for Office Hotfixes...

Do you have any idea??

Thanks..

Adrian
 
That is correct, it will not return Office hotfixes.

MS Documentation: Updates or hotfixes supplied by Windows Installer (MSI) or the Windows update site ( are not returned by Win32_QuickFixEngineering.

I have a script that looks in the registry for any software installed with KBXXXXXX in the display name if you think that may help you with what you're trying to accomplish.

--------------------------------------------------------------------------------
dm4ever
My philosophy: K.I.S.S - Keep It Simple Stupid
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top