Force connections to a remote drive

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • vbshanes@gmail.com

    #1

    Force connections to a remote drive

    We use Samba on a SCO Unix box as our file server / backup device. I
    have a directory mapped as a Windows drive. I read / write files from
    this remote drive with my VB,net application. This arrangement works
    99.99% of the time.

    That being said, Windows does not automatically connect to the remote
    drive at system boot every once in a great while. Some of our
    customers have certain Windows boxes that the problem is a bit more
    frequent.

    The easy work around is to go into Windows Explorer and double click
    on the remote drive. Every program in Windows can now see the drive.
    That's not very professional.

    I want to force my application to do the same sort of connection that
    Windows Explorer is doing. Any ideas?

    Thanks.
  • Michel Posseth  [MCP]

    #2
    Re: Force connections to a remote drive


    This looks more like a SAMBA misconfiguratio n to me , just a thought is
    netbios enabled on the Windows computers ?
    as i remember simular issues in the company i previously worked for . it
    turned out that the Windows XP machines had standard netbios dissabled
    enabling netbios solved these issues .

    regards

    Michel





    <vbshanes@gmail .comschreef in bericht
    news:9c14f597-5735-4d34-9dfa-c89781eb123d@t1 8g2000prt.googl egroups.com...
    We use Samba on a SCO Unix box as our file server / backup device. I
    have a directory mapped as a Windows drive. I read / write files from
    this remote drive with my VB,net application. This arrangement works
    99.99% of the time.
    >
    That being said, Windows does not automatically connect to the remote
    drive at system boot every once in a great while. Some of our
    customers have certain Windows boxes that the problem is a bit more
    frequent.
    >
    The easy work around is to go into Windows Explorer and double click
    on the remote drive. Every program in Windows can now see the drive.
    That's not very professional.
    >
    I want to force my application to do the same sort of connection that
    Windows Explorer is doing. Any ideas?
    >
    Thanks.

    Comment

    • Bob Altman

      #3
      Re: Force connections to a remote drive

      <vbshanes@gmail .comwrote in message
      news:9c14f597-5735-4d34-9dfa-c89781eb123d@t1 8g2000prt.googl egroups.com...
      We use Samba on a SCO Unix box as our file server / backup device. I
      have a directory mapped as a Windows drive. I read / write files from
      this remote drive with my VB,net application. This arrangement works
      99.99% of the time.
      >
      That being said, Windows does not automatically connect to the remote
      drive at system boot every once in a great while. Some of our
      customers have certain Windows boxes that the problem is a bit more
      frequent.
      >
      The easy work around is to go into Windows Explorer and double click
      on the remote drive. Every program in Windows can now see the drive.
      That's not very professional.
      >
      I want to force my application to do the same sort of connection that
      Windows Explorer is doing. Any ideas?
      You can try accessing a file or a folder on the drive from code. That might
      do whatever magic Windows does when you double-click drive letter. If that
      doesn't work then you can look at the WNetAddConnecti on2 and
      WNetCancelConne ction2 APIs, which will let you mount and dismount network
      files programmaticall y.


      Comment

      • Brian

        #4
        Re: Force connections to a remote drive

        What verson of Samba are you using? What verison of SCO Unix?
        I had this problem a few years ago, well it was more like Samba on FlexOS,
        but the problem was only intermit.

        <vbshanes@gmail .comwrote in message
        news:9c14f597-5735-4d34-9dfa-c89781eb123d@t1 8g2000prt.googl egroups.com...
        We use Samba on a SCO Unix box as our file server / backup device. I
        have a directory mapped as a Windows drive. I read / write files from
        this remote drive with my VB,net application. This arrangement works
        99.99% of the time.
        >
        That being said, Windows does not automatically connect to the remote
        drive at system boot every once in a great while. Some of our
        customers have certain Windows boxes that the problem is a bit more
        frequent.
        >
        The easy work around is to go into Windows Explorer and double click
        on the remote drive. Every program in Windows can now see the drive.
        That's not very professional.
        >
        I want to force my application to do the same sort of connection that
        Windows Explorer is doing. Any ideas?
        >
        Thanks.

        Comment

        • vbshanes@gmail.com

          #5
          VB,Net Class (2005) to handle the connections

          Appologies to word wrapping.

          There is more code than the bare minimum to get the class to work. I
          put an error routine to get the english meaning of the returned error
          codes. Also, all of the constants defined by the Microsoft MSDN2 pages
          are defined, although I only needed a couple of them.

          Enjoy

          Imports System.Runtime. InteropServices
          Public Class clsConnectDrive
          Private Declare Function WNetAddConnecti on2 Lib "mpr.dll" Alias _
          "WNetAddConnect ion2A" (ByVal netResource As NETRESOURCE, _
          ByVal password As [String], ByVal Username As [String], _
          ByVal Flag As Integer) As Integer

          Private Declare Function WNetCancelConne ction2 Lib "mpr.dll" Alias
          _
          "WNetCancelConn ection2A" (ByVal lpName As String, _
          ByVal Flag As Integer, ByVal fForce As Integer) As Integer

          Private m_strDrive As String
          Private m_strNetworkSha re As String
          Private m_intError As Integer

          <StructLayout(L ayoutKind.Seque ntial)_
          Class NETRESOURCE
          Public dwScope As Integer
          Public dwType As Integer
          Public dwDisplayType As Integer
          Public dwUsage As Integer
          Public LocalName As String
          Public RemoteName As String
          Public Comment As String
          Public Provider As String
          End Class

          '---------- Network Constants ----------
          Private Const NO_ERROR As Integer = 0
          Private Const CONNECT_UPDATE_ PROFILE As Integer = &H1 '
          Disconnect

          Private Const RESOURCETYPE_AN Y As Integer = &H0
          Private Const RESOURCETYPE_DI SK As Integer = &H1
          Private Const RESOURCETYPE_PR INT As Integer = &H2

          Private Const RESOURCE_CONNEC TED As Integer = &H1
          Private Const RESOURCE_GLOBAL NET As Integer = &H2
          Private Const RESOURCE_REMEMB ERED As Integer = &H3

          Private Const RESOURCEDISPLAY TYPE_GENERIC As Integer = &H0
          Private Const RESOURCEDISPLAY TYPE_DOMAIN As Integer = &H1
          Private Const RESOURCEDISPLAY TYPE_SERVER As Integer = &H2
          Private Const RESOURCEDISPLAY TYPE_SHARE As Integer = &H3

          Private Const RESOURCEUSAGE_C ONNECTABLE As Integer = &H1
          Private Const RESOURCEUSAGE_C ONTAINER As Integer = &H2

          ' Error Constants:
          Private Const ERROR_ACCESS_DE NIED As Integer = 5&
          Private Const ERROR_ALREADY_A SSIGNED As Integer = 85&
          Private Const ERROR_BAD_DEV_T YPE As Integer = 66&
          Private Const ERROR_BAD_DEVIC E As Integer = 1200&
          Private Const ERROR_BAD_NET_N AME As Integer = 67&
          Private Const ERROR_BAD_PROFI LE As Integer = 1206&
          Private Const ERROR_BAD_PROVI DER As Integer = 1204&
          Private Const ERROR_BUSY As Integer = 170&
          Private Const ERROR_CANCELLED As Integer = 1223&
          Private Const ERROR_CANNOT_OP EN_PROFILE As Integer = 1205&
          Private Const ERROR_DEVICE_AL READY_REMEMBERE D As Integer = 1202&
          Private Const ERROR_EXTENDED_ ERROR As Integer = 1208&
          Private Const ERROR_INVALID_P ASSWORD As Integer = 86&
          Private Const ERROR_NO_NET_OR _BAD_PATH As Integer = 1203&

          '---------- Start Code ----------
          Public Sub New(ByVal Drive As String, ByVal NetworkShare As
          String)
          m_strDrive = Drive
          If m_strDrive.Leng th 1 Then m_strDrive =
          m_strDrive.Subs tring(0, 1)
          m_strDrive += ":"
          m_strNetworkSha re = NetworkShare
          End Sub

          '---------- Connect a drive ----------
          Public Function DriveConnect(Op tional ByVal IgnoreAlreadyCo nnected
          As Boolean = True) As Integer
          Dim myNetResource As New NETRESOURCE
          myNetResource.d wScope = RESOURCE_GLOBAL NET
          myNetResource.d wType = RESOURCETYPE_DI SK
          myNetResource.d wDisplayType = RESOURCEDISPLAY TYPE_SHARE
          myNetResource.d wUsage = RESOURCEUSAGE_C ONNECTABLE
          myNetResource.L ocalName = m_strDrive
          myNetResource.R emoteName = m_strNetworkSha re
          myNetResource.P rovider = Nothing
          m_intError = WNetAddConnecti on2(myNetResour ce, Nothing,
          Nothing, 0)
          If m_intError = ERROR_ALREADY_A SSIGNED AndAlso
          IgnoreAlreadyCo nnected Then m_intError = NO_ERROR
          Return m_intError
          End Function

          '---------- Disconnect a drive ----------
          Public Function DriveDisconnect () As Integer
          m_intError = WNetCancelConne ction2(m_strDri ve,
          CONNECT_UPDATE_ PROFILE, 0)
          Return m_intError
          End Function

          '---------- Error Code Description ----------
          ' Use the last error from either the connect or disconnect
          Public Function ErrorCodeMeanin g() As String
          Dim m_strMessage As String = "*** Undefined ***"
          Select Case m_intError
          Case NO_ERROR : m_strMessage = ""
          Case ERROR_ACCESS_DE NIED : m_strMessage = "Access Denied"
          Case ERROR_ALREADY_A SSIGNED : m_strMessage = "Already
          Assigned"
          Case ERROR_BAD_DEV_T YPE : m_strMessage = "Bad Device Type"
          Case ERROR_BAD_DEVIC E : m_strMessage = "Bad Device"
          Case ERROR_BAD_NET_N AME : m_strMessage = "Bad Net Name"
          Case ERROR_BAD_PROFI LE : m_strMessage = "Bad Profile"
          Case ERROR_BAD_PROVI DER : m_strMessage = "Bad Provider"
          Case ERROR_BUSY : m_strMessage = "Busy"
          Case ERROR_CANCELLED : m_strMessage = "Cancelled"
          Case ERROR_CANNOT_OP EN_PROFILE : m_strMessage = "Can Not
          Open Profile"
          Case ERROR_DEVICE_AL READY_REMEMBERE D : m_strMessage =
          "Device Already Remembered"
          Case ERROR_EXTENDED_ ERROR : m_strMessage = "Extended
          Error"
          Case ERROR_INVALID_P ASSWORD : m_strMessage = "Invalid
          Password"
          Case ERROR_NO_NET_OR _BAD_PATH : m_strMessage = "No Network
          or Bad Path"
          Case 53 : m_strMessage = "Can Not Connect - Check Samba
          Log"
          Case Else : m_strMessage = "*** Undefined ***"
          End Select
          Return m_strMessage
          End Function
          End Class

          Comment

          Working...