Solved

Problems during WMI Win32_Directory query

Posted on 2010-09-16
10
1,888 Views
Last Modified: 2012-05-10
Hi !

I'm running into an error during WMI processing of the available folders on a drive of our servers to perform an inventory of the paths and the security that is present. We need this info for migration preparations.
Once I run my simple dir-processing code against fro example the c:\windows folder it reports the subfolders exacly as expected.
But once I change my query-parameters to "(drive = "f:" AND path LIKE "\\gebruikers\\groups\\%")" in order to get the folders from drive f: the script runs for a few seconds and then exists with error "The remote procedure call failed". I set the WMI logging to verbose and in the WMI-logging file it shows "Error 800706be occured executing request for select __RELPATH, drive, path, name, filename from Win32_Directory where (drive = "f:" AND path LIKE "\\gebruikers\\groups\\%")"

My current code to list the folders is:
'================================
Const forAppending = 8

Dim objFS, objLog, objLocator, objWMIService, colFolders, objFolder, strLine
Dim strLogstring
Set objFS = CreateObject("Scripting.FilesystemObject")
Set objLog = objFS.CreateTextFile(".\foldertree.log",true)
objLog.Close
Set objLog = Nothing

strComputer = "."
Set objLocator = CreateObject("WbemScripting.SWbemLocator")
Set objWMIService = objLocator.ConnectServer (strComputer, "root/cimv2")
    objWMIService.Security_.impersonationlevel = 3
    objWMIService.Security_.Privileges.AddAsString "SeSecurityPrivilege", True
    objWMIService.Security_.Privileges.AddAsString "SeBackupPrivilege", True

Set colFolders = objWMIService.ExecQuery("Select drive,path,name,filename from Win32_Directory where (drive='f:' and path like '\\gebruikers\\groups\\%')")
'wscript.echo "[" & colFolders.count & "] folders found in groups: now log folders ..."

For Each objFolder in colFolders
      strLine = objFolder.drive & objFolder.path & objFolder.filename
      wscript.echo strLine
      Call fWrite2Log(".\foldertree.log", strLine, forAppending)
Next

objLog.Close
Set objLog = Nothing
Set objFS = Nothing

Function fWrite2Log(strLogfile, strLogstring, iMode)
      Dim objTMP
      Set objTMP = objFS.openTextFile(strLogfile, iMode)
      objTMP.writeLine strLogstring
      objTMP.close
      Set objTMP = Nothing
End Function
'================================

The strange thing (for me) is that the folder where the script fails is never the same, so it seems like some buffer thing or so but I can't get my finger on it.

I hope someone can help me out here. I've read quite a lot on the web already but couldn't find a solution so far.

Best regards and many thanks in advance
Eric
0
Comment
Question by:evegter
  • 4
  • 3
  • 2
  • +1
10 Comments
 
LVL 10

Expert Comment

by:Alan_White
ID: 33693927
Is this link any use: http://blogs.technet.com/b/heyscriptingguy/archive/2006/09/19/how-can-i-locate-all-the-folders-that-have-archive-asn-in-the-path.aspx

It seems to imply you might need a % wildcard at the front too.

It also says the LIKE operator only works with XP/2003 and higher, what OS are you running?

Is this just one server you are trying to run against?
0
 
LVL 17

Accepted Solution

by:
Tony Massa earned 167 total points
ID: 33694185
I've used DumpSec in the past to get this info...it's probably an easier solution

http://www.systemtools.com/cgi-bin/download.pl?DumpAcl
0
 

Author Comment

by:evegter
ID: 33694500
Hi Alan,
thanks for your reply. The %-sign in front is not required here because the mentioned folder is the name of the folder that starts in the root of drive f:. The server OS is Windows 2003 32 bit with latest patches etc. The fact that the script runs correctly against the c:\windows folder means that the query-functionality is basically available on the server and should be able to retrieve another folder too.
The code in the link you sent is quite similar to what I'm doing. I probably got my initial code from a similar site anyway :). I extended my query with the drive='f:' and specific properties just to speed up the query-process based on MS guidelines to optimize queries. Without the drive='f:' parameter the query simply takes much longer and finally also crashes the same way.

I must admit that I didn't tried the script on another server; that means I tested it on my own W7 pc and some virtual servers I run on my laptop and that ran fine. I didn't try another production server then, but I just ran the scrtip agains another server and that seems to run just fine. Another server I just tried too is Windows 2000 and fails because of that I believe.

