connect to LAN system

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sameerkhan
    New Member
    • Nov 2006
    • 6

    connect to LAN system

    Hi everyone,

    I have less exposure in VB. i have to program following logic. could any please send me how to do.

    i will get two parameter servername and folderpath

    i have to connect to server name and i have validate the path is exist or not.

    if exist i have to validate the path is in C: drive r not

    Ex input param.

    servername chnmachine
    path C:\program files


    Thanx in advance
  • swatmajor1
    New Member
    • Oct 2006
    • 40

    #2
    Originally posted by sameerkhan
    Hi everyone,

    I have less exposure in VB. i have to program following logic. could any please send me how to do.

    i will get two parameter servername and folderpath

    i have to connect to server name and i have validate the path is exist or not.

    if exist i have to validate the path is in C: drive r not

    Ex input param.

    servername chnmachine
    path C:\program files


    Thanx in advance
    Hi there

    Lets see if I've got thing straight.

    You want to see if a server exists and whether or not a particular folder on that server exists. I'm guessing that you want the program to return the full server name and path in a text box as well.

    I don't know whether or not I can help you, but I will see what others I know more experienced than me will say, so keep watch

    Signing off,

    Swatmajor1

    Comment

    • sashi
      Recognized Expert Top Contributor
      • Jun 2006
      • 1749

      #3
      Originally posted by sameerkhan
      Hi everyone,

      I have less exposure in VB. i have to program following logic. could any please send me how to do.

      i will get two parameter servername and folderpath

      i have to connect to server name and i have validate the path is exist or not.

      if exist i have to validate the path is in C: drive r not

      Ex input param.

      servername chnmachine
      path C:\program files


      Thanx in advance
      Hi there,

      Kindly refer to below attached code segment, hope it helps. Good luck & Take care.

      Put this portion in a class file..
      Code:
      Option Explicit
      
      Private Declare Function WNetAddConnection Lib "mpr.dll" Alias "WNetAddConnectionA" (ByVal lpszNetPath As String, ByVal lpszPassword As String, ByVal lpszLocalName As String) As Long
      Private Declare Function WNetCancelConnection Lib "mpr.dll" Alias "WNetCancelConnectionA" (ByVal lpszName As String, ByVal bForce As Long) As Long
      
      Const WN_Success = &H0
      Const WN_Not_Supported = &H1
      Const WN_Net_Error = &H2
      Const WN_Bad_Pointer = &H4
      Const WN_Bad_NetName = &H32
      Const WN_Bad_Password = &H6
      Const WN_Bad_Localname = &H33
      Const WN_Access_Denied = &H7
      Const WN_Out_Of_Memory = &HB
      Const WN_Already_Connected = &H34
      
      '-- Error number and message
      Public ErrorNum         As Long
      Public ErrorMsg         As String
      
      Public rc               As Long
      
      Private Const ERROR_NO_CONNECTION = 8
      Private Const ERROR_NO_DISCONNECT = 9
      
      Public Sub Connect(sDrive As String, sService As String, Optional sPassword As String = "")
         
         On Error GoTo Err_Connect
         Me.ErrorNum = 0
         Me.ErrorMsg = ""
         rc = WNetAddConnection(sService & Chr(0), sPassword & Chr(0), sDrive & Chr(0))
         If rc <> 0 Then GoTo Err_Connect
         
         Exit Sub
      
      Err_Connect:
         Me.ErrorNum = rc
         Me.ErrorMsg = WnetError(rc)
      
      End Sub
      
      Public Sub DisConnect(sDrive As String)
         
         On Error GoTo Err_DisConnect
         Me.ErrorNum = 0
         Me.ErrorMsg = ""
         rc = WNetCancelConnection(sDrive + Chr(0), 0)
         If rc <> 0 Then GoTo Err_DisConnect
         
         Exit Sub
      Err_DisConnect:
         Me.ErrorNum = rc
         Me.ErrorMsg = WnetError(rc)
      
      End Sub
      
      Private Function WnetError(Errcode As Long) As String
      
         Select Case Errcode
            Case WN_Not_Supported:
               WnetError = "Function is not supported."
            Case WN_Out_Of_Memory:
               WnetError = "Out of Memory."
            Case WN_Net_Error:
               WnetError = "An error occurred on the network."
            Case WN_Bad_Pointer:
               WnetError = "The Pointer was Invalid."
            Case WN_Bad_NetName:
               WnetError = "Invalid Network Resource Name."
            Case WN_Bad_Password:
               WnetError = "The Password was Invalid."
            Case WN_Bad_Localname:
               WnetError = "The local device name was invalid."
            Case WN_Access_Denied:
               WnetError = "A security violation occurred."
            Case WN_Already_Connected:
               WnetError = "The local device was connected to a remote resource."
            Case Else:
               WnetError = "Unrecognized Error " + str(Errcode) + "."
         End Select
      
      End Function
      Sample usage as follows..
      Code:
         Call gclsNetUse.Connect(gsDrive, gsServerName)
         If (gclsNetUse.rc <> 0) And (gclsNetUse.rc <> 85) Then
            MsgBox gclsNetUse.ErrorMsg
            End
         End If

      Comment

      • sameerkhan
        New Member
        • Nov 2006
        • 6

        #4
        Thanks Buddy. Let me test it is feasible to solve my problem.

        Comment

        Working...