notta Posted June 30, 2008 Posted June 30, 2008 This is a partial of a script I'm working on. This works perfectly on Windows XP, but 2000 is not getting inside the for loop. I get msgbox 2,3, but no matter what I try I cannot get msgbox 4 to pop. I checked MDSN and it shows that this should work with Windows 2000. Is there something I'm missing here? Thanks. $computername = stringlower(@ComputerName) $strAppName = "Symantec" msgbox(0,"","2") $objWMIService = ObjGet("winmgmts:\\" & $computername & "\root\CIMV2") $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_Product WHERE Name LIKE '%" & $strAppName & "%'", "WQL", _ $wbemFlagReturnImmediately + $wbemFlagForwardOnly) msgbox(0,"","3") For $objItem In $colItems MsgBox(0,"","4") MsgBox(0,"",$objItem.Name) Next
Artisan Posted July 1, 2008 Posted July 1, 2008 What's the value of $wbemFlagReturnImmediately + $wbemFlagForwardOnly? Or what would I need to #include to test this? I've got Windows 2000, but it complains that those 2 variabels aren't defined...
notta Posted July 1, 2008 Author Posted July 1, 2008 (edited) Thanks for the comment. Add this: $wbemFlagReturnImmediately = 0x10 $wbemFlagForwardOnly = 0x20 The upsetting thing about this is that I made some major changes over the past few weekends to my script for work. Tonight I thought I was done, but when I went to do my testing I'm finding a lot of WMI calls are not working like I thought they would on 2k. I didn't see anything documented on MSDN that what I posted will not work on 2k. If this doesn't work then I have to find all the reg values for about 4-5 different values of SAV and check for them explicitly. If that's the case that will suck big time. Edited July 1, 2008 by notta
Artisan Posted July 1, 2008 Posted July 1, 2008 (edited) It's too late for me to bug MSDN, and I'm not familiar with ExecQuery or CIMV2. That said, I'm not getting box 4 either. I'm running Windows 200 SP3 if that's of any use. (SP4 caused nothing but trouble for me...) Guess I'm not going to be of much assistance tonight, sorry. Edited July 1, 2008 by Artisan
GEOSoft Posted July 1, 2008 Posted July 1, 2008 (edited) You can not use a LIKE query in Win 2000 when working with services. Change "Like" to "=" Edit: I already have a servives UDF posted on my site which has the same issue. I just have not gotten around to fixing it yet. Edited July 1, 2008 by GEOSoft George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!"
notta Posted July 1, 2008 Author Posted July 1, 2008 (edited) You can not use a LIKE query in Win 2000 when working with services. Change "Like" to "=" Edit: I already have a servives UDF posted on my site which has the same issue. I just have not gotten around to fixing it yet. Thanks Geo. Yea I posted in the vbscript newsgroups and someone replied stating that "LIKE" was not a valid clause in 2000. I was thinking of a longer way to fix this, but you saved me a ton of time. Just in case anyone has the same problem the correct syntax is: $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_Product WHERE Name = '" & $strAppName & "'", "WQL", _ $wbemFlagReturnImmediately + $wbemFlagForwardOnly) Note the removal of the percent signs. I have not checked the times on the searches, but I would imagine using Like clause is quicker. So would you use the first statement for XP and the second one for 2000 If @OSVersion == "WIN_XP" Then $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_Product WHERE Name LIKE '%" & $strAppName & "%'", "WQL", _ $wbemFlagReturnImmediately + $wbemFlagForwardOnly) ElseIf @OSVersion == "WIN_2000" Then $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_Product WHERE Name = '" & $strAppName & "'", "WQL", _ $wbemFlagReturnImmediately + $wbemFlagForwardOnly) EndIf or just use the name = for all versions? What's your thoughts? Edited July 1, 2008 by notta
GEOSoft Posted July 2, 2008 Posted July 2, 2008 Thanks Geo. Yea I posted in the vbscript newsgroups and someone replied stating that "LIKE" was not a valid clause in 2000. I was thinking of a longer way to fix this, but you saved me a ton of time. Just in case anyone has the same problem the correct syntax is: $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_Product WHERE Name = '" & $strAppName & "'", "WQL", _ $wbemFlagReturnImmediately + $wbemFlagForwardOnly) Note the removal of the percent signs. I have not checked the times on the searches, but I would imagine using Like clause is quicker. So would you use the first statement for XP and the second one for 2000 If @OSVersion == "WIN_XP" Then $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_Product WHERE Name LIKE '%" & $strAppName & "%'", "WQL", _ $wbemFlagReturnImmediately + $wbemFlagForwardOnly) ElseIf @OSVersion == "WIN_2000" Then $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_Product WHERE Name = '" & $strAppName & "'", "WQL", _ $wbemFlagReturnImmediately + $wbemFlagForwardOnly) EndIf or just use the name = for all versions? What's your thoughts?With windows services you won't see much of a difference either way. The list of services is just not big enough for time to become a factor. I would just stay with "=" George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!"
notta Posted July 9, 2008 Author Posted July 9, 2008 Well Geo, I moved on thinking all was good, but I ran into a new snag. Some of the versions floating around here have different DisplayName values. Example 'Symantec Antivirus' and 'Symantec Antvirus Client' Without the LIKE clause I have to be exact on the name or it will not match. Can you fit a wildcard in this statment somehow? $strAppName = "Symantec Antivirus" $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_Product WHERE Name = '" & $strAppName* & "'", "WQL", _ $wbemFlagReturnImmediately + $wbemFlagForwardOnly) I know that it completely wrong, but I'm just trying show my point. Thanks.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now