473,325 Members | 2,785 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 software developers and data experts.

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.
Oct 24 '08 #1
4 3021

This looks more like a SAMBA misconfiguration 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

<vb******@gmail.comschreef in bericht
news:9c**********************************@t18g2000 prt.googlegroups.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.

Oct 24 '08 #2
<vb******@gmail.comwrote in message
news:9c**********************************@t18g2000 prt.googlegroups.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 WNetAddConnection2 and
WNetCancelConnection2 APIs, which will let you mount and dismount network
files programmatically.
Oct 25 '08 #3
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.

<vb******@gmail.comwrote in message
news:9c**********************************@t18g2000 prt.googlegroups.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.

Oct 26 '08 #4
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 WNetAddConnection2 Lib "mpr.dll" Alias _
"WNetAddConnection2A" (ByVal netResource As NETRESOURCE, _
ByVal password As [String], ByVal Username As [String], _
ByVal Flag As Integer) As Integer

Private Declare Function WNetCancelConnection2 Lib "mpr.dll" Alias
_
"WNetCancelConnection2A" (ByVal lpName As String, _
ByVal Flag As Integer, ByVal fForce As Integer) As Integer

Private m_strDrive As String
Private m_strNetworkShare As String
Private m_intError As Integer

<StructLayout(LayoutKind.Sequential)_
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_ANY As Integer = &H0
Private Const RESOURCETYPE_DISK As Integer = &H1
Private Const RESOURCETYPE_PRINT As Integer = &H2

Private Const RESOURCE_CONNECTED As Integer = &H1
Private Const RESOURCE_GLOBALNET As Integer = &H2
Private Const RESOURCE_REMEMBERED As Integer = &H3

Private Const RESOURCEDISPLAYTYPE_GENERIC As Integer = &H0
Private Const RESOURCEDISPLAYTYPE_DOMAIN As Integer = &H1
Private Const RESOURCEDISPLAYTYPE_SERVER As Integer = &H2
Private Const RESOURCEDISPLAYTYPE_SHARE As Integer = &H3

Private Const RESOURCEUSAGE_CONNECTABLE As Integer = &H1
Private Const RESOURCEUSAGE_CONTAINER As Integer = &H2

' Error Constants:
Private Const ERROR_ACCESS_DENIED As Integer = 5&
Private Const ERROR_ALREADY_ASSIGNED As Integer = 85&
Private Const ERROR_BAD_DEV_TYPE As Integer = 66&
Private Const ERROR_BAD_DEVICE As Integer = 1200&
Private Const ERROR_BAD_NET_NAME As Integer = 67&
Private Const ERROR_BAD_PROFILE As Integer = 1206&
Private Const ERROR_BAD_PROVIDER As Integer = 1204&
Private Const ERROR_BUSY As Integer = 170&
Private Const ERROR_CANCELLED As Integer = 1223&
Private Const ERROR_CANNOT_OPEN_PROFILE As Integer = 1205&
Private Const ERROR_DEVICE_ALREADY_REMEMBERED As Integer = 1202&
Private Const ERROR_EXTENDED_ERROR As Integer = 1208&
Private Const ERROR_INVALID_PASSWORD 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.Length 1 Then m_strDrive =
m_strDrive.Substring(0, 1)
m_strDrive += ":"
m_strNetworkShare = NetworkShare
End Sub

'---------- Connect a drive ----------
Public Function DriveConnect(Optional ByVal IgnoreAlreadyConnected
As Boolean = True) As Integer
Dim myNetResource As New NETRESOURCE
myNetResource.dwScope = RESOURCE_GLOBALNET
myNetResource.dwType = RESOURCETYPE_DISK
myNetResource.dwDisplayType = RESOURCEDISPLAYTYPE_SHARE
myNetResource.dwUsage = RESOURCEUSAGE_CONNECTABLE
myNetResource.LocalName = m_strDrive
myNetResource.RemoteName = m_strNetworkShare
myNetResource.Provider = Nothing
m_intError = WNetAddConnection2(myNetResource, Nothing,
Nothing, 0)
If m_intError = ERROR_ALREADY_ASSIGNED AndAlso
IgnoreAlreadyConnected Then m_intError = NO_ERROR
Return m_intError
End Function

'---------- Disconnect a drive ----------
Public Function DriveDisconnect() As Integer
m_intError = WNetCancelConnection2(m_strDrive,
CONNECT_UPDATE_PROFILE, 0)
Return m_intError
End Function

'---------- Error Code Description ----------
' Use the last error from either the connect or disconnect
Public Function ErrorCodeMeaning() As String
Dim m_strMessage As String = "*** Undefined ***"
Select Case m_intError
Case NO_ERROR : m_strMessage = ""
Case ERROR_ACCESS_DENIED : m_strMessage = "Access Denied"
Case ERROR_ALREADY_ASSIGNED : m_strMessage = "Already
Assigned"
Case ERROR_BAD_DEV_TYPE : m_strMessage = "Bad Device Type"
Case ERROR_BAD_DEVICE : m_strMessage = "Bad Device"
Case ERROR_BAD_NET_NAME : m_strMessage = "Bad Net Name"
Case ERROR_BAD_PROFILE : m_strMessage = "Bad Profile"
Case ERROR_BAD_PROVIDER : m_strMessage = "Bad Provider"
Case ERROR_BUSY : m_strMessage = "Busy"
Case ERROR_CANCELLED : m_strMessage = "Cancelled"
Case ERROR_CANNOT_OPEN_PROFILE : m_strMessage = "Can Not
Open Profile"
Case ERROR_DEVICE_ALREADY_REMEMBERED : m_strMessage =
"Device Already Remembered"
Case ERROR_EXTENDED_ERROR : m_strMessage = "Extended
Error"
Case ERROR_INVALID_PASSWORD : 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

Oct 30 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

23
by: John Bailo | last post by:
I build an NT service using the FileSystemWatcher() class to detect when new files arrive at our ftp server. Now I want to configure it to watch for files on someone else's remote server. ...
1
by: Max Baki via .NET 247 | last post by:
I all, i've write a sample ftp Windows service which download files and copy them on remote share or remote mapped drive (the service works fine on local drives). This part of code is the...
3
by: Daniel | last post by:
Is it possible to retain local file system read, write, delete access while impersonating for access to a remote drive in a different domain? I need to be able to move files from a local computer...
2
by: Daniel E. Ulfe | last post by:
Hi, I have a small problem... I have an application that copy files from one computer to another (very simple), but... when I try to check a folder in the remote computer using: ...
2
by: Howard Kaikow | last post by:
Can a program access the sectors on a remote drive? I'm using VS .NET 2003 in Win 2000. -- http://www.standards.com/; See Howard Kaikow's web site.
1
by: Paul Buxton | last post by:
Hi, Platform is Windows 2003 SP1. I've been asked to set up a website where the website files are all sourced from a NAS box. However if I do this, and tell IIS that it is a remote share...
3
by: Derick Beckwith | last post by:
Hello, How would I quickly determine if a logical disk drive is ready to use? I am developing for ver 1.1 so the DriveInfo class is not available to me. The method I am currently using seems to...
9
by: =?Utf-8?B?THVpcyBBbnRvbmlvIFJvc2VsbG8gR2FyY2lh?= | last post by:
Hi, I have a big problem with a Visual C++ 6.0 function that retrives the logical drives and types in the local system. This function works perfectly on Windows 98, NT, 2000, XP and 2003, but I...
4
by: Ryderch | last post by:
Greetings folks! I need to open a file located on a remote machine running DOS (ouch!) from a client running Vista. The network connection is based on NetBEUI. Test1 Code running on the...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.