Fast UNC check

FuzMic

DataBase Tinker
Local time
Tomorrow, 04:50
Joined
Sep 13, 2006
Messages
744
Hi gurus

I want to check if an UNC exist using Scripting.FileSystemObject .GetFolder("\\MYUNCPATH\MYFLD")

If it does not exist it will flag error 76. In some pc, the response is fast but in some it may take up to 2 minutes before err is flagged.

Is there another faster way yet easy. Hopefully.
 
You can ping the server first to see if it exists, with code like...
Code:
Function Ping(ServerName As String) As Boolean
On Error GoTo handler
    Dim objPing As Object
    Dim objStatus As Object
       
    Set objPing = _
        GetObject("winmgmts:{impersonationLevel=impersonate}"). _
        ExecQuery("Select * from Win32_PingStatus Where Address = '" & ServerName & "'")
       
    For Each objStatus In objPing
        Select Case objStatus.StatusCode
            Case 0
                Ping = True
            Case 11001 To 11050
                Ping = False
            Case Else
                Ping = False
        End Select
    Next
    Exit Function
handler:
    Ping = False
End Function
This takes about 4 seconds on my machine if I try to ping a machine that doesn't exist on the network.
Mark
 
maybe just check if it exists, instead of creating an object
out of it.

Code:
Public Function FolderExists(FolderName As String) As Boolean
    Dim objFSO As Object
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    FolderExists = objFSO.FolderExists(FolderName)
    Set objFSO = Nothing
End Function
 
Mark Thanks for the pinging advice & arnelgp Thanks too, i will the folderexists instead of getfolder & see how the speed pans out.
 
Guys sorry to report using Folder.exist still slow on on particular win8.1 laptop. It might be just a bug in the OS due to whatever reason.
Ping does work at all.
 

Users who are viewing this thread

Back
Top Bottom