Solved

Detect Map Drive is Connected

Posted on 2004-09-10
14
422 Views
Last Modified: 2008-01-09
I several users that have mapped drives to //Server/path/path...

Each user could have different drive letters.

Mary could be K:

Bob could be H:

John could be J:

Therefore I don't want to hard code the letter.  I want to pass the //Server/path/path... to a function and tell me if the //Server/path/path is connected or not.

These people have lap top computers and I don't want the program to run if the mapped drive is not connected.

I would like a function call to check this connection and pass back a true or false on connected or not based on the passing of the //Server/path/path... and not the letter.

Thanks,
smithmrk
0
Comment
Question by:smithmrk
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 5
  • 3
14 Comments
 
LVL 8

Expert Comment

by:bramsquad
ID: 12027266
If Dir("//Server/path/path") <> "" Then
     MsgBox "true"
Else
     MsgBox "false"
End If

~b
0
 

Author Comment

by:smithmrk
ID: 12027433
I need to know if the mapped drive is connected.

The mapped drive path is always listed there, the question is does it have the red X over it or not.

Thanks,
smithmrk
0
 
LVL 8

Expert Comment

by:bramsquad
ID: 12027556
actually after using this code i came up with something similar, but it should work

the Dir() function fails if there is not connection, so if you set an event handler, you can tell if there is a connection or not.

Function IsConnected(Fullpath As String) As Boolean
    On Error GoTo fail
    If Dir(Fullpath, vbDirectory) <> "" Then IsConnected = True
fail:
    IsConnected = False
End Function

~b
0
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 

Author Comment

by:smithmrk
ID: 12027642
It seems to always fail.

I'm connected right now and it is failing.

Thanks,
smithmrk
0
 
LVL 8

Expert Comment

by:bramsquad
ID: 12027946
i need to start testing these out before i submit them

replace your function with this

Function IsConnected(Fullpath As String) As Boolean
    On Error GoTo fail
    If Dir(Fullpath, vbDirectory) <> "" Then
        IsConnected = True
        Exit Function
    End If
fail:
    IsConnected = False
End Function
0
 
LVL 15

Expert Comment

by:unknown_routine
ID: 12027972
Hi ,
Use ChDir   ( this is Vb equal of dos CD)


Chdir "M:\Dir1\Dir2"

Here M is name of mapped drive( change it to any letter you need) , if it is  not conected this command returns an error

and you will find out.
0
 

Author Comment

by:smithmrk
ID: 12027999
I can't used letters!

Letters are different for each user.

I want to know if the map drive is connected or not.  Red X or Not

Thanks,
smithmrk
0
 
LVL 15

Expert Comment

by:unknown_routine
ID: 12028079

Then simply use the server name:


ChDir "\\Server\dir1\dir2"
0
 
LVL 8

Accepted Solution

by:
bramsquad earned 250 total points
ID: 12028085
ok, this is my exact code, and it works perfect...

'-----------------------------------

Private Sub Command65_Click()
     If IsConnected("\\Iademsvr0000\FINANCE\") = True Then
         MsgBox "its here"
     Else
         MsgBox "its not here"
     End If
End Sub

'-----------------------------------

Function IsConnected(Fullpath As String) As Boolean
    On Error GoTo fail
    If Dir(Fullpath, vbDirectory) <> "" Then
        IsConnected = True
        Exit Function
    End If
fail:
    IsConnected = False
End Function

~b
0
 
LVL 8

Expert Comment

by:bramsquad
ID: 12028101
the reason it was showing up false all the time is becuase i didnt exit the function after setting the return value, so it always set it to false
0
 
LVL 8

Expert Comment

by:bramsquad
ID: 12028171
oh wow.....

i just realized, you have to have a forward slash at the end of your path

so this

IsConnected("\\Iademsvr0000\FINANCE\")

is correct....and this

IsConnected("\\Iademsvr0000\FINANCE")

is incorrect.  this should do the trick
0
 

Author Comment

by:smithmrk
ID: 12028383
The Slash may have been my issue, but I was also passing the wrong path I wanted to check to the function.

Either way it works now, because I just disconnected my lap top from the server and it failed on connection.

Thanks,
smithmrk
0
 
LVL 15

Expert Comment

by:unknown_routine
ID: 12028691
Did you try my last comment?

It seems to work.
0
 

Author Comment

by:smithmrk
ID: 12028722
Yes!

Thanks I'm all set now.

I really appreciate the help.

Thanks again,
smithmrk
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

726 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