Extreme slowdown when accessing files over the network through VB when using an XP machine.

One part of my program checks the status of various files on other machines over a corporate network as a means of tracking progress on on a centralized machine. One of the issues that I never was able to resolve when using a Win98 box was having to manually open a connection to each machine (open a folder on each machine even though the folder share passwords were stored). When trying to access files in shared folders it would just come up as unavailable if I tried doing from within the VB program if I had not yet manually opened the shared folder.

Well now with WinXP it no longer does this, however that issue has now been replaced with a much more annoying one. Where before access was instant, it now takes 20-30 seconds to open a connection to any of the other machines (that is it no longer makes me manually open a folder, but now it basically locks up while it waits for 20+ seconds for the network connection to complete and the files to become accessible).

I realize this may not be the best forum to ask this question, since I also experience the slowdown when trying to open a shared folder outside of VB using an XP machine, but I thought perhaps someone might know a more direct way of checking a file across the network than what I'm using which would bypass this slowdown (or ideally something to reduce the lag). While I would like to read data from text files instantly without delay, it would suffice if I could at least know whether a named file exists in a given shared folder. Oddly this delay also crops up if there isn't constant communication as well. That is if a few minutes pass without accessing the shared folder, I incurr the long delay once again on the next attempt at access.

Public Function FileExist(strPath As String) As Boolean
    'Check whether a file exists/can be accessed
    Dim X As Integer
    X = FreeFile
    On Error Resume Next
    Open strPath For Input As X
    If Err = 0 Then
        FileExist = True
    Else: FileExist = False
    End If
    Close X
End Function
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Maybe its quicker when you use a window api to check off the file exist. I am not sure about that. You can try the code below.
Please let me now if you've got a question about the code or let me now how this is working for you.


Public Type WIN32_FIND_DATA
   dwFileAttributes As Long
   ftCreationTime As FILETIME
   ftLastAccessTime As FILETIME
   ftLastWriteTime As FILETIME
   nFileSizeHigh As Long
   nFileSizeLow As Long
   dwReserved0 As Long
   dwReserved1 As Long
   cFileName As String * MAX_PATH
   cAlternate As String * 14
End Type

Public Declare Function FindFirstFile Lib "kernel32" _
   Alias "FindFirstFileA" _
  (ByVal lpFileName As String, _
   lpFindFileData As WIN32_FIND_DATA) As Long
Public Declare Function FindClose Lib "kernel32" _
  (ByVal hFindFile As Long) As Long

Public Function FileExists(strPath As String) As Boolean

   Dim hFile As Long
   hFile = FindFirstFile(strPath, WFD)
   FileExists = hFile <> INVALID_HANDLE_VALUE
   Call FindClose(hFile)
End Function
JamesKillianAuthor Commented:
Thanks for the reply, it has the same amount of delay though, I made a quick test and it takes the same amount of time either way.
I'am sorry but i don't now what else you can try.

I've seen delays like this and they were always due to a network issue.

It could be something like a subnet mask mismatch, or NetBEUI taking preference to TCP/IP and not hearing anything. I've even seen the TCP/IP stack being loaded twice and competing. All resulting in a timeout or rerouting which takes a lot of time.

So take a look at your network settings and those of the other machine.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Hi JamesKillian,
This old question (QID 20561323) needs to be finalized -- accept an answer, split points, or get a refund.  Please see http://www.cityofangels.com/Experts/Closing.htm for information and options.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.