INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Tips -N- Tricks

Connecting to Network Drive with Win API by danceman
Posted: 19 Aug 02

DECLARE INTEGER WNetAddConnection IN "mpr.dll" ;
    STRING cRemoteName, ;
    STRING cPassword, ;
    STRING cLocalName
DECLARE INTEGER WNetCancelConnection in WIN32API String,integer


#DEFINE NO_ERROR 0
* Error Constants: for connecting
#DEFINE ERROR_ACCESS_DENIED = 5
#DEFINE ERROR_ALREADY_ASSIGNED = 85
#DEFINE ERROR_BAD_DEV_TYPE = 66
#DEFINE ERROR_BAD_DEVICE = 1200
#DEFINE ERROR_BAD_NET_NAME = 67
#DEFINE ERROR_BAD_PROFILE = 1206
#DEFINE ERROR_BAD_PROVIDER = 1204
#DEFINE ERROR_BUSY = 170
#DEFINE ERROR_CANCELLED = 1223
#DEFINE ERROR_CANNOT_OPEN_PROFILE = 1205
#DEFINE ERROR_DEVICE_ALREADY_REMEMBERED = 1202
#DEFINE ERROR_EXTENDED_ERROR = 1208
#DEFINE ERROR_INVALID_PASSWORD = 86
#DEFINE ERROR_NO_NET_OR_BAD_PATH = 1203

* Error Constants: for disconnecting
#DEFINE ERROR_BAD_PROFILE  1206
#DEFINE ERROR_CANNOT_OPEN_PROFILE 1205
#DEFINE ERROR_DEVICE_IN_USE 2404
#DEFINE ERROR_EXTENDED_ERROR 1208
#DEFINE ERROR_NOT_CONNECTED 2250
#DEFINE ERROR_OPEN_FILES 2401

nReturn = 0
lForce = .t. && disconnect even if files or jobs are on connection
lNoForce = .f.  && fail to dissconnect if files or jobs are in connection

cResource = "\\Server\ShareName"
cPassword = "MyPassword"   && empty if not needed
cDriveLetter = "Y:"

nReturn = WNetAddConnection(cResource,cPassword,cDriveLetter)
if nReturn = NO_ERROR
    messagebox('Connection to server Successfull',0,'Shared Connect')
else
    messagebox('Connection to server Failed',0,'Shared Connect')
endif


nReturn = WNetCancelConnection(cDriveLetter,lNoForce)


** if failed you could process the nReturn in a case on the error codes

Back to Microsoft: Visual FoxPro FAQ Index
Back to Microsoft: Visual FoxPro Forum

My Archive

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close