Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2003
  • Last Modified:

Problems during WMI Win32_Directory query

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
evegter
Asked:
evegter
  • 4
  • 3
  • 2
  • +1
3 Solutions
 
Alan_WhiteCommented:
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
 
Tony MassaCommented:
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
 
evegterAuthor Commented:
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
RobSampsonCommented:
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
 
Alan_WhiteCommented:
Given that your script works on other servers, I would suspect that there is a WMI issue on that box.
0
 
RobSampsonCommented:
Or there's some funny characters in the folder names that it's having trouble parsing...
0
 
evegterAuthor Commented:
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
 
evegterAuthor Commented:
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
 
evegterAuthor Commented:
thanks for contributing
0
 
RobSampsonCommented:
No problem Eric. Thanks for the additional info.

Regards,

Rob.
0

Featured Post

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

  • 4
  • 3
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now