Results 1 to 7 of 7

Thread: Checking to see if drive exists (mapped drive)

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jul 2001
    Posts
    95

    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.

  2. #2
    -= B u g S l a y e r =- peet's Avatar
    Join Date
    Aug 2000
    Posts
    9,629
    sample on making a network drive

    VB Code:
    1. '// Make a New project. Add a module. To the form Add three Text boxes And a Command button.
    2.  
    3. '// Code:
    4. '// Add this code To the module:
    5.  
    6. Option Explicit
    7. Declare Function WNetAddConnection Lib "mpr.dll" Alias "WNetAddConnectionA" (ByVal lpszNetPath As String, ByVal lpszPassword As String, ByVal lpszLocalName As String) As Long
    8. Declare Function WNetCancelConnection Lib "mpr.dll" Alias "WNetCancelConnectionA" (ByVal lpszName As String, ByVal bForce As Long) As Long
    9. Const WN_SUCCESS = 0 ' The function was successful.
    10. Const WN_NET_ERROR = 2 ' An error occurred on the network.
    11. Const WN_BAD_PASSWORD = 6 ' The password was invalid.
    12.  
    13. Function AddConnection(MyShareName As String, MyPWD As String, UseLetter As String) As Integer
    14.     On Local Error GoTo AddConnection1_Err
    15.     AddConnection = WNetAddConnection(MyShareName, MyPWD, UseLetter)
    16.     AddConnection_End:
    17.     Exit Function
    18.     AddConnection_Err:
    19.         AddConnection = Err
    20.         MsgBox Error$
    21.         Resume AddConnection_End
    22. End Function
    23.  
    24. '// Add this code To the Command button:
    25.  
    26. Private Sub Command1_Click()
    27.     variable = AddConnection(Text1.Text, Text2.Text , Text3.Text)
    28. End Sub
    -= a peet post =-

  3. #3
    -= B u g S l a y e r =- peet's Avatar
    Join Date
    Aug 2000
    Posts
    9,629

    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
    -= a peet post =-

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Jul 2001
    Posts
    95
    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,

  5. #5
    -= B u g S l a y e r =- peet's Avatar
    Join Date
    Aug 2000
    Posts
    9,629
    what kind of problems?

    any error msgs ?
    -= a peet post =-

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Jul 2001
    Posts
    95
    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 ="

  7. #7
    C# Aficionado Lord_Rat's Avatar
    Join Date
    Sep 2001
    Location
    Cave
    Posts
    2,497
    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
  •  



Click Here to Expand Forum to Full Width