PBDR.COM

About   -   Contact   -   Purchase   -   Search   -   What's New

 
 
Mapping a Network Drive
This tip was sent in from Don L. Miller and show how to use the Window API for mapping a network drive from PowerBuilder.

Function Declaration:

FUNCTION ulong WNetUseConnectionA (ulong hwndOwner, &
   REF s_netresource lpNetResource, string lpPassword, 
   string lpUsername, ulong dwFlags, REF string lpAccessName, &
   REF ulong lpBufferSize, REF ulong lpResult) library "mpr.dll"

Structure Definition:

$PBExportHeader$s_netresource.srs
global type s_netresource from structure
 unsignedlong  dwScope
 unsignedlong  dwType
 unsignedlong  dwDisplayType
 unsignedlong  dwUsage
 string  lpLocalName
 string  lpRemoteName
 string  lpComment
 string  lpProvider
end type

Mapping Code:

CONSTANT ulong NO_ERROR = 0
CONSTANT ulong CONNECT_REDIRECT = 128
CONSTANT ulong RESOURCETYPE_DISK = 1

s_netresource lstr_netresource

String   ls_null
String   ls_buffer
String   ls_MappedDrive
 
uLong    ll_bufferlen
uLong    ll_null
uLong    ll_ErrInfo
uLong    ll_success
 
SetNull(ll_null)
SetNull(ls_null)
 
ls_buffer = Space(32)
ll_bufferlen = Len(ls_buffer)
 
lstr_netresource.dwType = RESOURCETYPE_DISK
lstr_netresource.lpLocalName = ls_null
lstr_netresource.lpRemoteName = "UNC resource name here"
lstr_netresource.lpProvider = ls_null
 
ll_ErrInfo = WNetUseConnectionA(ll_null, lstr_netresource, &
   'password', 'username', &
   CONNECT_REDIRECT, ls_buffer, ll_bufferlen, ll_success)
 
IF ll_ErrInfo = NO_ERROR THEN
   MessageBox("Drive Mapped", "Drive Letter is " + ls_buffer)
   Return 1
ELSE
   MessageBox("Mapping Falied", "Error is " + String(ll_ErrInfo))
   Return -1
END IF
 

Top of Page

Legal Notice

Ken Howe 2011