Results 1 to 8 of 8

Thread: Mapping Network Drive

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 1999
    Posts
    363

    Post

    Hi, I read the following in a post:

    "For mapping a network drive, do the following: <A HREF="http://www.vb-world.net/internet/tip93.html"" TARGET=_blank>http://www.vb-world.net/internet/tip93.html"</A>

    But when I use the code listed in the article the function returns 1200 and the drive doesn't map. How can I map a drive through VB?

    Thanks in advance,
    Wade

  2. #2
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,177

    Post

    I just put these together and they work for me:
    Code:
    Private Declare Function WNetAddConnection Lib "mpr.dll" Alias "WNetAddConnectionA" (ByVal lpszNetPath As String, ByVal lpszPassword As String, ByVal lpszLocalName As String) As Long
    Private Declare Function WNetCancelConnection Lib "mpr.dll" Alias "WNetCancelConnectionA" (ByVal lpszName As String, ByVal bForce As Long) As Long
    
    Function ConnectDrive(ByVal NetworkPath As String, ByVal Password As String, ByVal DriveLetter As String) As Boolean
        ConnectDrive = (WNetAddConnection(NetworkPath, Password, DriveLetter) = 0)
    End Function
    
    Function DisconnectDrive(ByVal DriveLetter As String, Optional ByVal Force As Boolean = False) As Boolean
        DisconnectDrive = (WNetCancelConnection(DriveLetter, Force) = 0)
    End Function
    Usage: ConnectDrive("\\Server\ShareName", "Password", "Z:")
    Usage: DisconnectDrive("Z:", [Force])


    ------------------
    Aaron Young
    Analyst Programmer
    [email protected]
    [email protected]


  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 1999
    Posts
    363

    Post

    Aaron,

    I copied the code you posted and called it using:
    Code:
    sSuccess = ConnectDrive("\\PDC\KINMAN-DFS\", "", "H:\")
    MsgBox sSuccess
    It returned False. From Windows Explorer, I mapped using \\PDC\KINMAN-DFS\ for the path, H:\ for the drive and no password and that works. Do you see where I am going wrong?

    Thanks so much,
    Wade

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 1999
    Posts
    363

    Post

    It returned false again, but the values should be correct because they work from Explorer. Anything else I could try?

    Thanks,
    Wade

  5. #5
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,177

    Post

    Remove the Trailing BackSlash "\" from your NetworkPath and DriveLetter, ie.

    sSuccess = ConnectDrive("\\PDC\KINMAN-DFS", "", "H:")

    ------------------
    Aaron Young
    Analyst Programmer
    [email protected]
    [email protected]


  6. #6
    Junior Member
    Join Date
    Feb 2000
    Location
    Netherlands
    Posts
    27

    Post

    Originally posted by WadeD:
    It returned false again, but the values should be correct because they work from Explorer. Anything else I could try?

    Thanks,
    Wade
    You want to make a mapping to a PDC(=NT). I think you have to declare a loginname in WNetAddConnection. Otherwise you won't have enough rights to make the share.

  7. #7
    Guest
    Hi!

    How can I Map Drive with a different User ID ?


    I Want map drive on my machine with user ID and password
    of other person....


    Thanks!


    JP

  8. #8
    New Member
    Join Date
    Sep 2000
    Posts
    1

    Wink Map Network Drive with new Username and password


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width