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.
0 Comments   [ + ] Show Comments

Comments

Please log in to comment

Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.

Answers

0
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.
Answered 03/05/2009 by: VBScab
Red Belt

Please log in to comment
0
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:

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.
Answered 03/05/2009 by: MRaybone
Senior Yellow Belt

Please log in to comment
0
Spot on guys!

It worked!!!

Thanks again for your help!

Stephane
Answered 03/05/2009 by: Fau
Senior Purple Belt

Please log in to comment
Answer this question or Comment on this question for clarity