Way to get open file info quickly

Posted on 2005-04-21
Last Modified: 2010-08-05
Hi Experts,

I have a problem with trying to get some information on open files out of our server.  The following
code works, but is deathly slow on all but the local server on the local sub-domain.  If I try to query a
server from another sub-domain across the WAN, it takes forever.  Is this because of a late-binding
issue?   I just wanted to speed up the process of obtaining this information and perhaps use
early-binding if possible.  Tools like the PSTOOLS by Winternals are extremely fast at returning
results no matter what server I query (and I want the same), but am stumped on how I could
approach this (or if it is even possible using ADSI?).  


    Dim fso As IADsFileServiceOperations
    Dim rs2 As IADsCollection
    Dim rs As IADsResource
    On Error GoTo Cleanup
    Set fso = GetObject("WinNT://" & Command$ & "/LanmanServer")
    Set rs2 = fso.Resources
    For Each rs In rs2
        List1.AddItem rs.Path
        If (Err.Number <> 0) Then
            MsgBox ("An error has occurred. " & Err.Number & vbCrLf & Err.Description)
        End If
        Set rso = Nothing
        Set rs = Nothing

Question by:sharizod
    LVL 23

    Accepted Solution

    The FSO is a lot slower then using API's to achieve getting or accessing any information with regards to access times take a look at these :

    This scripting page ( which has a one to search files and attain file information ( not sure about getting it to do it remotely however )

    Take a look here on comparison between API VS FSO :

    You can also search around on the above site for any info with regards to getting remote file info.

    Here is some things to look at :

    An Admin program in vb 6 using wmi and adsi ( Not sure how much help this will be to you ) :

    I hope this helps you out some what.
    LVL 1

    Author Comment

    Hi Gecko_au2003,

    Thanks for the response.  I want to try and get away from the vbscripting (either through VB itself or via scripts).
    They only support late-binding for the methods they expose that deal with files.  Because of that, utilizing it
    would be too slow for my application.  I do have some code that I picked up about a month ago that iterates through
    the filesystem using the NetFileEnum API's.  It uses a couple of Copymemory tricks as well to get it to map the
    necessary information in memory to make it all work.  I want to utilize this code because it works - with a catch.
    It only works when executing it as an exe on the server that is running in the context of the domain admins or
    administrators groups.  When I try to use the same code in an ActiveX DLL and try calling it in a web page, it
    executes, but produces no results (unlike executing the EXE on the server).

    Are there permissions attached to calling the NetFileEnum API??  If so, how can I get around it, and do you
    know of any code that is ialready in .NET that utilizes that function to obtain open file information across

    Best Regards & TIA.
    LVL 1

    Author Comment

    I just thought I'd mention I tried converting the vb6 code to .NET and there were so many issues with it, I just
    couldn't get it to work.  A lot of the API calls involve parameters declared as type ANY, which .NET no longer
    supports!  I understand I have to marshal them but I have tried to get the syntax down from a few code
    examples, but came up empty-handed and more frustrated than ever.
    LVL 23

    Expert Comment

    I am not really sure what else to suggest, as the only things I found relevant to what you are trying to do is in what I have posted, other then maybe take a look at or

    They have some good stuff on them that you may find of use :)

    Other then that I am sorry !
    LVL 1

    Author Comment

    Gecko, thanks for the help thus far, but I really haven't gotten much further than when I started
    this question (sorry for the lag in response).   I've decided the users can live with a bit of
    delay since the server or PC seems to cache the result and it seems to execute faster with
    each run.

    Thanks for trying,
    LVL 23

    Expert Comment

    what did you do in the end  and what happened exactly ?
    LVL 1

    Author Comment

    I was just perusing some of my old questions to find some answers with another problem I'm faced with and see
    that I never answered you back here!  My apologies.  

    Anyway.  What I did was to use rewrite it in .NET utilizing ADSI.  Then I used impersonation to get the
    proper permissions to be able to successfully execute the ADSI queries.  I did have all sorts of trials
    and tribulations upgrading the root Win2K PDC & IIS 5 to use the .NET framework  but came out on
    top (although I still don't know HOW I did it)!!  

    I still had permissions problems using traditional ASP and there was no way in heck that I was ever
    going to get it to work properly other than using the traditional COM/NetFileEnum solution that had
    already been in place (kept having IIS locking issues whenever a sync via FP2002 would be performed
    and would have to rename the COM DLL or re-install IIS to be able to use it again).

    Although it is true that ADSI is MUCH slower than the NetFileEnum version of my ASP DLL, the users
    don't need THAT much of a real-time reporting solution.  All they use the web app/component for is
    to see who is currently on the MRP system we use for the purpose of kicking them out (for those
    processes that can be run with only one user in the system).  If and when I can ever get a workable
    version utilizing the NetFileEnum API in .NET, I may switch over to that.

    Featured Post

    How to improve team productivity

    Quip adds documents, spreadsheets, and tasklists to your Slack experience
    - Elevate ideas to Quip docs
    - Share Quip docs in Slack
    - Get notified of changes to your docs
    - Available on iOS/Android/Desktop/Web
    - Online/Offline

    Join & Write a Comment

    The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
    If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
    Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
    This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

    732 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

    17 Experts available now in Live!

    Get 1:1 Help Now