|
-
Oct 12th, 2000, 10:31 AM
#1
Thread Starter
Hyperactive Member
How can I map a network drive then check that it is still mapped when the program starts
-
Oct 12th, 2000, 02:05 PM
#2
To map a network drive, take a look at this thread.
Or you can do it using DOS.
Code:
Private Sub Command1_Click()
Shell ("net use ?: \\??\c"), vbHide
End Sub
? = The drive letter you want to use
?? = the network name of the computer you are mapping
-
Oct 12th, 2000, 02:20 PM
#3
Assuming you're network drive is mapped with an NT share, and the program you're talking about, is a vb program, you can use this code to make sure the connection is OK.
Code:
Option Explicit
Private Type NETRESOURCE
dwScope As Long
dwType As Long
dwDisplayType As Long
dwUsage As Long
pLocalName As String
pRemoteName As String
pComment As Long
pProvider As Long
End Type
Private Declare Function WNetGetConnection Lib "mpr.dll" Alias "WNetGetConnectionA" (ByVal lpszLocalName As String, ByVal lpszRemoteName As String, cbRemoteName As Long) As Long
Private Declare Function WNetCancelConnection2 Lib "mpr.dll" Alias "WNetCancelConnection2A" (ByVal lpName As String, ByVal dwFlags As Long, ByVal fForce As Long) As Long
Private Declare Function WNetAddConnection2 Lib "mpr.dll" Alias "WNetAddConnection2A" (lpNetResource As NETRESOURCE, ByVal lpPassword As String, ByVal lpUserName As String, ByVal dwFlags As Long) As Long
Private Const RESOURCETYPE_DISK = &H1
Private Const ERROR_NOT_CONNECTED = 2250&
Private Const CONNECT_UPDATE_PROFILE = &H1
Private Sub Form_Load()
Call CheckDrive("J:", "\\vseuec01\iss_dev$")
End Sub
Private Sub CheckDrive(ByVal Drive As String, ByVal Share As String)
Dim CurrShare As String
Dim nr As NETRESOURCE
Dim retVal As Long
Dim bConnected As Boolean
bConnected = False
CurrShare = Space(256)
retVal = WNetGetConnection(Drive, CurrShare, 255)
If retVal = 0 Then
CurrShare = Left(CurrShare, InStr(CurrShare, Chr(0)) - 1)
If UCase(Share) = UCase(CurrShare) Then
' everything is OK, do nothing
bConnected = True
Else
' if already connected to something else
' disconnect it (and force it)
retVal = WNetCancelConnection2(Drive, 0, True)
End If
End If
' if not connected, connect it
If Not bConnected Then
nr.dwType = RESOURCETYPE_DISK
nr.pLocalName = Drive
nr.pRemoteName = Share
retVal = WNetAddConnection2(nr, vbNullString, vbNullString, 0)
' if you want the new connection to be restored at next logon
' use the next line instead of the previous one
'retVal = WNetAddConnection2(nr, vbNullString, vbNullString, CONNECT_UPDATE_PROFILE)
End If
End Sub
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|