|
-
May 12th, 2002, 11:56 AM
#1
Thread Starter
Lively Member
Checking to see if drive exists (mapped drive)
Hi All,
You know the way that you can map a drive on your computer to a remote shared directory every time the PC starts up.
Is there any way of checking in VB that this mapping has occured.
And if it hasnt is there a way to do it through VB?.
Thanks in advance,
Ray.
P.S. Its a very simple backup program that xcopys files to remote shared directory.
-
May 12th, 2002, 12:16 PM
#2
-= B u g S l a y e r =-
sample on making a network drive
VB Code:
'// Make a New project. Add a module. To the form Add three Text boxes And a Command button.
'// Code:
'// Add this code To the module:
Option Explicit
Declare Function WNetAddConnection Lib "mpr.dll" Alias "WNetAddConnectionA" (ByVal lpszNetPath As String, ByVal lpszPassword As String, ByVal lpszLocalName As String) As Long
Declare Function WNetCancelConnection Lib "mpr.dll" Alias "WNetCancelConnectionA" (ByVal lpszName As String, ByVal bForce As Long) As Long
Const WN_SUCCESS = 0 ' The function was successful.
Const WN_NET_ERROR = 2 ' An error occurred on the network.
Const WN_BAD_PASSWORD = 6 ' The password was invalid.
Function AddConnection(MyShareName As String, MyPWD As String, UseLetter As String) As Integer
On Local Error GoTo AddConnection1_Err
AddConnection = WNetAddConnection(MyShareName, MyPWD, UseLetter)
AddConnection_End:
Exit Function
AddConnection_Err:
AddConnection = Err
MsgBox Error$
Resume AddConnection_End
End Function
'// Add this code To the Command button:
Private Sub Command1_Click()
variable = AddConnection(Text1.Text, Text2.Text , Text3.Text)
End Sub
-
May 12th, 2002, 12:21 PM
#3
-= B u g S l a y e r =-
Re: Checking to see if drive exists (mapped drive)
Originally posted by dermodyr
....
P.S. Its a very simple backup program that xcopys files to remote shared directory.
hehe nothing beats xcopy when it comes to copy files... I use it too.. but I only use bat files running it 
Code:
c:
cd c:\util\backuptool
xcopy c:\_PVRRP_\*.* /D /E /C /I /H /R /Y D:\_PVRRP_ > D:\_PVRRP_\_PVRRP_.LOG
very fast
-
May 12th, 2002, 01:08 PM
#4
Thread Starter
Lively Member
Yeah XCOPY rocks. Actually you might know this. My XCOPY doesnt support the /EXCLUDE parameter. Do you know why this is.
Sorry man but I couldnt get that code to work. I have found some similar code on a different thread. But again Im having problems.
Heres the module
Public Sub Connect(sDrive As String, sService As String, sPassword As String)
On Error GoTo Err_Connect
ErrorNum = 0
ErrorMsg = ""
rc = WNetAddConnection(sService & Chr(0), sPassword & Chr(0), sDrive & Chr(0))
If rc <> 0 Then GoTo Err_Connect
Exit Sub
Err_Connect:
ErrorNum = rc
ErrorMsg = WnetError(rc)
End Sub
What do I pass to this function to create a connection.
E.g. Map z: to \\reception\backup with no password.
Yeah Im a eejit I know but I havent worked much with mods or functions.
Thanks man,
-
May 12th, 2002, 01:10 PM
#5
-= B u g S l a y e r =-
what kind of problems?
any error msgs ?
-
May 12th, 2002, 01:14 PM
#6
Thread Starter
Lively Member
Sorry man the first line should be
Public Sub Connect(sDrive As String, sService As String, Optional sPassword As String = "")
If I put in
Connect ("z:", "\\reception\backup\", "") it says "Compile Error expected ="
-
May 12th, 2002, 01:30 PM
#7
If it's the only thing on the line, either place the keyword CALL before it, or don't include parenthesis
Need to re-register ASP.NET?
C:\WINNT\Microsoft.NET\Framework\v#VERSIONNUMBER#\aspnet_regiis -i
(Edit #VERSIONNUMBER# as needed - do a DIR if you don't know)
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
|