Alternate choice for LIKE on Windows 2000?
Hey guys,
Ok, here's a line of code (Vbscript) that works fine on Windows XP, but on Windows 2000 gives a charming error #80041017 which is probably related to the use of LIKE which from what I read, was introduced in Windows XP.
Set colFolders = objWMIService.ExecQuery _
("Select * from Win32_Directory where Name Like '%network\\admin%' and Drive = 'C:'")
How could I rewrite this to have it working for 2000?
Thanks for your help!
Stephane
PS: If you need the whole code, just tell me, it's 10-15 lines long.
Ok, here's a line of code (Vbscript) that works fine on Windows XP, but on Windows 2000 gives a charming error #80041017 which is probably related to the use of LIKE which from what I read, was introduced in Windows XP.
Set colFolders = objWMIService.ExecQuery _
("Select * from Win32_Directory where Name Like '%network\\admin%' and Drive = 'C:'")
How could I rewrite this to have it working for 2000?
Thanks for your help!
Stephane
PS: If you need the whole code, just tell me, it's 10-15 lines long.
0 Comments
[ + ] Show comments
Answers (3)
Please log in to answer
Posted by:
anonymous_9363
15 years ago
How could I rewrite this to have it working for 2000?You could use the right tool to begin with, Stephane! :)
There are innumerable examples of recursive folder searching on the web using the FileSystemObject object. Here's one http://groups.google.com/group/microsoft.public.scripting.vbscript/browse_thread/thread/6c989ba336722877 (see Bruce M. Axten's post). The variable-naming is suspect but at least it works. Add some proper error-trapping, too.
EDIT:
Another http://psacake.com/web/func/dirsrch_object.htm
You'll need to remove the ASP stuff (%< and >%) but other than that, it's ready to go.
Posted by:
MRaybone
15 years ago
Stephane, below are 2 code examples. The 1st is for Windows XP/2003 using 'LIKE', the 2nd is what I had to use to get the same result under Windows 2000:
Not that it matters, but the code example here is from a piece which checks for the presence of particular hotfixes.
You're basically using the instr() function to check each item of your entire list of potential results, instead of using 'LIKE' to select the results directly.
Hope this helps!
MRaybone.
WINXP/2003:
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colQuickFixes = objWMIService.ExecQuery("Select * from Win32_QuickFixEngineering WHERE HotFixID LIKE '%" & strHotFixID & "%'")
For Each objQuickFix in colQuickFixes
Install_Flag = True
Next
WIN2000:
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colQuickFixes = objWMIService.ExecQuery("Select * from Win32_QuickFixEngineering")
For Each objQuickFix in colQuickFixes
If instr(ucase(objQuickFix.HotFixID), strHotFixID) > 0 then
Install_Flag = True
End If
Next
Not that it matters, but the code example here is from a piece which checks for the presence of particular hotfixes.
You're basically using the instr() function to check each item of your entire list of potential results, instead of using 'LIKE' to select the results directly.
Hope this helps!
MRaybone.
Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.
so that the conversation will remain readable.