I might have to try a few other source servers that are Windows 2003 and see if I can reproduce the error. Then maybe repair WMI on the server that fails now..

Any more ideas?

Tx
Eric
0
 
LVL 65

Expert Comment

by:RobSampson
ID: 33697322
Hi, it seems to work for me....if you run this code, it will direct output to a command prompt.  Can you see where it gets up to during it's iteration?  And let us know what line the error is on?

Regards,

Rob.
If LCase(Right(Wscript.FullName, 11)) = "wscript.exe" Then

    strPath = Wscript.ScriptFullName

    strCommand = "%comspec% /k cscript  """ & strPath & """"

    Set objShell = CreateObject("Wscript.Shell")

    objShell.Run(strCommand), 1, True

    Wscript.Quit

End If



Const forAppending = 8



Dim objFS, objLog, objLocator, objWMIService, colFolders, objFolder, strLine

Dim strLogstring

Set objFS = CreateObject("Scripting.FilesystemObject")

Set objLog = objFS.CreateTextFile(".\foldertree.log",true)

objLog.Close

Set objLog = Nothing



strComputer = "."

Set objLocator = CreateObject("WbemScripting.SWbemLocator")

Set objWMIService = objLocator.ConnectServer (strComputer, "root/cimv2")

    objWMIService.Security_.impersonationlevel = 3

    objWMIService.Security_.Privileges.AddAsString "SeSecurityPrivilege", True

    objWMIService.Security_.Privileges.AddAsString "SeBackupPrivilege", True



Set colFolders = objWMIService.ExecQuery("Select drive,path,name,filename from Win32_Directory where (drive='c:' and path like '\\gebruikers\\groups\\%')")

'wscript.echo "[" & colFolders.count & "] folders found in groups: now log folders ..."



For Each objFolder in colFolders

      strLine = objFolder.drive & objFolder.path & objFolder.filename

      wscript.echo strLine

      Call fWrite2Log(".\foldertree.log", strLine, forAppending)

Next



objLog.Close

Set objLog = Nothing

Set objFS = Nothing



Function fWrite2Log(strLogfile, strLogstring, iMode)

      Dim objTMP

      Set objTMP = objFS.openTextFile(strLogfile, iMode)

      objTMP.writeLine strLogstring

      objTMP.close

      Set objTMP = Nothing

End Function

Open in new window

0
 
LVL 10

Assisted Solution

by:Alan_White
Alan_White earned 167 total points
ID: 33699559
Given that your script works on other servers, I would suspect that there is a WMI issue on that box.
0
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 
LVL 65

Assisted Solution

by:RobSampson
RobSampson earned 166 total points
ID: 33699583
Or there's some funny characters in the folder names that it's having trouble parsing...
0
 

Author Comment

by:evegter
ID: 33700220
I personally think it will be a WMI/DCOM related error on the server that I scan in this case. Another server runs through the script without a problem. Because the script always exits with an RPC error either on the FOR or NEXT line. Because it appears to work fine on that specific server once I process the C: drive (or a specific folder on the C:) and always fails once I try to access the F: drive. The suggestion by Rob regarding funny characters also crossed my mind but because it quits sort-of randomly (but still alphabetically) it sometimes gets past a certain foldername and the other time it does not. It also doesn't matter if that folder has SYSTEM/Administrators/... etc permissions or not.

I'll try to fix DCOM/WMI and then report status here...

Rgds,
Eric
0
 

Author Comment

by:evegter
ID: 33774320
I'm closing this question now as I can't really solve this particular issue. It's getting less relevant because the migration software (Quest Storage Suite) seems to run fine on the box. I did solve a couple of standard issues like improper nameresolution due to WINS Static record mismatches etc. After fixing the WINS and DNS nameresolution and turning of Kerberos PAC verification the server responds well. I needed to turn of the Kerberos PAC verification because the server is in an old WinNT domain were migrating away from.
Points to all people that provided input in this question.

Rgds,
Eric
0
 

Author Closing Comment

by:evegter
ID: 33774340
thanks for contributing
0
 
LVL 65

Expert Comment

by:RobSampson
ID: 33774389
No problem Eric. Thanks for the additional info.

Regards,

Rob.
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

I hope you'll find this tutorial useful and interesting. So let's try to extend Tcl with a new package.  For anyone more deeply interested please check out the book "Practical Programming in Tcl and Tk". It's really one of the best written books abo…
ADCs have gained traction within the last decade, largely due to increased demand for legacy load balancing appliances to handle more advanced application delivery requirements and improve application performance.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now