Re: Visual Basic \ IFS
The advice given here set me on the right track. This is the sample code necessary for me to connect to the IFS through Visual Basic.
And then finally call the mapping
MapDrive(TheDriveLetter, IFSDIRECTORYPATH , "YourUserName", "YourPassword")
The advice given here set me on the right track. This is the sample code necessary for me to connect to the IFS through Visual Basic.
PHP Code:
'These variables are used to map a network drive to the IFS on the iSeries
Public Declare Function WNetAddConnection2 Lib "mpr.dll" Alias "WNetAddConnection2A" (ByRef lpNetResource As NETRESOURCE, ByVal lpPassword As String, ByVal lpUserName As String, ByVal dwFlags As Integer) As Integer
Public Declare Function WNetCancelConnection2 Lib "mpr" Alias "WNetCancelConnection2A" (ByVal lpName As String, ByVal dwFlags As Integer, ByVal fForce As Integer) As Integer
Public Const ForceDisconnect As Integer = 1
Public Const RESOURCETYPE_DISK As Long = &H1
Public Structure NETRESOURCE
Public dwScope As Integer
Public dwType As Integer
Public dwDisplayType As Integer
Public dwUsage As Integer
Public lpLocalName As String
Public lpRemoteName As String
Public lpComment As String
Public lpProvider As String
End Structure
Public Const NO_ERROR = 0
Public Const CONNECT_UPDATE_PROFILE = &H1
' The following includes all the constants defined for NETRESOURCE,
' not just the ones used in this example.
Public Const RESOURCETYPE_PRINT = &H2
Public Const RESOURCETYPE_ANY = &H0
Public Const RESOURCE_CONNECTED = &H1
Public Const RESOURCE_REMEMBERED = &H3
Public Const RESOURCE_GLOBALNET = &H2
Public Const RESOURCEDISPLAYTYPE_DOMAIN = &H1
Public Const RESOURCEDISPLAYTYPE_GENERIC = &H0
Public Const RESOURCEDISPLAYTYPE_SERVER = &H2
Public Const RESOURCEDISPLAYTYPE_SHARE = &H3
Public Const RESOURCEUSAGE_CONNECTABLE = &H1
Public Const RESOURCEUSAGE_CONTAINER = &H2
' Error Constants:
Public Const ERROR_ACCESS_DENIED = 5&
Public Const ERROR_ALREADY_ASSIGNED = 85&
Public Const ERROR_BAD_DEV_TYPE = 66&
Public Const ERROR_BAD_DEVICE = 1200&
Public Const ERROR_BAD_NET_NAME = 67&
Public Const ERROR_BAD_PROFILE = 1206&
Public Const ERROR_BAD_PROVIDER = 1204&
Public Const ERROR_BUSY = 170&
Public Const ERROR_CANCELLED = 1223&
Public Const ERROR_CANNOT_OPEN_PROFILE = 1205&
Public Const ERROR_DEVICE_ALREADY_REMEMBERED = 1202&
Public Const ERROR_EXTENDED_ERROR = 1208&
Public Const ERROR_INVALID_PASSWORD = 86&
Public Const ERROR_NO_NET_OR_BAD_PATH = 1203&
Public Const NET_ERROR_ACCESS_DENIED As Short = 5
Public Const ERROR_SESSION_CREDENTIAL_CONFLICT As Short = 1219
Public Const ERROR_NO_NETWORK As Short = 1222
Public Const ERROR_NOT_CONNECTED As Short = 2250
Public Const ERROR_OPEN_FILES As Short = 2401
Public Const ERROR_DEVICE_IN_USE As Short = 2404
Private iSeriesConnect As OleDbConnection
'Function to map drive/connect to drive
Public Function MapDrive(ByVal DriveLetter As String, ByVal UNCPath As String, ByVal strUsername As String, ByVal strPassword As String) As Boolean
Dim TheNetResource As NETRESOURCE
TheNetResource = New NETRESOURCE
TheNetResource.lpRemoteName = UNCPath
TheNetResource.lpLocalName = ""
'TheNetResource.lpLocalName = DriveLetter & ":"
TheNetResource.dwType = RESOURCETYPE_DISK
Dim iFlags As Integer = 0
iFlags = CONNECT_UPDATE_PROFILE
Dim result As Integer
result = WNetAddConnection2(TheNetResource, strPassword, strUsername, iFlags)
If result = 0 Then
Return True
Else
Return False
End If
End Function
#End Region
MapDrive(TheDriveLetter, IFSDIRECTORYPATH , "YourUserName", "YourPassword")
Comment