Click to See Complete Forum and Search --> : Mapping Network Drive
WadeD
Jan 26th, 2000, 09:22 PM
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
Aaron Young
Jan 26th, 2000, 10:27 PM
I just put these together and they work for me:
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
aarony@redwingsoftware.com
ajyoung@pressenter.com
WadeD
Jan 26th, 2000, 10:38 PM
Aaron,
I copied the code you posted and called it using:
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
WadeD
Jan 27th, 2000, 12:09 AM
It returned false again, but the values should be correct because they work from Explorer. Anything else I could try?
Thanks,
Wade
Aaron Young
Jan 27th, 2000, 11:48 AM
Remove the Trailing BackSlash "\" from your NetworkPath and DriveLetter, ie.
sSuccess = ConnectDrive("\\PDC\KINMAN-DFS", "", "H:")
------------------
Aaron Young
Analyst Programmer
aarony@redwingsoftware.com
ajyoung@pressenter.com
Hansz
Feb 9th, 2000, 10:46 PM
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.
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
ankepulco
Sep 25th, 2000, 05:05 AM
Look at http://www.andreavb.f2s.com/tip030017.html
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.